Suraj Chakraborty
Suraj Chakraborty

Reputation: 105

How can i perform an sql LIKE search using Hibernate Search?

I want to perform LIKE search (e.g. all words containing 'abc' i.e. %abc%) but by using the Hibernate Search API.

Is there a way to do it by using the existing analyzers ?

If so which one is better in terms of performance; SQL or Hibernate Search for this case ?

Upvotes: 1

Views: 210

Answers (2)

Martin Braun
Martin Braun

Reputation: 602

Maybe have a look at this:

http://lucene.apache.org/core/4_10_2/core/org/apache/lucene/search/RegexpQuery.html?is-external=true

But note this:

"Note this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow RegexpQueries, a Regexp term should not start with the expression .*"

This should be included in Hibernate-Search

Upvotes: 1

Sanne
Sanne

Reputation: 6107

Correct, Hibernate Search is much more efficient for this than using a SQL LIKE criteria.

The StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer) is a good fit, other analyzers will do more advanced text splitting.

Upvotes: 0

Related Questions