当前位置: 首页>>代码示例>>Java>>正文


Java SearchFactory.getReaderProvider方法代码示例

本文整理汇总了Java中org.hibernate.search.SearchFactory.getReaderProvider方法的典型用法代码示例。如果您正苦于以下问题:Java SearchFactory.getReaderProvider方法的具体用法?Java SearchFactory.getReaderProvider怎么用?Java SearchFactory.getReaderProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.search.SearchFactory的用法示例。


在下文中一共展示了SearchFactory.getReaderProvider方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkIndexOnStartup

import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
public void checkIndexOnStartup() {
	//log.info("Observed event {1} from Thread {0}", Thread.currentThread().getName(), App.INIT_SUCCESS);

	// See if we need to rebuild the index during startup ...
	FullTextEntityManager ftEm = Search.getFullTextEntityManager(entityManager);
	SearchFactory searchFactory = ftEm.getSearchFactory();
	ReaderProvider readerProvider = searchFactory.getReaderProvider();
	IndexReader reader = readerProvider.openReader(searchFactory.getDirectoryProviders(NodeDocumentVersion.class)[0]);
	int maxDoc = 0;

	try {
		maxDoc = reader.maxDoc();
	} finally {
		readerProvider.closeReader(reader);
	}

	if (maxDoc == 0) {
		log.warn("No objects indexed ... rebuilding Lucene search index from database ...");
		long _exit = 0L;
		long _entr = System.currentTimeMillis();

		try {
			int docs = doRebuildIndex();
			_exit = System.currentTimeMillis();
			log.info("Took " + (_exit - _entr)
					+ " (ms) to re-build the index containing " + docs
					+ " documents.");
		} catch (Exception exc) {
			if (exc instanceof RuntimeException) {
				throw (RuntimeException) exc;
			} else {
				throw new RuntimeException(exc);
			}
		}

		// build the spell checker index off of the HS index.
		buildSpellCheckerIndex(searchFactory);
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:40,代码来源:IndexHelper.java

示例2: buildSpellCheckerIndex

import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
protected void buildSpellCheckerIndex(SearchFactory searchFactory) {
	IndexReader reader = null;
	Directory dir = null;
	long _entr = System.currentTimeMillis();
	File spellCheckIndexDir = new File("lucene_index/spellcheck");
	log.info("Building SpellChecker index in {0}", spellCheckIndexDir.getAbsolutePath());
	ReaderProvider readerProvider = searchFactory.getReaderProvider();

	try {
		reader = readerProvider.openReader(searchFactory.getDirectoryProviders(NodeDocumentVersion.class)[0]);
		dir = FSDirectory.open(spellCheckIndexDir);
		SpellChecker spell = new SpellChecker(dir);
		spell.clearIndex();
		spell.indexDictionary(new LuceneDictionary(reader, NodeDocument.TEXT_FIELD));
		spell.close();
		dir.close();
		dir = null;
		long _exit = System.currentTimeMillis();
		log.info("Took {1} (ms) to build SpellChecker index in {0}",
				spellCheckIndexDir.getAbsolutePath(), String.valueOf((_exit - _entr)));
	} catch (Exception exc) {
		log.error("Failed to build spell checker index!", exc);
	} finally {
		if (dir != null) {
			try {
				dir.close();
			} catch (Exception zzz) {
			}
		}
		if (reader != null) {
			readerProvider.closeReader(reader);
		}
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:35,代码来源:IndexHelper.java

示例3: getReader

import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
/**
 * Get Lucene index reader.
 */
@SuppressWarnings("rawtypes")
private IndexReader getReader(FullTextSession session, Class entity) {
	SearchFactory searchFactory = session.getSearchFactory();
	DirectoryProvider provider = searchFactory.getDirectoryProviders(entity)[0];
	ReaderProvider readerProvider = searchFactory.getReaderProvider();
	return readerProvider.openReader(provider);
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:11,代码来源:SearchDAO.java

示例4: list

import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
/**
 * Shows the main statistics page
 */
public void list() {
	IndexReader indexReader = null;
	ReaderProvider readerProvider = null;

	try {
		SearchFactory searchFactory = Search.createFullTextSession(
				this.sessionFactory.getCurrentSession()).getSearchFactory();

		DirectoryProvider<?> directoryProvider = searchFactory
				.getDirectoryProviders(Post.class)[0];
		readerProvider = searchFactory.getReaderProvider();
		indexReader = readerProvider.openReader(directoryProvider);

		String indexDirectory = directoryProvider.getDirectory().toString();
		indexDirectory = indexDirectory.substring(indexDirectory
				.indexOf('@') + 1);

		boolean indexExists = IndexReader.indexExists(indexDirectory);

		this.result.include("indexExists", indexExists);

		if (indexExists) {
			this.result.include("numberOfDocs", indexReader.numDocs());
			this.result.include("indexLocation", indexDirectory);
			this.result.include("totalMessages",
					this.forumRepository.getTotalMessages());
			this.result.include("isLocked",
					IndexReader.isLocked(indexDirectory));
			this.result.include("lastModified",
					new Date(IndexReader.lastModified(indexDirectory)));
		}
	} catch (IOException e) {
		throw new ForumException(e);
	} finally {
		if (readerProvider != null && indexReader != null) {
			readerProvider.closeReader(indexReader);
		}
	}
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:43,代码来源:LuceneAdminController.java

示例5: getTerms

import org.hibernate.search.SearchFactory; //导入方法依赖的package包/类
/**
 * Get Lucent document terms.
 */
@SuppressWarnings("unchecked")
public List<String> getTerms(Class<?> entityType, String nodeUuid) throws CorruptIndexException, IOException {
	List<String> terms = new ArrayList<String>();
	FullTextSession ftSession = null;
	IndexSearcher searcher = null;
	ReaderProvider provider = null;
	Session session = null;
	IndexReader reader = null;

	try {
		session = HibernateUtil.getSessionFactory().openSession();
		ftSession = Search.getFullTextSession(session);
		SearchFactory sFactory = ftSession.getSearchFactory();
		provider = sFactory.getReaderProvider();
		QueryBuilder builder = sFactory.buildQueryBuilder().forEntity(entityType).get();
		Query query = builder.keyword().onField("uuid").matching(nodeUuid).createQuery();

		DirectoryProvider<Directory>[] dirProv = sFactory.getDirectoryProviders(NodeDocument.class);
		reader = provider.openReader(dirProv[0]);
		searcher = new IndexSearcher(reader);
		TopDocs topDocs = searcher.search(query, 1);

		for (ScoreDoc sDoc : topDocs.scoreDocs) {
			if (!reader.isDeleted(sDoc.doc)) {
				for (TermEnum te = reader.terms(); te.next(); ) {
					Term t = te.term();

					if ("text".equals(t.field())) {
						for (TermDocs tds = reader.termDocs(t); tds.next(); ) {
							if (sDoc.doc == tds.doc()) {
								terms.add(t.text());
								//log.info("Field: {} - {}", t.field(), t.text());
							}
						}
					}
				}
			}
		}
	} finally {
		if (provider != null && reader != null) {
			provider.closeReader(reader);
		}

		if (searcher != null) {
			searcher.close();
		}
		HibernateUtil.close(ftSession);
		HibernateUtil.close(session);
	}

	return terms;
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:56,代码来源:SearchDAO.java


注:本文中的org.hibernate.search.SearchFactory.getReaderProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。