Hi,

Your example response (<facetEntry count="20">) looks like customized. Your 
SolrJ program also has Element class that I have never seen.

By the way, fq=-author:Dickens, Janet is parsed as -author:Dickens 
defaultField:Janet


Assuming it is String type, either use quotes fq=-author:"Dickens, Janet" or 
term query parser:
fq=-{!term f=author}Dickens, Janet


Ahmet


On Thursday, February 27, 2014 12:42 AM, idioma <corda.ila...@gmail.com> wrote:
I use a SolrJ-based client to query Solr and I have been trying to construct
HTTP requests where facet name/value pairs are excluded. The web interface I
am working with has a refine further functionality, which allows excluding
one or more facet values. I have 3 facet fields: domain, content type and
author and I would like to be able to handle faceting by exclusion on each
of them. For example, q = Dickens AND fq=-author:Dickens, Janet will
construct the following HTTP request:

/solr/solrbase/select?q=Dickens&fq=-author:Dickens%2c+Janet&wt=json&indent=true

Whereas the XML dump will look like:

             <facets>
              <facet name="author">
                <facetEntry count="20">Dickens, Charles</facetEntry>
                <facetEntry count="10">Dickens, Sarah</facetEntry>
              </facet>
            </facets>

So far, the Java implementation I am working with does not seems to handle
filter query exclusion:

private HttpSolrServer solrServer;
solrServer = new HttpSolrServer("http://localhost:8983/solr/";);

private static final String CONFIG_SOLR_FACET_FIELD = "facet_field";
private String[] _facetFields = new String[] {"author"};

private static final String CONFIG_SOLR_FACETS = "facets"
     Element el = myParams.getChild(CONFIG_SOLR_FACETS);

        _facetUse = el.getAttributeValue("useFacets", "true");
        _facetMinCount = el.getAttributeValue("minCount",
String.valueOf(1));
        _facetLimit = el.getAttributeValue("limit", String.valueOf(20));


List vals = el.getChildren(CONFIG_SOLR_FACET_FIELD);
        if (vals.size() > 0) {
            _facetFields = new String[vals.size()];
            for (int i=0; i < vals.size(); i++) {
            _facetFields[i] = ((Element)vals.get(i)).getTextTrim();
            }  
        }

SolrQuery query = new SolrQuery();
query.setQuery(qs);


List facetList = doc.getRootElement().getChildren("facet");
                    Iterator<String> it = facetList.iterator();
                    while (it.hasNext()) {
                        Element el = (Element)it.next(); //
                        String name = el.getAttributeValue("name"); 
                        String value = el.getTextTrim();
                        if (name != null && value != null) {    
                            facets.add(name+":"+value);
                        }

                    }


query.setQuery(qs).
           setFacet(Boolean.parseBoolean(_facetUse)).
           setFacetMinCount(Integer.parseInt(_facetMinCount)).
           setFacetLimit(Integer.parseInt(_facetLimit)).

        for (int i=0; i<_facetFields.length; i++) {
            query.addFacetField(_facetFields[i]);      
        };

        for (int i=0; i<facets.size(); i++) {
            query.addFilterQuery(facets.get(i));
        };
  return query;

    }
I was recommended to use something along these lines:

  SolrQuery solrQuery = new SolrQuery();
  solrQuery.set(CommonParams.FQ, “-author:Dickens,Janet”);

However, this seems to be a hardcoded approach and it cannot be easily
applied across all 3 facets and all facet values. I have looked at this, but
still it is not clear to me how I should include the exclusion variant in my
current code. Can you help with this?

Thanks indeed,

I.



--
View this message in context: 
http://lucene.472066.n3.nabble.com/Filter-query-exclusion-with-SolrJ-tp4119974.html
Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to