Developer forum

Forum » CMS - Standard features » New index - the contains expression

New index - the contains expression

Lars Larsen
Reply

Hi

I have an index (new index) and have defined a query on it. One of the expressions in the query is using the "Contains" operator on the productid field. When searching for productid "20032" I get hits on all products having a productid starting with "20032" (eg. "20032-L", "20032-M" etc.). But if I search for "32" I get no hits. Why is that the case when I use the operator "Contains"?


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Lars,

This is because that operator behaves a bit differently than a Contains operation on a string or a LIKE operator in SQL. This is due to how Lucene works with wildcard searches. The behavior is that it checks each term in the search input to see if there is at least one term in the index that starts with those terms. You can think of it like the search routine check each part of the search input against the result to see if there's a result part that begins with the input part.

Consider this sentence as a result in the index: My blue bike.

If I pass "bl bi" into a expression using the Contains operator, it will match anything that contains the parts "bl*" and "bi*", therefore my sentence from above is matched. If I passed in "lue ike", I would get no results, because there are no results containing the parts "lue*" and "ike*".

It is possible in Lucene to change that behavior, but it's strongly recommended not to do that as it comes with a high performance cost. This is the reason it works like this in new indexing.

This is also how Google handles search, by the way -- though they have extra heuristic features surrounding their search.

- Jeppe

Votes for this answer: 1

 

You must be logged in to post in the forum