简体   繁体   中英

Hibernate search : exact phrase matching

Using Hibernate Search, I cannot manage to search for an exact sentence.

For instance, having the following sentences in my index :

1 - New York weather
2 - New York

I want to get only the line 2 matching "New York", so I make the following query :

qb.phrase().onField("label").sentence("New York").createQuery()

But this query returns both "New York" and "New York weather", ie my sentence is used like a prefix when I would like to use it like an equals.

How to do this using hibernate search ?

Under 5.1.2.4 it mentions a 'slop factor'

https://docs.jboss.org/hibernate/search/4.1/reference/en-US/html_single/#search-query-querydsl

Try a slop factor of zero?

qb.phrase().withSlop(0).onField("label").sentence("New York").createQuery()

also try using the Lucene API as mentioned in this question.

Finding exact match using Lucene search API

Your use case is a straight forward one and probably doesn't warrant the Hibernate Search query DSL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM