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


Java FullTextEntityManager.getSearchFactory方法代码示例

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


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

示例1: search

import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
/**
 * Searches the lucene store for a specific query
 *
 * @param <T>       What type of information are we searching
 * @param clazz     The class of the information we are searching
 * @param queryText The query text
 * @return list of entities
 * @throws ParseException the parse exception
 */
public final <T extends BaseEntity> List<Object[]> search(final Class<T> clazz, final String queryText) throws ParseException {
    final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);

    final SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();

    final QueryParser parser = new MultiFieldQueryParser(getClassLuceneFields(clazz), searchFactory.getAnalyzer(clazz));

    final List<Query> parsedQueries = Arrays.stream(queryText.split("AND"))
            .map(e -> parseQuery(e, parser))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());

    final BooleanQuery.Builder bq = new BooleanQuery.Builder();
    parsedQueries.forEach(e -> bq.add(e, BooleanClause.Occur.MUST));

    final FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(bq.build(), clazz);
    jpaQuery.setProjection(ProjectionConstants.SCORE, ProjectionConstants.EXPLANATION, ProjectionConstants.THIS);

    return (List<Object[]>) jpaQuery.getResultList();
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:30,代码来源:EntitySearch.java

示例2: checkIndexOnStartup

import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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

示例3: updateSpellCheckerIndex

import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
public void updateSpellCheckerIndex(NodeDocumentVersion nDocVer) {
	log.info("Observed Wine added/updated event for {1} from Thread {0}",
			Thread.currentThread().getName(), String.valueOf(nDocVer));
	String text = (nDocVer != null) ? nDocVer.getText() : null;

	if (text != null) {
		Dictionary dictionary = null;

		try {
			FullTextEntityManager ftEm = (FullTextEntityManager) entityManager;
			SearchFactory searchFactory = ftEm.getSearchFactory();
			dictionary = new SetDictionary(text, searchFactory.getAnalyzer("wine_en"));
		} catch (IOException ioExc) {
			log.error("Failed to analyze dictionary text {0} from Wine {1} to update spell checker due to: {2}" +
					text + nDocVer.getUuid() + ioExc.toString());
		}

		if (dictionary != null) {
			Directory dir = null;
			// only allow one thread to update the index at a time ...
			// the Dictionary is pre-computed, so it should happen quickly
			// ...
			// this synchronized approach only works because this component
			// is application-scoped
			synchronized (this) {
				try {
					dir = FSDirectory.open(new File("lucene_index/spellcheck"));
					SpellChecker spell = new SpellChecker(dir);
					spell.indexDictionary(dictionary);
					spell.close();
					log.info("Successfully updated the spell checker index after Document added/updated.");
				} catch (Exception exc) {
					log.error("Failed to update the spell checker index!", exc);
				} finally {
					if (dir != null) {
						try {
							dir.close();
						} catch (Exception zzz) {
						}
					}
				}
			}
		}
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:46,代码来源:IndexHelper.java


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