Search code examples
collectionssolrrequestoperatorslogical-operators

Solr search query using multiple fields


My objects have fields: Title, Image, Description, web, type, url, id and _version (collection of recipes). The type is the category of recipe (dessert, first course...). I want to find all elements with title or description containing "pasta pomodoro" only in the type: secondi-piatti (that is, second course). My query is:
(Title:pasta,pomodoro OR Description:pasta,pomodoro) AND (type:secondi-piatti).
The title and description queries are correct (because in this way it can find also elements containing only "pomodoro" or "pasta"), but I don't understand why in my results I have also recipes of type:primi-piatti (that is, first course), because I suppose that with an AND it will find only elements of that type. Does someone know what is the problem?

Solr

I have also to say that if I write the same query but instead of using type:secondi-piatti, I use type:dolci (desserts), it works because it displays only recipes containing "pasta" as desserts and not recipes of the first course. In summary this structure of the query follow the type that I want only if the type is dolci (dessert), with all other types (primi, secondi-piatti, antipasti, contorni) it doesn't work.


Solution

  • I found out the problem. Having a type with two terms it searches the types that contains one term or the other one, in fact piatti belongs both to primi-piatti and to secondi-piatti. I have to write:

    (Title:pasta,pomodoro OR Description:pasta,pomodoro) AND type:(secondi AND piatti)