0

I have solr schema with field categoryName as stringwhich has hierarchical data as follows Fruits & Vegetables/Fruits Fruits & Vegetables/Vegetables categoryName field has following fieldType

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

When I want to search only Vegetables here is my query

/query?q=categoryName:Vegetables

This gives me all the categories including Fruits

/query?q=(categoryName:/Vegetables/) This gives me all the categories including Fruits and following is the debug

"rawquerystring": "(categoryName:/Vegetables/)",
"querystring": "(categoryName:/Vegetables/)",
"parsedquery": "RegexpQuery(categoryName:/vegetables/)",
"parsedquery_toString": "categoryName:/vegetables/"

/query?q=categoryName:/\/Vegetables/ This gives me all the categories including Fruitsand following is the debug

"rawquerystring": "(categoryName:/\\/Vegetables/)",
"querystring": "(categoryName:/\\/Vegetables/)",
"parsedquery": "RegexpQuery(categoryName:/\\/vegetables/)",
"parsedquery_toString": "categoryName:/\\/vegetables/"

/query?q=(categoryName:/Vegetables$/) This gives me zero results and following is the debug

"rawquerystring": "(categoryName:/*Vegetables$/)",
"querystring": "(categoryName:/*Vegetables$/)",
"parsedquery": "RegexpQuery(categoryName:/*vegetables$/)",
"parsedquery_toString": "categoryName:/*vegetables$/"

What is the correct way to get exclusive documents of type Vegetables? Or Fruits

Srinivas
  • 553
  • 9
  • 21
  • That field doesn't really seem to be an actual StrField, as `categoryName:Vegetables` doesn't match any of the actual values. A StrField only produces exact matches. – MatsLindh Jul 23 '15 at 09:08
  • @MatsLindh, I have updated my question with exact field type information, categoryName is not a string field. Please tell me if I have to change the field type to string here in this case, since categoryName would have spaces and characters like `&` I went with `text_general` type – Srinivas Jul 23 '15 at 09:15

0 Answers0