.withSlop(2) .onField(theFieldName).boostedTo(4.0f)
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); }
.withSlop(2) .onField("myContentText").boostedTo(4.0f) .andField("myContentTextEdgeNGram").boostedTo(2.0f)
.withSlop(2) .onField(theFieldName).boostedTo(4.0f)
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
titleQB.phrase().withSlop(2).onField(TITLE_NGRAM_INDEX) .andField(TITLE_EDGE_NGRAM_INDEX).boostedTo(5) .andField("atoms.name").boostedTo(5)
.withSlop(2) .onField("myContentText").boostedTo(4.0f) .andField("myContentTextEdgeNGram").boostedTo(2.0f)
public void testPhraseWithSlop() { loadTestingData(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(Person.class).get().phrase().withSlop(3) .onField("blurb").sentence("Eats grass").createQuery();
phrase = phrase.withSlop(fullTextTermExpr.getFuzzySlop());
phrase = phrase.withSlop(fullTextTermExpr.getFuzzySlop());
public void testPhraseWithSlopWithoutAnalyzer() { loadNumericTypes(); Query query = Search.getSearchManager(cache).buildQueryBuilderForClass(NumericType.class).get().phrase().withSlop(1) .onField("name").sentence("Some string").createQuery(); CacheQuery<Person> cacheQuery = Search.getSearchManager(cache).getQuery(query); List<Person> found = cacheQuery.list(); assertEquals(0, found.size()); NumericType type = new NumericType(10, 60); type.setName("Some string"); cache.put("otherKey", type); found = cacheQuery.list(); assertEquals(1, found.size()); assert found.contains(type); NumericType type1 = new NumericType(20, 60); type1.setName("Some other string"); cache.put("otherKey1", type1); found = cacheQuery.list(); assertEquals(1, found.size()); assert found.contains(type); }
@Override @SuppressWarnings("unchecked") protected void execute(FullTextSession fts) { long bookCount = ctx.bookIdCounter.get(); String phrase = PHRASES[(int) ( bookCount % PHRASES.length )]; Query q = fts.getSearchFactory() .buildQueryBuilder() .forEntity( Book.class ) .get() .phrase() .withSlop( 3 ) .onField( "summary" ) .sentence( phrase ) .createQuery(); List<Book> result = fts.createFullTextQuery( q, Book.class ).list(); if ( ctx.testContext.assertQueryResults ) { assertResult( result, phrase ); assertResultSize( result, phrase, bookCount ); } }
.withSlop( 3 ) .onField( "mythology" ) .sentence( "Month whitening" )