I have a text-field called name in my schema.xml. A query q=name:(organic) returns the following documents:
<doc>
<str name="id">ontology.category.1483</str>
<str name="name">Organic Products</str>
</doc>
<doc>
<str name="id">ontology.keyword.4896</str>
<str name="name">Organic Stores</str>
</doc>
This is perfectly right in a normal Solr Search, however I would like to construct the query so that it doesn’t return anything because ‘organic’ only matches 1 of the 2 words available in the field.
A better way to say it could be this: Only return results if all tokens in the field are matched. So if there are two words (tokens) in a field and I only match 1 (‘organic’, ‘organics’,‘organ’ etc.) I shouldn’t get a match because only 50% of the field has been searched on.
Is this possible in Solr? How do I construct the query?
Due to time contraints, I had to resort to the following (hacky) solution.
I added the term count to the index via a DynamicField field called
tc_i.Now at query time I count the terms and append it to the query, so
q=name:(organic)becomesq=name:(organic) AND tc_i:(1)and this won’t return documents for “organic stores” / “organic products” obviously because theirtc_ifields are set at 2 (two words).