solr清理查询

我在轨道上使用带有ruby的solr。 这一切都运行良好,我只需要知道是否有任何现有的代码来清理用户输入,比如以查询开头? 要么 *

我不知道任何代码可以做到这一点,但理论上可以通过查看Lucene中的解析代码并搜索throw new ParseException (只有16个匹配!)来完成。

在实践中,我认为你最好只是在代码中捕获任何solrexception并显示“无效查询”消息或类似的东西。

编辑:这里有几个“消毒剂”:

Solr安全性和Solr查询语法维基页面可能是相关的。

如果您正在使用带有PHP的日光浴室 ,那么您可以使用Solarium_Escape::term()方法。

 /** * Escape a term * * A term is a single word. * All characters that have a special meaning in a Solr query are escaped. * * If you want to use the input as a phrase please use the {@link phrase()} * method, because a phrase requires much less escaping.\ * * @link http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters * * @param string $input * @return string */ static public function term($input) { $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/'; return preg_replace($pattern, '\\\$1', $input); }