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


Java Search类代码示例

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


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

示例1: search

import org.hibernate.search.jpa.Search; //导入依赖的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: index

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
public void index(Class<?> type) {
	FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
	if (type == Article.class) {
		for (int i = 0; i < articleDao.count(); i += 20) {
			List<Article> articles = articleDao.findList(i, 20, null, null);
			for (Article article : articles) {
				fullTextEntityManager.index(article);
			}
			fullTextEntityManager.flushToIndexes();
			fullTextEntityManager.clear();
			articleDao.clear();
		}
	} else if (type == Product.class) {
		for (int i = 0; i < productDao.count(); i += 20) {
			List<Product> products = productDao.findList(i, 20, null, null);
			for (Product product : products) {
				fullTextEntityManager.index(product);
			}
			fullTextEntityManager.flushToIndexes();
			fullTextEntityManager.clear();
			productDao.clear();
		}
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:25,代码来源:SearchServiceImpl.java

示例3: initialize

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
/**
 * Call at the startup of the server.
 *
 *  - Enables Hibernate's FullTextEntityManager for Full-text searching.
 *  - Initializes roles in database
 */
public void initialize()
{
    logger.info("Linking entityManager.");
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    logger.info(String.format("entityManager: %s linked.", entityManager));

    try
    {
        logger.info("Beginning to index data.");
        fullTextEntityManager.createIndexer().startAndWait();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    logger.info("Index complete.");

    // Initialize user roles in database
    Role publicRole = createRole(1, "ROLE_PUBLIC");
    roleRepository.save(publicRole);
    Role adminRole = createRole(2, "ROLE_ADMIN");
    roleRepository.save(adminRole);
}
 
开发者ID:MTUHIDE,项目名称:CoCoTemp,代码行数:29,代码来源:StartupService.java

示例4: searchByText

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Override
public List<Product> searchByText(String text) {
	Product productEntity = newInstance();
	FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);

	QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
			.forEntity(productEntity.getClass()).get();
	if (!Strings.isNullOrEmpty(text)) {
		Query query = qb.keyword().onField("name").andField("details").andField("technicalDetails").matching(text)
				.createQuery();

		javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query,
				productEntity.getClass());
		List<Product> result = persistenceQuery.getResultList();

		if (CollectionUtils.isNotEmpty(result)) {
			for (Product product : result) {
				loadImagesFromQuantities(product.getQuantities());
			}
		}
		return result;
	}
	return Collections.emptyList();
}
 
开发者ID:raphaelazzolini,项目名称:mercurius,代码行数:25,代码来源:ProductDAOImpl.java

示例5: getAnalyzer

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Override
public Analyzer getAnalyzer(Class<?> entityType) {
	if (jpaPropertiesProvider.isHibernateSearchElasticSearchEnabled()) {
		ExtendedSearchIntegrator searchIntegrator = Search.getFullTextEntityManager(getEntityManager())
				.getSearchFactory().unwrap(ExtendedSearchIntegrator.class);
		ScopedElasticsearchAnalyzer scopedAnalyzer = (ScopedElasticsearchAnalyzer) searchIntegrator.getAnalyzerReference(entityType).getAnalyzer();
		
		try {
			// these properties are package protected !
			ElasticsearchAnalyzer globalAnalyzer = (ElasticsearchAnalyzer) FieldUtils.getField(ScopedElasticsearchAnalyzer.class, "globalAnalyzer", true).get(scopedAnalyzer);
			@SuppressWarnings("unchecked")
			Map<String, ElasticsearchAnalyzer> analyzers = (Map<String, ElasticsearchAnalyzer>) FieldUtils.getField(ScopedElasticsearchAnalyzer.class, "scopedAnalyzers", true).get(scopedAnalyzer);
			
			Map<String, Analyzer> luceneAnalyzers = Maps.newHashMap();
			for (Entry<String, ElasticsearchAnalyzer> analyzer : analyzers.entrySet()) {
				luceneAnalyzers.put(analyzer.getKey(), getAnalyzer(analyzer.getValue().getName(null)));
			}
			return new ScopedLuceneAnalyzer(getAnalyzer(globalAnalyzer.getName(null)) /* parameter is not used */, luceneAnalyzers);
		} catch (IllegalAccessException e) {
			throw new RuntimeException("illegal access on scoped analyzer", e);
		}
	} else {
		return Search.getFullTextEntityManager(getEntityManager()).getSearchFactory().unwrap(SearchIntegrator.class).getAnalyzer(entityType);
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:26,代码来源:HibernateSearchDaoImpl.java

示例6: processKeywords

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Nullable
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
private Long[] processKeywords(EntityManager entityManager, @Nullable Integer maxResults) {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(this.entityImplClass).get();
    BooleanJunction<?> conjunction = queryBuilder.bool();

    PropertyMetadata keywordPropMetadata;

    for (String keywordPropName : this.keywords.keySet()) {
        conjunction = conjunction.must(queryBuilder.keyword()
            .onFields((keywordPropMetadata = this.entityPropMetadatas.get(keywordPropName)).getLowercaseFieldName(),
                keywordPropMetadata.getEdgeNgramFieldName(), keywordPropMetadata.getNgramFieldName(), keywordPropMetadata.getPhoneticFieldName())
            .matching(StringUtils.join(this.keywords.get(keywordPropName), StringUtils.SPACE)).createQuery());
    }

    FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(new InterceptingQuery(conjunction.createQuery()), this.entityImplClass);
    fullTextQuery.setProjection(ProjectionConstants.ID);

    if (maxResults != null) {
        fullTextQuery.setMaxResults(maxResults);
    }

    return ((List<Object[]>) fullTextQuery.getResultList()).stream().map(fullTextResult -> ((Long) fullTextResult[0])).toArray(Long[]::new);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:26,代码来源:SdcctCriteriaImpl.java

示例7: searchAdherentSortOnName

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
@Transactional
public void searchAdherentSortOnName() throws Exception {
	// Given
	adherent.setNom("FERRÉ");
	adherentRepository.saveAndFlush(adherent);

	final Adherent secondAdherent = new Adherent();
	secondAdherent.setPrenom(DEFAULT_PRENOM);
	secondAdherent.setNom("BERRUBÉ");
	adherentRepository.saveAndFlush(secondAdherent);

	final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
	fullTextEntityManager.flushToIndexes();

	// When
	restAdherentMockMvc.perform(get("/api/adherents/search?criteria=eRR&sort=nom").accept(TestUtil.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
	.andExpect(jsonPath("$.[*].nom").value(contains("BERRUBÉ", "FERRÉ")));
}
 
开发者ID:glebreton,项目名称:lapetiterennes,代码行数:20,代码来源:AdherentResourceTest.java

示例8: test

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void test() {
    final String testValue = "test";

    assertThat(entityWithFullTextRepository.findCount(findByValue(testValue))).isEqualTo(0);

    EntityWithFullText entityWithFullText = new EntityWithFullText();
    entityWithFullText.setValue(testValue);
    entityWithFullText = entityWithFullTextRepository.save(entityWithFullText);

    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    fullTextEntityManager.index(entityWithFullText);
    fullTextEntityManager.flushToIndexes();
    fullTextEntityManager.flush();

    assertThat(entityWithFullTextRepository.find(findByValue(testValue))).containsExactly(entityWithFullText);
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:18,代码来源:EntityWithFullTextRepositoryIT.java

示例9: test

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void test() {
    final String testValue = "test";

    assertThat(entityWithMultipleFullTextRepository.findCount(findByValue(testValue))).isEqualTo(0);

    EntityWithMultipleFullText entityWithMultipleFullText = new EntityWithMultipleFullText();
    entityWithMultipleFullText.setValue1(testValue);
    entityWithMultipleFullText.setValue2("abcdef");
    entityWithMultipleFullText = entityWithMultipleFullTextRepository.save(entityWithMultipleFullText);

    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    fullTextEntityManager.index(entityWithMultipleFullText);
    fullTextEntityManager.flushToIndexes();
    fullTextEntityManager.flush();

    assertThat(entityWithMultipleFullTextRepository.find(findByValue(testValue))).containsExactly(entityWithMultipleFullText);
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:19,代码来源:EntityWithMultipleFullTextRepositoryIT.java

示例10: deep_test

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void deep_test() {
    final String testValue = "test";

    assertThat(entityWithMultipleFullTextRepository.findCount(findByDeepValue(testValue))).isEqualTo(0);

    EntityWithMultipleFullText entityWithMultipleFullText = new EntityWithMultipleFullText();
    entityWithMultipleFullText.setValue1("abcdef");
    EntityWithFullText entityWithFullText = new EntityWithFullText();
    entityWithFullText.setValue(testValue);
    entityWithMultipleFullText.setEntityWithFullText(entityWithFullText);
    entityWithMultipleFullText = entityWithMultipleFullTextRepository.save(entityWithMultipleFullText);

    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    fullTextEntityManager.index(entityWithMultipleFullText);
    fullTextEntityManager.flushToIndexes();
    fullTextEntityManager.flush();

    assertThat(entityWithMultipleFullTextRepository.find(findByDeepValue(testValue))).containsExactly(entityWithMultipleFullText);
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:21,代码来源:EntityWithMultipleFullTextRepositoryIT.java

示例11: test

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void test() {
    final Integer testValue = 1995;

    assertThat(entityWithFullTextIntegerRepository.findCount(findByValue(testValue))).isEqualTo(0);

    EntityWithFullTextInteger entityWithFullTextInteger = new EntityWithFullTextInteger();
    entityWithFullTextInteger.setValue(testValue);
    entityWithFullTextInteger = entityWithFullTextIntegerRepository.save(entityWithFullTextInteger);
    EntityWithFullTextInteger another = new EntityWithFullTextInteger();
    another.setValue(1994);
    entityWithFullTextIntegerRepository.save(another);

    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    fullTextEntityManager.index(entityWithFullTextInteger);
    fullTextEntityManager.flushToIndexes();
    fullTextEntityManager.flush();

    assertThat(entityWithFullTextIntegerRepository.find(findByValue(testValue))).containsExactly(entityWithFullTextInteger);
}
 
开发者ID:jpasearch,项目名称:jpasearch,代码行数:21,代码来源:EntityWithFullTextIntegerRepositoryIT.java

示例12: recreateIndex

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@PostConstruct
public void recreateIndex() throws Exception {
	log.debug("SearchConfiguration - creating full-text index");
	
	FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
	
	Future<?> indexResult = fullTextEntityManager.createIndexer().start();
	
	Futures.addCallback(JdkFutureAdapters.listenInPoolThread(indexResult), new FutureCallback<Object>() {
		@Override
		public void onSuccess(Object result) {
			log.debug("SearchConfiguration - finished creating full-text index");
		}

		@Override
		public void onFailure(Throwable t) {
			log.error("SearchConfiguration - Failed creating full-text index", t);
		}
	});
}
 
开发者ID:IHTSDO,项目名称:MLDS,代码行数:21,代码来源:SearchConfiguration.java

示例13: search

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public SearchResult<Page> search(String term, int offset, int limit) {
	FullTextEntityManager fullTextEm = Search.getFullTextEntityManager( getEm() );
	QueryBuilder queryBuilder = fullTextEm.getSearchFactory().buildQueryBuilder()
			.forEntity( Page.class ).get();
	
	Query luceneQuery = queryBuilder.keyword()
			.onField( "title" ).boostedTo( 2.0f )
			.andField( "content" )
			.matching( term )
			.createQuery();
	
	Sort scoreSort = queryBuilder.sort().byScore().createSort();

	FullTextQuery query = fullTextEm.createFullTextQuery( luceneQuery, Page.class )
			.setFirstResult( offset )
			.setMaxResults( limit )
			.setSort( scoreSort );
	
	return new SearchResult<>( query.getResultSize(), query.getResultList() );
}
 
开发者ID:hibernate,项目名称:hibernate-demos,代码行数:23,代码来源:HibernatePageDaoImpl.java

示例14: queryOnSingleField

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void queryOnSingleField() {
	EntityManager em = emf.createEntityManager();

	inTransaction( em, tx -> {
		FullTextEntityManager ftem = Search.getFullTextEntityManager( em );
		QueryBuilder qb = ftem.getSearchFactory()
				.buildQueryBuilder()
				.forEntity( VideoGame.class )
				.get();

		FullTextQuery query = ftem.createFullTextQuery(
				qb.keyword().onField( "title" ).matching( "samurai" ).createQuery(),
				VideoGame.class
		);

		List<VideoGame> videoGames = query.getResultList();
		assertThat( videoGames ).onProperty( "title" ).containsExactly( "Revenge of the Samurai" );
	} );

	em.close();
}
 
开发者ID:hibernate,项目名称:hibernate-demos,代码行数:23,代码来源:HibernateSearchWithElasticsearchIT.java

示例15: queryOnMultipleFields

import org.hibernate.search.jpa.Search; //导入依赖的package包/类
@Test
public void queryOnMultipleFields() {
	EntityManager em = emf.createEntityManager();

	inTransaction( em, tx -> {
		FullTextEntityManager ftem = Search.getFullTextEntityManager( em );
		QueryBuilder qb = ftem.getSearchFactory()
				.buildQueryBuilder()
				.forEntity( VideoGame.class )
				.get();

		FullTextQuery query = ftem.createFullTextQuery(
				qb.keyword().onFields( "title", "description").matching( "samurai" ).createQuery(),
				VideoGame.class
		);

		List<VideoGame> videoGames = query.getResultList();
		assertThat( videoGames ).onProperty( "title" ).containsExactly( "Revenge of the Samurai", "Tanaka's return" );
	} );

	em.close();
}
 
开发者ID:hibernate,项目名称:hibernate-demos,代码行数:23,代码来源:HibernateSearchWithElasticsearchIT.java


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