2012-04-02 43 views
3

websolr正在恢复搜索 “ - ” 在websolr

RSolr::Error::Http - 400 Bad Request 
Error: <html><head><title>Apache Tomcat/6.0.28 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - org.apache.lucene.queryParser.ParseException: Cannot parse '----': Encountered &quot; &quot;-&quot; &quot;- &quot;&quot; at line 1, column 1. 
Was expecting one of: 
    &quot;(&quot; ... 
    &quot;*&quot; ... 
    <QUOTED> ... 
    <TERM> ... 
    <PREFIXTERM> ... 
    <WILDTERM> ... 
    &quot;[&quot; ... 
    &quot;{&quot; ... 
    <NUMBER> ... 

时曾经尝试搜索 “ - ” 字符。

其他特殊字符正常工作,如“:”等我试图使用CGI.escape,但它并没有逃脱这些字符。

回答

2

您是否试过用反斜杠转义它?

正常情况下,当您为文档编制索引时,标记器会自行删除短划线字符,因此您可能只想将短划线除去,除非您的意思是它是否定查询。

完整的Solr查询语法是在这里:http://wiki.apache.org/solr/SolrQuerySyntax

2

正如克里斯正确地指出,你需要转义反斜线。

根据您使用的查询解析器,有一些特殊字符具有含义。在撰写本文时,Lucene的(因此SOLR)是查询分析器赋予特殊的含义这些字符:

您应该参考的文档为Lucene query parser syntax他们的全部意义。默认的Solr查询解析器提供了Lucene查询解析器语法的超集,如SolrQueryParser wiki页面所述。

如果您不想担心逃跑的事情,DisMax Query Parser旨在接受更接近用户输入到搜索框中的输入。最近我还没有测试过各种特殊功能,但通常情况下,它可能会在输入中更加优雅。