title: Faceting with Solr using "string" fields, "text" fields and "copy" fields
body: <p>I have a problem with Solr and Faceting and wondering if anyone knows of the fix. I have a work around for it at the minute, however i really want to work out why my query isn't working. </p>
  
  <p>Here is my Schema, simplified to make it easier to follow:</p>
  
  <pre><code>&lt;fields&gt;
      &lt;field name="uniqueid" type="string" indexed="true" required="true"/&gt;
      &lt;!-- Indexed and Stored Field ---&gt;
      &lt;field name="recordtype" type="text" indexed="true" stored="true"/&gt;
      &lt;!-- Facet Version of fields --&gt;
      &lt;field name="frecordtype" type="string" indexed="true" stored="false"/&gt;
  &lt;/fields&gt;
  
  &lt;!-- Copy fields for facet searches --&gt;
  &lt;copyField source="recordtype" dest="frecordtype"/&gt;
  </code></pre>
  
  <p>As you can see I have a case insensitive field called recordtype and it's copied to a case sensitive field frecordtype which does not tokenize the text. This is because solr returns the indexed value rather than the stored value in the faceting results.</p>
  
  <p>When i try the following query:</p>
  
  <pre><code>http://localhost:8080
  /solr
  /select
  ?version=2.2
  &amp;facet.field=%7b!ex%3dfrecordtype%7dfrecordtype
  &amp;facet=on
  &amp;fq=%7b!tag%3dfrecordtype%7dfrecordtype%3aLarge%20Record
  &amp;f1=*%2cscore
  &amp;rows=20
  &amp;start=0
  &amp;qt=standard
  &amp;q=text%3a%25
  </code></pre>
  
  <p>I don't get any results, however the facteting still shows there is 1 record.</p>
  
  <pre><code>&lt;result name="response" numFound="0" start="0" /&gt; 
   &lt;lst name="facet_counts"&gt;
    &lt;lst name="facet_queries" /&gt; 
   &lt;lst name="facet_fields"&gt;
   &lt;lst name="frecordtype"&gt;
    &lt;int name="Large Record"&gt;1&lt;/int&gt; 
    &lt;int name="Small Record"&gt;12&lt;/int&gt; 
    &lt;int name="Other"&gt;1&lt;/int&gt; 
    &lt;/lst&gt;
    &lt;/lst&gt;
    &lt;lst name="facet_dates" /&gt; 
    &lt;/lst&gt;
  </code></pre>
  
  <p>However if i change the fitler query (line 7 only) to be on the "recordtype" insted of frecordtype:</p>
  
  <pre><code>http://localhost:8080
  /solr
  /select
  ?version=2.2
  &amp;facet.field=%7b!ex%3dfrecordtype%7dfrecordtype
  &amp;facet=on
  &amp;fq=%7b!tag%3dfrecordtype%7drecordtype%3aLarge%20Record
  &amp;f1=*%2cscore
  &amp;rows=20
  &amp;start=0
  &amp;qt=standard
  &amp;q=text%3a%25
  </code></pre>
  
  <p>I get the 1 result back that i want.</p>
  
  <pre><code>&lt;result name="response" numFound="1" start="0" /&gt; 
   &lt;lst name="facet_counts"&gt;
    &lt;lst name="facet_queries" /&gt; 
   &lt;lst name="facet_fields"&gt;
   &lt;lst name="frecordtype"&gt;
    &lt;int name="Large Record"&gt;1&lt;/int&gt; 
    &lt;int name="Small Record"&gt;12&lt;/int&gt; 
    &lt;int name="Other"&gt;1&lt;/int&gt; 
    &lt;/lst&gt;
    &lt;/lst&gt;
    &lt;lst name="facet_dates" /&gt; 
    &lt;/lst&gt;
  </code></pre>
  
  <p>So my question is, is there something i need to do in order to get the first version of the query to return the results i want? Perhaps it's something to do with URL Encoding or something? Any hints from some solr guru's or otherwise would be very grateful.</p>
  
  <p>NOTE: This isn't necessary a faceting question as the faceting is actually working. It's more a query question in that I can't perform a query on a "string" field, even though the case and spacing is exactly the same as the indexed version.</p>
  
  <p>EDIT: For more information on faceting you can check out these blog post's on it:</p>
  
  <ul>
  <li><a href="http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html" rel="noreferrer">http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html</a></li>
  <li><a href="http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit" rel="noreferrer">http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit</a></li>
  </ul>
  
  <p>Thanks</p>
  
  <p>Dave</p>