Solr - {! Ex} on facet request

Background

I am trying to combine two functions that work perfectly separately, but cannot make them work together.

* 1) As described in the solr wiki , I can mark a specific fq and then exclude it on my facet.field. This will make my estimates of the fashions remain unchanged even when choosing a value, for example:

fq={!tag=pt}price:100&facet=true&facet.field={!ex=pt}price 

* 2) I want to use facet.query as follows:

 facet=true&facet.query=price:[0 TO 100]&facet.query=price:[100 TO *] 

So, I want to combine * 1 and * 2, this is what I tried:

 fq={!tag=pt}price:[0 to 100]&facet=true&facet.query={!ex=pt}price:[0 TO 100]&facet.query={!ex=pt}price:[100 TO *] 

What actually happens is what I get back from Solr:

 <lst name="facet_queries"> <int name="{!ex=pt}price:[0 TO 100]">8</int> <int name="{!ex=pt}price:[100 TO *]">19</int> </lst> 

My question is:

Why {! ex = pt} part of the name? It ruined my logic. Maybe I abused it, if so, what is the right way?

Additional Information

I expect the following: (Same as what I get when starting * 2 without * 1)

 <lst name="facet_queries"> <int name="price:[0 TO 100]">8</int> <int name="price:[100 TO *]">19</int> </lst> 

This makes sense, because if I run * 1, this is what I get in facet_fields:

 <lst name="facet_fields"> <lst name="price"> <int name="80">8</int> <int name="150">19</int> </lst> </lst> 

He does not say name = "{! Ex = pt} price"

+7
lucene solr
source share
3 answers

I assume this is because:

  • *1 example uses facet.field , which should be called the same as the field that it uses (without any exceptions). In the example
  • *2 uses facet.query , which should represent the query (with all the possible information used in the query ... it would be pointless to display part of the query, for example, without exception of the part)

In any case, if you need to specify a specific cell that uses exclusive functionality, then this can be done as follows (using the key parameter):

facet.field={!ex=pt key=good_name_for_a_facet}price

The same works for facet.query ... For example, if you want to hide the ex part:

facet.query={!ex=pt key=$queryOne}price:[0 TO 100]

where queryOne is part of the raw parameter passed to queryOne=price:[0 TO 100] as queryOne=price:[0 TO 100]

So, the final request will look something like this:

 fq={!tag=pt}price:[0 TO 100]&facet=true&facet.query={!ex=pt key=$queryOne}price:[0 TO 100]&facet.query={!ex=pt key=$queryTwo}price:[100 TO *]&queryOne=price:[0 TO 100]&queryTwo=price:[100 TO *] 

Ps I used an external parameter for the key, because in this way - there is no need to manually escap the special characters.

+4
source share

I ran into this problem and solved it by adding the local param key to the {! ex}. So for your example, I would do:

fq = {! tag = pt} price: [0 to 100] & facet = true & facet.query = {! ex = pt key = "0 to 100" } price: [0 TO 100] & facet.query = {! Ex = pt key = "100 TO *" } price: [100 TO *]

The reason for this is because QueryFacet is handled differently than FieldFacet (facet.field vs facet.query). Solr only removes the local parameter, which is {! Ex ...} in FieldFacet keys. I really tracked this down to the code for this, as you can see on line 680 in FacetComponent.java (v 4.6) from the link below:

http://svn.apache.org/viewvc/lucene/dev/tags/lucene_solr_4_6_0/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java?view=markup

I did not continue to monitor it, because in my use case I need a "pretty" key :)

+1
source share

Here is how I solved it:

 for (int i = 0; i < facetQueries.size(); i++) { String value = facetQueries.get(i); query.addFacetQuery(String.format("{!ex=%s key=$fQValue_%s}%s", value, i, value)); query.add(String.format("fQValue_%s", i), value); } 
+1
source share

All Articles