2
votes

I am using Solr 6.0.0

I am tring to filter out unwanted suggestions from Solr Suggester. In my Solr database I have all my products

My products all have a boolean field "ShowOnSite". Products that are ready for sale have this value set to true. Products not yet ready have it set to false.

When I try to filter the suggested results from the suggester using this boolean field, I always get 0 results, even though I have plenty of products ready to be shown.

My Products looks somewhat like this like this:

<field name="id"                type="string"      indexed="true" stored="true" required="true"/>
<field name="Name"              type="string"      indexed="true" stored="true"/>
<field name="ShowOnSite"        type="boolean"     indexed="true" stored="true" />
<field name="text_autocomplete" type="textSuggest" indexed="true" stored="true"/>

The textSuggest fieldType has the following configuration:

  <fieldType class="solr.TextField" name="textSuggest" positionIncrementGap="100">
    <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>

My suggester looks like this

  <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="suggest">true</str>
      <str name="suggest.count">20</str>
      <str name="wt">json</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

  <searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">default</str>
      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
      <str name="highlight">true</str>
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="field">text_autocomplete</str>
      <str name="weightField">InStock</str>
      <str name="contextField">ShowOnSite</str>
      <str name="suggestAnalyzerFieldType">textSuggest</str>
      <str name="buildOnStartup">true</str>
    </lst>
  </searchComponent>

My query looks like this:

/suggest?suggest.q={querystring}&suggest.cfq=true

Expected I receive only the products that has "ShowOnSite" == true

Actual I receive 0 proucts from the suggester

I have tried other configurations aswell. By using not true I get all products:

/suggest?suggest.q={querystring}&suggest.cfq=-true

I have also tried to add the field name in the cfq. This yields 0 products:

/suggest?suggest.q={querystring}&suggest.cfq=ShowOnSite:true

EDIT1 I have also tried using either 0 or 1 for false and true respectively. These do not work either

2
Initial guess is that this is caused by the boolean type of the field, since no analysis happens as far as I know for the values used by the cfq. Try with 0, or better; make a secondary field as a string field and store the false or true value verbatim in that field - and try filtering by that instead.MatsLindh
@MatsLindh Thank you for your suggestions. I have tried this and it works. I just have a hard time understanding why a boolean value would not work. Filtering on booleans seems like the most basic thing to implement.Black_bull
My guess (and I haven't verified this) is that the boolean field type is a special field type created in Solr and isn't backed directly in Lucene with a similar type. So when the token true is sent back to the index as the token (no analysis etc. taking place), it doesn't match what token is actually stored. You can go deeper into this by looking at what has been actually stored in the index for that field and true/false values. But as I said, this is a guess. It might be wildly wrong.MatsLindh

2 Answers

2
votes

Initial guess is that this is caused by the boolean type of the field, since no analysis happens as far as I know for the values used by the cfq.

Make a secondary field as a string field and store the false or true value verbatim in that field - and use that for filtering instead.

0
votes

As suggested by MatsLindh. Use a text field instead. The easiest way is to just copy that field:

Add this to the managed-schema file of your index (in Solr):

  <field name="THE_FIELD_TO_BE_USED_BY_THE_SUGGESTER" type="text_general" indexed="true" stored="true" multiValued="false"/>
  <copyField source="YOUR_BOOLEAN_FIELD" dest="THE_FIELD_TO_BE_USED_BY_THE_SUGGESTER" maxChars="30000" />