q and logical operators.

Hi all,

I have a strange problem which seems to stomp my google-fu skills.

We have a webshop which has a solr based search mechanism which allows
customers to search for products based on a range of different fields,
including item numbers. I recently added a feature which allows users who
are logged in to search for custom item numbers which are associated with
that user. What this means in practical terms is that when a user logs in,
the solr search query has to look in one extra field compared to when the
user is not logged in.

The standard non-logged in search query looks like this (I only included
the relevant first part of the query.):
http://
<secret>/solr/11731_Danish/search?defType=edismax&q=Visitkort+display+Durable+4+rum+til+240+kort

When doing the same search while logged in, the query looks like this:
http://
<secret>/solr/11731_Danish/search?defType=edismax&q=Visitkort+display+Durable+4+rum+til+240+kort+OR+customer_5266762_product_number_string:Visitkort+display+Durable+4+rum+til+240+kort

Here I add an extra field, customer_5266762_product_number_string (5266762
being the logged in users internal ID), basically including the same search
tearm two times.

The above examples work beautifully when searching for a specific item
number stored in the customer_5266762_product_number_string. The problem is
that when a user is logged in and want to do regular searches, the system
begins to break down. In the specific example above, I expect to get a
single hit for a product with the title "Visitkort display Durable 4 rum
til 240 kort". It works as expected with the first non-logged-in example.
The second logged-in example returns over 7000 hits. I would expect it to
return just one hit since there is nothing relevant in the
customer_5266762_product_number_string for this query.

Now, the following is where my brain begins to melt down.

I discovered that if you put the search text in quotation marks, it will
work as expected, but doing so breaks another loved feature we have:

If i want a hit on the product named "Visitkort display Durable 4 rum til
240 kort", I could do a search for "vis dis dur", and it would show up. I
could also get a hit if i write "vis dur dis", changing the orden of the
words. If i put the search query in quotation marks, I break that
capability. I would get a hit for "vis dis dur", but "vis dur dis" no
longer returns anything. This is not an option for me.

It is entirely posible that there is a better way of implementing this and
fortunately, a rewrite is possible at this time. If my basic approach is
correct and I just don't understand how to construct my query correctly, an
RTFM pointer will be most welcome!

-- 
Med venlig hilsen / Best regards

*John Nielsen*
Programmer



*MCB A/S*
Enghaven 15
DK-7500 Holstebro

Kundeservice: +45 9610 2824
p...@mcb.dk
www.mcb.dk

Reply via email to