java - How to search a full phrase along with single terms using Hibernate Lucene? -


earlier searching "father david azrael". returns results names term father or david or azrael.

following code in picture:

string[] fields =  { "id", "person.firstname", "person.middlename", "person.lastname" }; (string field : fields) {            (string match : pattern) {                         bool.should(qb.keyword().wildcard().onfield(field).matching(match).createquery());            }         }         query = bool.createquery(); 

along above scenario, there additional requirement if end user want search "father david azrael"; should 1 result only.

means if search "father david azrael"; results having name should appears if user search "father azrael" should work working now.

so changes need done above code implement same?

you can use phrase query, shown in section 5.1.2.4 of documentation:

bool.should(qb     .phrase()     .onfield(field)     .sentence("father david azrael")     .createquery()); 

i don't know mean "father david azrael" being treated differently "father azrael", won't comment on part, that's how create phrase query. combine phrase existing wildcard queries adding both boolean query both sets of results, phrase matches receiving highest scores. or run phrase query first, , fall on wildcard queries when gets no results.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -