Question

I'm using Apache Solr with Solarium client library for PHP.

The problem is special character, a dash (-).

When I have a dash in my search query, I don't get any matches.

I tried to solve this by using Solarium_Query_Helper::escapeTerm(). But I don't get any matches again. The dash is being escaped with a backslash \.

What is the solution for this problem?

I was thinking about escaping all fields when indexing, but that doesn't sound like a good idea.

Here is the part of my schema.xml:

 <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" enablePositionIncrements="true" />
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>
...
<fields>
...
  <field name="myfield" type="text_general" indexed="true" stored="true" />
</fields>
...
<defaultSearchField>text</defaultSearchField>
<copyField source="myfield" dest="text" />
Was it helpful?

Solution

The are some special characters that you need to escape. They are listed here:

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \

You can escape them using the backslash \. I'm not a Solarium expert but the function you're using seems to do what needs to be done. Probably there is another reason why you don't get the expected matches back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top