Nie Selam
Nie Selam

Reputation: 1451

query to search for occurance of any word of a search string

I have the following documents:

     fName : "Samuel",
     sName : "Erick Jameson"

I want to return the user if the search is by Samuel, Erick, Jameson, Erick Jameson, Samuel Erick etc.

Basically if any word exist in the fName or sName, I want to return it. For now, I have the following query:

 Function.lower(Expression.property("fName")).like(Expression.string("%" + searchTermLC + "%"))))
 .or((Expression.property("lName").like(Expression.string("%" + searchTermLC + "%")));

my search results are:

 Samuel              found
 Erick               found
 Jameson             found
 Erick Jameson       found

the following are not found:

 Samuel Erick
 Erick Samuel
 Samuel Jameson

...

what query would do that?

Upvotes: 0

Views: 29

Answers (1)

Sandy
Sandy

Reputation: 24

There are a few mistakes noted in your query above:

  1. The open close brackets don't match
  2. You forgot about Function.lower(Expression.property("lName")).

I assume when you did your own test, the query syntax was right otherwise you would not have gotten any results.

The results you got are as expected for like operator. If you want the query to include:

Samuel Erick
Erick Samuel
Samuel Jameson

in your results, you can try the In Operator.

Upvotes: 0

Related Questions