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); }
@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; }
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