Reputation: 853
I'm using hibernate-search in my Spring MVC project and I would like to accomplish something but I'm not sure if it's possible. Here is the problem:
I'm using NGramFilterFactoryClass for this and have configured minGramSize=3 and maxGramSize=3.
Let's say my search term is "Keyword"
If I type anything like this:
"ywo", "key", "ord", "blablaordblabla"
query will return "Keyword". This is fine and I understand how this works but what I wanna do is when I type something like:
"bkey", "blablaordblabla"
I don't want to return "Keyword". "Keyword" should be returned only when search term is something like:
"key", "ord", "ywo", "eywo", "word" etc...
So, I guess I'm looking for a '%like%' type query. How can I accomplish this with hinernate-search?
Upvotes: 3
Views: 3218
Reputation: 6107
If you Analyze your input with NGrams you won't be able to perform exact "Like%" queries. You probably want a SimpleAnalyzer or something similar which doesn't completely break your keywords in smaller pieces, or you might want to skip Analysis for this field and index it as-is.
You then combine this with a WildCard Query; note how example in the reference docs uses the keyword element to build the query, which inherently disables the analyzer on the input. (Make sure you scroll down the the Wildcard queries section in the docs).
I assume you're using NGrams because you need them for another use case. Remember you can use the @Fields annotation to index a same property in various different ways, so you could index it with ngrams and also in another form more suited for wildcard queries.
Upvotes: 1
Reputation: 1691
I don't know if is what you are looking for, but maybe you need what is called "wildcard queries".
Try to have a look at this link as reference. Also have a look at this stackoverflow topic
Upvotes: 1