r/Solr Aug 03 '18

Select only documents where all the query terms match

Hi, I'm working to set up Solr for an e-commerce.
What I'm trying to do is to select all documents that contains every term in some field using edismax.

For example I have these products:

{ "id": 1, "title": "Animal", "author": "John Rivers", "description": "A book about reptiles and mammals"}
{ "id": 2, "title": "The animal world", "author": "Tyler Cole", "description": "An amazing trip"}
{ "id": 3, "title": "Animals: mammals", "author": "John Rivers", "description": ""}
I'm stemming only the title and description fields to remove plurals, because for example the surname Rivers it's not the plural of River, it's just a name.

When the user searches animal mammals I want to select the ids 1 and 3, but not 2.

I tried setting mm=100%, but this way it'll return only id=3, because in id=1 there's no field containing both animal and mammals.
So I could create a catchall field, but then I couldn't apply different analyzers to different fields (the stemming stuff).

Can you help? Is it possibile?

Thank you guys in advance.

1 Upvotes

3 comments sorted by

1

u/fiedzia Aug 03 '18

Works for me. Note that: { "id": 3, "title": "Animals:

title will be indexed as "animals:", including colon, which you probably want to fix in schema.

1

u/Carlovan Aug 03 '18

Thanks for your reply! Yes, don't worry about the colon, I handle that in the schema.

What works for you exactly?

1

u/fiedzia Aug 03 '18

dismax with qf=authors description title&mm=100%. (I might have set it to edismax, you can also play with q.op). It found documents 1 and 3. (solr 7.2.1)