solr faceted search - how do I specify multiple fields on the Solr Query UI?
Asked Answered
S

6

15

I'm a newbie to solr and tying my hands at solr. Can some one here please explain how to specify multiple facet fields for a given search.

I'm using the Solr Admin UI/ query ink and it allows me to specify only one field. I would however like to facet on multiple fields like region industry stock-exchange etc on my company search.

I have gone through the solr wiki and relevant doc links like the one below http://docs.lucidworks.com/display/solr/Query+Screen

but none of them seem to explain how to specify multiple fields. I want to build something like the usual Amazon/Walmart etc search ui that provides multiple facets and counts when trying to search for a product on my planned cmpany search page.

Siloum answered 13/6, 2013 at 15:30 Comment(2)
Got to this question googling for multiple nested facets, for anyone else who is looking for that (like total positive, negative and neutral comments by month) here are some links: yonik.com/solr-subfacetsDripstone
Is the same possible through Solr panel(UI) ?Alike
M
17

You can query multiple facet fields. Just write with the syntax:

.../select?q=&facet=true&facet.field=<field1>&facet.field=<field2>
Mckeon answered 24/1, 2014 at 11:1 Comment(3)
Looks like you got this. But to be clear.. since I was confused. You use the "Raw Query Parameters" field for this.Constanta
This does not seem to work as of version 7.0.0. SolrException, undefined field: "field1,field2"Staffer
This works just fine in recent Solr, <field1> and <field2> are placeholders--you're meant to replace those values with the field names in your dataTortoiseshell
S
4

You are looking for json.facet

It's available from solr 5(some advanced features are available from solr 6). Basically that means you can insert your facet search parameters via json to the url.

It looks like this(live example):

&facet=true&json.facet={"filed1":{"type":"terms","field":"filed1","limit":2000},"filed2":{"type":"terms","field":"filed2","limit":2000}}

There is also a shorter version:

&facet=true&json.facet={"field1":{"terms":"field1"},"field2":{"terms":"field2"}}

You can find more information here

Synergy answered 6/7, 2017 at 10:58 Comment(0)
B
2

When you execute the search in the Solr Query UI, it will show the actual url that is being sent to Solr above the results pane. Click on that url and it will open a new window in your browser to that url. From there you can add additional parameters to the url to get facteing on multiple fields, by adding additional &facet.field=<your field> entries.

Please see the Solr Faceting Parameters reference for more details and other options.

Benzoin answered 13/6, 2013 at 15:42 Comment(0)
A
0

The Solr Admin UI allows you to specify multiple facets fields i.e. a csv of fields in the facet.field parameter. You need to check the facet checkbox and then you will get more options.

If you are querying Solr using a link then the link should look like - facet=true&facet.field=field1&facet.field=field2.

Austerity answered 13/6, 2013 at 15:42 Comment(1)
Maybe that worked in 2013, but in a recent version, 8.2, it only works if you specify it in the URL, and not in the edit field provided by the admin panel. The edit field in the admin panel only works with one field. Putting two fields: FieldA, FieldB in CSV format creates a single field facet.field="FieldA, FieldB" in the generated URL which is incorrect. However, if you edit the query it produces to separate them as facet.field=FieldA&facet.field=FieldB, then of course it works. But the requester wanted to use the Admin UI directly, and your answer suggests that they can.Gauss
L
0

In 2024 with Solr 9.4, you cannot use multiple fields in facet.field

Instead, use the json.facet textarea box and specify your facet definition using a bit of JSON like:

{
    categories:{
       "type":"terms",
      "field" : "category",
      "limit" : 5
    },
    machine_types:{
       "type":"terms",
      "field" : "machine_type",
      "limit" : 5
    },
}

More info here: https://solr.apache.org/guide/solr/latest/query-guide/json-facet-api.html

Linguiform answered 2/3 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.