lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From idioma <>
Subject Filter query exclusion with SolrJ
Date Wed, 26 Feb 2014 22:38:09 GMT
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:


Whereas the XML dump will look like:

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

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",
        _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();

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



        for (int i=0; i<_facetFields.length; i++) {

        for (int i=0; i<facets.size(); 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,


View this message in context:
Sent from the Solr - User mailing list archive at

View raw message