0

I am using filter queries with Solr 4.10.0 / Lucene 4.10.0 and have the strange situation that while

  • fq=areas:Finanz- & Rechnungswesen and
  • fq=areas:"Finanz- & Rechnungswesen"

yield the same set of documents,

  • fq=areas:E-Commerce & Neue Medien and
  • fq=areas:"E-Commerce & Neue Medien"

don't – in the latter case, the set of results is empty.

I executed the queries in the Solr admin UI and checked in the Solr log that the filters correctly translate to the query params

  • fq=areas:Finanz-+%26+Rechnungswesen
  • fq=areas:"Finanz-+%26+Rechnungswesen"
  • fq=areas:E-Commerce+%26+Neue+Medien
  • fq=areas:"E-Commerce+%26+Neue+Medien"

respectively. Only in the last case, the result set is empty. Can anyone explain why this is the case? Unfortunately, Spring Data Solr quotes multi-word filters, so it gives a wrong result in that case.

jpvee
  • 913
  • 1
  • 15
  • 23
  • 2
    have you tried `Criteria.expression` which will take the argument as is? Would you mind sharing the snippet where you construct the query? – Christoph Strobl Apr 10 '15 at 12:15
  • @ChristophStrobl: Thanks a lot for your suggestion; I tried it (constructed the query natively without quotes) and it works indeed, but only in special scenarios: When I use a more complex query (two strings joined with OR), I haven't found any query whatsoever which gives the correct result. Instead, I have now found an ugly workaround by using levenshtein distance: new Criteria(fieldName).fuzzy(value, 1); instead of new Criteria(fieldName).is(value); is returning the desired document set. – jpvee Apr 13 '15 at 10:21

1 Answers1

0

Without seeing the data within your index it's hard to diagnose exactly why you have different numbers of results, however your queries may not be behaving how you expect due to the field syntax.

the filter query areas:Finanz- & Rechnungswesen will be parsed as: areas:Finanz- {default_field}:rechnungswesen where {default_field} is whatever has been configured as your default field when one has not been supplied.

In order to debug these queries more easily, have a look at the results with debugQuery=true, this can also be done in the Solr Admin UI's query interface.

To make sure that all terms are limited to your areas field, use parentheses, e.g:

areas:(Finanz- & Rechnungswesen)

For more details, have a look at the Solr query parser syntax: https://wiki.apache.org/solr/SolrQuerySyntax#Default_QParserPlugin:_LuceneQParserPlugin

Toby Cole
  • 66
  • 3