PDS
PDS

Reputation: 592

Solr and search operators - lucene apache solr

I got problem with search operator '*' (star)

My case is:

I search some doc field(it's dynamic field:

<fieldType name="bwcm_string" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <!-- <tokenizer class="solr.StandardTokenizerFactory"/> -->
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.ReversedWildcardFilterFactory" />
   </analyzer>
  <analyzer type="query">
   <!-- <tokenizer class="solr.StandardTokenizerFactory"/> -->
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

)

<dynamicField name="*_STRING"  type="b_string"  indexed="true"  stored="true" multiValued="false"/>

and I search using query '*\' and query filter by dynamic field with "*B*" and it return only doc where field contain 'B Bug', there are other docs with fields which contains A Bug and they also should be return in this case. Any advice ?

Thanks

Upvotes: 0

Views: 509

Answers (2)

femtoRgon
femtoRgon

Reputation: 33341

Not quite clear whether your query is "*B*" or *B* from your description, but I'm guessing the former.

In this case, your query is for the phrase *B*, that is, the asterisks are not being interpreted as query operators. They are part of the term being searched for. Since you are using LowercaseTokenizer, which is effectively a combination of LetterTokenizer and LowercaseFilter (by the way, following up a LowercaseTokenizer with a LowercaseFilter is redundant), any non-letter will be eliminated from the query, meaning your effective query is for simply: B

Instead, just search for *B*. You may need to setAllowLeadingWildcard(true) on the query parser. Given the cases provided, though, just B* would be quite adequate (and will perform much better).

Upvotes: 1

Fuxi
Fuxi

Reputation: 5488

I think that what you need is ReversedWildcardFilterFactory.

Looks like your exact use case is described here: Wildcard queries and how Solr handles them

Upvotes: 1

Related Questions