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 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,