本文整理汇总了Java中org.hibernate.search.jpa.Search.getFullTextEntityManager方法的典型用法代码示例。如果您正苦于以下问题:Java Search.getFullTextEntityManager方法的具体用法?Java Search.getFullTextEntityManager怎么用?Java Search.getFullTextEntityManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.search.jpa.Search
的用法示例。
在下文中一共展示了Search.getFullTextEntityManager方法的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();
}
示例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();
}
}
}
示例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);
}
示例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();
}
示例5: 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);
}
示例6: 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É")));
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
});
}
示例12: 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() );
}
示例13: get
import org.hibernate.search.jpa.Search; //导入方法依赖的package包/类
/**
* Return all associated money transfers with given expense report.
*
* @param expenseReport to look for in money transfers
* @return collection of moneyTransfers associated with expenseReport or null.
*/
@Override
public Collection<MoneyTransfer> get(ExpenseReport expenseReport) {
if (expenseReport == null) {
throw new IllegalArgumentException("expenseReport is null");
}
FullTextEntityManager ftem = Search.getFullTextEntityManager(em);
QueryBuilder queryBuilder = ftem.getSearchFactory().buildQueryBuilder().forEntity(MoneyTransfer.class).get();
Query query = queryBuilder.keyword().onField("report.id").matching(expenseReport.getId()).createQuery();
FullTextQuery fullTextQuery = ftem.createFullTextQuery(query, MoneyTransfer.class);
fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
return fullTextQuery.getResultList();
}
示例14: getAllWithNoVerifierAssigned
import org.hibernate.search.jpa.Search; //导入方法依赖的package包/类
@Override
public Collection<ExpenseReport> getAllWithNoVerifierAssigned() {
FullTextEntityManager ftem = Search.getFullTextEntityManager(em);
QueryBuilder queryBuilder = ftem.getSearchFactory().buildQueryBuilder().forEntity(ExpenseReport.class).get();
Query allAssigned = queryBuilder.range().onField("verifier.id").above(0).createQuery();
// Query query = queryBuilder.bool().must(allAssigned).not().createQuery();
Query statusSubmitted = queryBuilder.keyword().onField("status").matching(ReportStatus.SUBMITTED).createQuery();
Query query = queryBuilder.bool()
.must(allAssigned).not()
.must(statusSubmitted)
.createQuery();
FullTextQuery fullTextQuery = ftem.createFullTextQuery(query, ExpenseReport.class);
fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
return fullTextQuery.getResultList();
}
示例15: getAllForSubmitterWithStatus
import org.hibernate.search.jpa.Search; //导入方法依赖的package包/类
@Override
public Collection<ExpenseReport> getAllForSubmitterWithStatus(Person submitter, ReportStatus status) {
FullTextEntityManager ftem = Search.getFullTextEntityManager(em);
QueryBuilder queryBuilder = ftem.getSearchFactory().buildQueryBuilder().forEntity(ExpenseReport.class).get();
Query forPerson = queryBuilder.keyword().onField("submitter.id").matching(submitter.getId()).createQuery();
Query forStatus = queryBuilder.keyword().onField("status").matching(status).createQuery();
Query query = queryBuilder.bool()
.must(forPerson)
.must(forStatus)
.createQuery();
FullTextQuery fullTextQuery = ftem.createFullTextQuery(query, ExpenseReport.class);
fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
return fullTextQuery.getResultList();
}