2012-04-02 37 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旨在接受更接近用戶輸入到搜索框中的輸入。最近我還沒有測試過各種特殊功能,但通常情況下,它可能會在輸入中更加優雅。