Reputation: 11
I'm currently experimenting with Solr and attempting to get a query to only retrieve documents where all the provided tokens match.
For example, assume I have a field called data which when indexed uses a PatternTokenizer to split the incoming string on a delimiting character, e.g. '/'. For the input string "Foo/Bar/Baz" I would expect to get three tokens (if my understanding of the docs is correct!). Adding a few more documents I end up with:
Foo/Bar/Baz ==> Foo, Bar, Baz
Foo/Far/Faz ==> Foo, Far, Faz
Boo/Bar/Baz ==> Boo, Bar, Baz
When I come to query this field however, I get results I wasn't quite expecting. Using the query:
+data:Foo/Bar
I would expect this to match documents which contained both Foo and Bar, but instead it returns documents which contain at least Foo or Bar, scoring those with both terms higher. Other than altering the query such that it resembles:
+data:Foo +data:Bar
is there any way to change the behaviour such that instead of matching all 3 of my example documents, it matches only the one?
This experiment was done using the nightly builds of Solr 4.0.
Thanks
Upvotes: 1
Views: 1362
Reputation: 804
You could set the default operator to be AND in schema.xml which will make all queries an AND search.
http://wiki.apache.org/solr/SchemaXml#Default_query_parser_operator
You could also change it per-query by adding q.op=AND to the solr url.
http://solrhost/solr/select?q=solr+lucene&q.op=AND
Upvotes: 3