.sentence(terms.iterator().next().toLowerCase()).createQuery();
private void addDisplayFilterExact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { bool.must(qb.phrase().onField("myDisplay").sentence(nextFilter.getValue()).createQuery()); }
private void addDisplayFilterInexact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { Query textQuery = qb .phrase() .withSlop(2) .onField("myDisplay").boostedTo(4.0f) .andField("myDisplayEdgeNGram").boostedTo(2.0f) // .andField("myDisplayNGram").boostedTo(1.0f) // .andField("myDisplayPhonetic").boostedTo(0.5f) .sentence(nextFilter.getValue().toLowerCase()).createQuery(); bool.must(textQuery); }
.andField("myContentTextNGram").boostedTo(1.0f) .andField("myContentTextPhonetic").boostedTo(0.5f) .sentence(theText.toLowerCase()).createQuery();
@SuppressWarnings("rawtypes") private BooleanJunction<BooleanJunction> addShouldPhraseWithAttributesOnFields(Map<String, String> eqSentenceOnField, QueryBuilder qb, BooleanJunction<BooleanJunction> combinedQuery) { for(String field : eqSentenceOnField.keySet()){ String value = eqSentenceOnField.get(field); Query luceneQuery = qb.phrase() .onField(field) .sentence(value) .createQuery(); combinedQuery.should(luceneQuery); //must(luceneQuery); } return combinedQuery; }
@SuppressWarnings("rawtypes") private BooleanJunction<BooleanJunction> addMustPhraseWithAttributesOnFields(Map<String, String> eqSentenceOnField, QueryBuilder qb, BooleanJunction<BooleanJunction> combinedQuery) { for(String field : eqSentenceOnField.keySet()){ String value = eqSentenceOnField.get(field); Query luceneQuery = qb.phrase() .onField(field) .sentence(value) .createQuery(); combinedQuery.must(luceneQuery); } return combinedQuery; }
@SuppressWarnings("rawtypes") private BooleanJunction<BooleanJunction> addMustPhraseWithMultiFieldOnAttribute(Map<String, Set<String>> attributeForMultipleFieldsMap, QueryBuilder qb, BooleanJunction<BooleanJunction> combinedQuery) { PhraseContext queryParse = qb.phrase(); for(String value :attributeForMultipleFieldsMap.keySet()){ Set<String> attributes = attributeForMultipleFieldsMap.get(value); PhraseMatchingContext pharseMatchingContext = null; for(String attribute : attributes){ if(!attribute.isEmpty()){ if(pharseMatchingContext == null){ pharseMatchingContext = queryParse.onField(attribute); } else{ pharseMatchingContext.andField(attribute); } } } if(pharseMatchingContext != null){ Query luceneQuery = pharseMatchingContext.sentence(value).createQuery(); combinedQuery.must(luceneQuery); } } return combinedQuery; }
@SuppressWarnings("rawtypes") private BooleanJunction<BooleanJunction> addShouldWMustPhraseWithAttributesOnFields(Map<String, String> eqSentenceOnField,Map<String, String> eqMustSentenceOnField, QueryBuilder qb, BooleanJunction<BooleanJunction> combinedQuery) { for(String field : eqSentenceOnField.keySet()){ String value = eqSentenceOnField.get(field); Query luceneQuery = qb.phrase() .onField(field) .sentence(value) .createQuery(); combinedQuery.should(luceneQuery); //must(luceneQuery); } combinedQuery.must(combinedQuery.createQuery()); //combinedQuery.setMinimumShouldMatch(2); for(String field : eqMustSentenceOnField.keySet()){ String value = eqMustSentenceOnField.get(field); Query luceneQuery = qb.phrase() .onField(field) .sentence(value) .createQuery(); combinedQuery.must(luceneQuery); //must(luceneQuery); } return combinedQuery; }
.sentence(terms.iterator().next().toLowerCase()).createQuery();
private void addDisplayFilterExact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { bool.must(qb.phrase().onField("myDisplay").sentence(nextFilter.getValue()).createQuery()); }
private void addDisplayFilterInexact(QueryBuilder qb, BooleanJunction<?> bool, ValueSet.ConceptSetFilterComponent nextFilter) { Query textQuery = qb .phrase() .withSlop(2) .onField("myDisplay").boostedTo(4.0f) .andField("myDisplayEdgeNGram").boostedTo(2.0f) // .andField("myDisplayNGram").boostedTo(1.0f) // .andField("myDisplayPhonetic").boostedTo(0.5f) .sentence(nextFilter.getValue().toLowerCase()).createQuery(); bool.must(textQuery); }
// New DSL based query composition //org.hibernate.search.query.dsl SearchFactory searchFactory = fullTextSession.getSearchFactory(); QueryBuilder buildQuery = searchFactory.buildQueryBuilder().forEntity(MasterDiagnosis.class).get(); PhraseContext keyword = buildQuery.phrase(); keyword.withSlop(3); //WildcardContext wildcard = keyword.wildcard(); String[] searchfields = MasterDiagnosis.getSearchfields(); PhraseMatchingContext onFields = keyword.onField(searchfields[0]); for (int i = 1; i < searchfields.length; i++) onFields.andField(searchfields[i]); PhraseTermination matching = onFields.sentence(lowerCasedSearchTerm); Query query = matching.createQuery(); // Convert the Search Query into something that provides results: Specify Compound again to be future proof
.andField(TITLE_EDGE_NGRAM_INDEX).boostedTo(5) .andField("atoms.name").boostedTo(5) .sentence(searchTerm.toLowerCase()).createQuery();
.andField("myContentTextNGram").boostedTo(1.0f) .andField("myContentTextPhonetic").boostedTo(0.5f) .sentence(theText.toLowerCase()).createQuery();
public void testPhraseSentence() { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().phrase() .onField("blurb").sentence("Eats grass").createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(1, found.size()); assert found.contains(person2); person4 = new Person(); person4.setName("Another goat"); person4.setBlurb("Eats grass and drinks water."); cache.put("anotherKey", person4); found = cacheQuery.list(); assertEquals(2, found.size()); assert found.contains(person2); assert found.contains(person4); }
.onField("blurb").sentence("Eats grass").createQuery();
public void testPhraseSentenceForNonAnalyzedEntries() { loadNumericTypes(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(NumericType.class).get().phrase() .onField("name").sentence("Some string").createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(0, found.size()); NumericType type4 = new NumericType(45,50); type4.setName("Some string"); cache.put("otherKey", type4); found = cacheQuery.list(); assertEquals(1, found.size()); assert found.contains(type4); }
@Test public void testPhraseQueryWithStopWords() throws Exception { final QueryBuilder monthQb = helper.queryBuilder( Month.class ); Query query = monthQb .phrase() .onField( "mythology" ) .sentence( "colder and whitening" ) .createQuery(); helper.assertThat( query ).from( Month.class ).hasResultSize( 1 ); }
phrase = phrase.withSlop(fullTextTermExpr.getFuzzySlop()); return phrase.onField(propertyValueExpr.getPropertyPath().asStringPath()).sentence(text).createQuery(); } else {
.onField("city") .sentence("London") .createQuery(); .onField("name") .sentence("2011") .createQuery(); .onField("awards") .sentence("Duke") .createQuery();