9

I am using SolrMeter to test Apache Solr search engine. The difference between Facet fields and Filter queries is not clear to me. SolrMeter tutorial lists this as an exapmle of Facet fields :

content
category
fileExtension

and this as an example of Filter queries :

category:animal

category:vegetable
categoty:vegetable price:[0 TO 10] 
categoty:vegetable price:[10 TO *] 

I am having a hard time wrapping my head around it. Could somebody explain by example? Can I use SolrMeter without specifying either facets or filters?

fassetar
  • 615
  • 1
  • 10
  • 37
Cola
  • 2,097
  • 4
  • 24
  • 30

2 Answers2

15

Facet fields are used to get statistics about the returned documents - specifically, for each value of that field, how many returned documents have that value for that field. So for example, if you have 10 products matching a query for "soft rug" if you facet on "origin," you might get 6 documents for "Oklahoma" and 4 for "Texas." The facet field query will give you the numbers 6 and 4.

Filter queries on the other hand are used to filter the returned results by adding another constraint. The thing to remember is that the query when used in filtering results doesn't affect the scoring or relevancy of the documents. So for example, you might search your index for a product, but you only want to return results constrained by a geographic area or something.

Ansari
  • 8,168
  • 2
  • 23
  • 34
  • Thank you! That is a great explanation. Do you think Faceting and filtering queries adds to the total search time of the query? – Cola Jul 13 '12 at 20:49
  • 1
    You're welcome. They must add a little time - it's easy enough to benchmark and test :) Depending on the complexity of the filter it might take some time. Faceting should be fairly straightforward in the implementation and shouldn't add *that much* time. – Ansari Jul 13 '12 at 20:57
  • 2
    Not necessarily true, filter queries are cached and processed first so repeated filters can reduce your search time. http://wiki.apache.org/solr/SolrCaching#Types_of_Caches_and_Example_Configuration – sclarson Mar 25 '13 at 00:05
2

A facet is an field (type) of the document, so category is the field. As Ansari said, facets are used to get statistics and provide grouping capabilities. You could apply grouping on the category field to show everything vegetable as one group.

Edit: The parts about searching inside of a specific field are wrong. It will not search inside of the field only. It should be 'adding a constraint to the search' instead.

Performing a filter query of category:vegetable will search for vegetable in the category field and no other fields of the document. It is used to search just specific fields rather than every field. Sometimes you know that the term you want only is in one field so you can search just that one field.

firelore
  • 498
  • 3
  • 11
  • Thank you! "It is used to search just specific fields rather than every field. " I am a bit confused by this, because what Ansari said seems to conflict with this statement. "Filter queries on the other hand are used to filter the returned results by adding another constraint. " So is it that specific fields are filtered from the search results or queries are searched for only in specific fields? – Cola Jul 13 '12 at 20:52
  • I believe Ansari is correct, in that they are another constraint. It would make more sense since filters can be cached for other queries and that you can have fairly complex filters (such as ranges). – firelore Jul 13 '12 at 21:06
  • Sorry to butt in here but firelore your answer is inaccurate in a number of respects. For one Grouping (collapsing) and faceting are totally different things. Secondly you can search for a single field in the main query itself in exactly the same way. – Ansari Jul 13 '12 at 21:06
  • Ack, I consider myself corrected on both counts. I was quite wrong on the grouping part. Here are the relevant parts to look through http://wiki.apache.org/solr/SolrFacetingOverview http://wiki.apache.org/solr/CommonQueryParameters#fq – firelore Jul 13 '12 at 21:16