Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Currently there is nothing built-in. There is activity within the community since October 2010 as you can see in <a href="https://issues.apache.org/jira/browse/SOLR-1913" rel="nofollow noreferrer">SOLR-1913</a>. The attached plugin seems to work also, but it has not made its way into Solr's trunk, yet.</p> <hr> <p>The other way I know and use is similar to the approach described in <a href="https://stackoverflow.com/questions/12636426/apache-solr-bitwise-operations-to-filter-search-results">Apache Solr: bitwise operations to filter search results</a>. I am using multivalued <code>string</code> or <code>int</code> types in my <strong>schema</strong></p> <pre class="lang-xml prettyprint-override"><code>&lt;fields&gt; &lt;!-- other fields --&gt; &lt;field name="ints" type="int" indexed="true" stored="true" multiValued="true" /&gt; &lt;field name="strings" type="string" indexed="true" stored="true" multiValued="true" /&gt; &lt;/fields&gt; </code></pre> <p>To make use of this, translate your integer into a list of <code>Integer</code> or list of <code>String</code>, where each value of the list represents on bit position. If you need to hook this into a DataImportHandler, you can use <a href="http://wiki.apache.org/solr/DataImportHandler#ScriptTransformer" rel="nofollow noreferrer">Solr's ScriptTransformer</a>.</p> <pre class="lang-java prettyprint-override"><code>List&lt;Integer&gt; integers = new ArrayList&lt;&gt;(); List&lt;String&gt; strings = new ArrayList&lt;&gt;(); String binaryString = Integer.toBinaryString(i); for(int c = 0; c &lt; binaryString.length(); c++) { if(binaryString.charAt(c) == '1') { integers.add(c); strings.add(c + "_1"); } else { strings.add(c + "_0"); } } </code></pre> <p>as example <code>5</code> - which is <code>101</code> in binary - would become</p> <ul> <li>integers: [4, 1]</li> <li>strings: [4_1, 2_0, 1_1]</li> </ul> <p>As you can see there is a difference: integers do not hold track which bits are absent whereas strings do. Which of these approaches suits your needs, depends on your use case. If you only need to know which bit is present, pick integers. This will make your index smaller. If you also need to know which bits are absent, pick strings.</p> <p>To query for this is rather simple</p> <ul> <li>integers: <code>q=ints:(1 OR 4)</code></li> <li>strings: <code>q=strings:(1_1 OR 4_1)</code></li> </ul> <p>If you want to exclude a certain bit, you would be tied to strings</p> <ul> <li><code>strings:((1_1 OR 4_1) AND 2_0)</code></li> </ul> <hr> <p>A <strong>caveat</strong> of this way is that there is <em>maxBooleanClauses</em>. Most people do not know it, till they hit it. This defaults to 1024 clauses, which you can see <a href="http://wiki.apache.org/solr/SolrConfigXml#The_Query_Section" rel="nofollow noreferrer">in Solr's Wiki</a>. You may also alter it in your solrconfig.xml. But the bigger you set this value to be and the more clauses your queries have the slower Solr will get.</p> <p>Up to now, we did not face performance issues with this. But we kept under 1024 clauses. This is something you should keep in mind, since I do not know how large your bit sets will be.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload