Pergunta

I want to be able to submit a query like this:

car AND (color:blue AND price:[* TO 10000] AND model:Toyota)

and retrieve results like this (assuming these are the most relevant results):

{name : "An old car", color: "blue", price: "6000", model : "Toyota"}
{name : "An old car", color: "red", price: "5000", model : "Toyota"}
{name : "Another old car", color: "blue", price: "9000", model : "Volvo"}
{name : "Another old car", color: "white", price: "11000", model : "Toyota"}

In other words, fuzzy search, but not on the string level but on the "faceting level". I want it work so that articles that match all the requirements always get up top but articles that only match a subset still get retrieved.

Does Solr or any other search framework have support for this? Can I accomplish this using query boosting for example?

Foi útil?

Solução

I believe it can be done by modifying the query somewhat like this (newlines added for readability); although I'm not sure about the boost syntax:

(car AND (color:blue^0.9 OR color:[* TO *]^0.1) 
     AND (price:[* TO 10000]^0.9 OR price:[* TO *]^0.1) 
     AND (model:Toyota^0.9 OR model:[* TO *]^0.1))

Edit:

This solution seems to work quite as I intended in my implementation. Although I added to the weights for the preferred properties. ^1000 seemed to give them enough weight to win over the non preferred.

Outras dicas

If you are using a url query, for example in the admin frontend a query looks like this:

q=car&fq=color:blue&fq=price:[* TO 10000]&fq=model:Toyota

Or maybe for your example it is

q=*&fq=name:car&fq=color:blue&fq=price:[* TO 10000]&fq=model:Toyota

Now the results depend on the configured logic operator which can be configured in the schema.xml, default operator is AND, see here:

Schema documentation

For a single field a filterquery is like a String.contains() function in java.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top