duanjupiao4730 2012-10-22 07:25
浏览 62
已采纳

Apache Solr Escape查询

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" />
  • 写回答

1条回答 默认 最新

  • dongye9071 2012-10-22 10:27
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64