开发者

Query problem in Solr

We're using Solr to search on a Shop index and a Product index. Currently a Shop has a field shop_keyword which also contains the keywords of the products assigned to it. The shop keywords are separated by a space. Consequently, if there is a product which has a keyword "apple" and another which has "orange", a search for shops having Apple AND Orange would return the shop for these products.

However, this is incorrec开发者_Python百科t since we want that a search for shops having Apple AND Orange returns shop(s) having products with both "apple" and "orange" as keywords.

We tried solving this problem, by making shop keywords multi-valued and assigning the keywords of every product of the shop as a new value in shop keywords. However as was confirmed in another post Querying Solr documents with one of the fields multi-valued, Solr does not support "all words must match in the same value of a multi-valued field".

(Hope I explained myself well)

How can we go about this? Ideally, we shouldn't change our search infrastructure dramatically.

Thanks!

Krt_Malta


I am going to assume shop_keyword is a text field.

A keyword search of Apple AND Orange would return only shop_keyword terms that contain both Apple and Orange, provided you are searching on that field exclusively (shop_keyword:Apple AND Orange). For example, you should only see results that contain:

Apple Orange

And not:

Apple Mango

(I was able to confirm this on my local Solr instance with a text field)

However, you would see results that contain:

Apple Lime Orange Tree

(where "Orange Tree" is a single word but has spaces)

From the link you posted, it seems like this is the problem. So your real problem is that you have spaces in your keywords, which Solr is also using as a delimiter of sorts, in which case the technical solutions listed there are the only ones I know of. However...

If you have control of the terms and they aren't used in a free text search (or for google), you could consider removing the spaces from the keywords and adding quotes to your search. That would solve your problem:

shop_keyword:"Apple" AND "Orange"

Wouldn't return "Orange_Tree".

If you went this route you could use a separate field to index terms for free text search and other non-programmatic purposes.

Not ideal, but I hope that kinda helps =).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜