Solr 查询不解析正斜杠
正斜杠“/”是 solr 字段名称中的保留字符吗?
我在编写 solr 排序查询时遇到问题,该查询将解析包含正斜杠“/”的字段
当对我的 solr 服务器进行 http 查询时:
q=*&sort=normal+desc
会工作,但
q=*&sort=with/slash+desc
q=*&sort=with%2Fslash+desc
两者都会失败,说“不能在多值字段上使用 FieldCache:与”
每个solr 文档包含两个 int 字段“正常”和“with/slash”。使用我的 solr 模式对字段进行索引,
...
<field name="normal" type="int" indexed="true" stored="true" required="false" />
<field name="with/slash" type="int" indexed="true" stored="true" required="false" />
...
是否有任何特殊方法需要在 solr 中编码正斜杠?或者我可以使用其他分隔符吗?我已经在使用“-”和“.”用于其他目的。
Is the forward slash "/" a reserved character in solr field names?
I'm having trouble writing a solr sort query which will parse for fields containing a forward slash "/"
When making an http query to my solr server:
q=*&sort=normal+desc
Will work but
q=*&sort=with/slash+desc
q=*&sort=with%2Fslash+desc
Both fail say "can not use FieldCache on multivalued field: with"
Each solr document contains two int fields "normal", and "with/slash". With my solr schema indexing the fields as so
...
<field name="normal" type="int" indexed="true" stored="true" required="false" />
<field name="with/slash" type="int" indexed="true" stored="true" required="false" />
...
Is there any special way I need to encode forward slashes in solr? Or are there any other delimiter characters I can use? I'm already using '-' and "." for other purposes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚遇到了同样的问题,经过一些实验发现,如果字段名称中有正斜杠,则必须在 Solr 查询中用反斜杠转义它(但请注意,您这样做不必在字段列表参数中执行此操作,因此在“q”字段中输入包含 my_value 的搜索
/my/field/name
:\/my\/field \/名称:我的值
我还没有尝试过排序字段,但尝试一下并让我们知道:)
这是在 Solr 4.0.0 alpha 上。
I just came across the same problem, and after some experimentation found that if you have a forward-slash in the field name, you must escape it with a backslash in the Solr query (but note that you do not have to do this in the field list parameter, so a search looking for
/my/field/name
containing my_value is entered in the "q" field as:\/my\/field\/name:my_value
I haven't tried the sort field, but try this and let us know :)
This is on Solr 4.0.0 alpha.
来自 solr wiki https://wiki.apache.org/solr/SolrQuerySyntax :
From the solr wiki at https://wiki.apache.org/solr/SolrQuerySyntax :
就我而言,我需要使用通配符
*
搜索正斜杠/
,例如:我尝试像这样转义它:
但这也不起作用。
解决方案是用双引号
"
包裹文本,就像这样做:无论是否转义正斜杠都返回相同的结果
In my case I needed to search for forward slash
/
with wild card*
, e.g.:I Tried to escape it like so:
but that didn't work also.
the solution was to wrap the text with double quote
"
like do:both returned the same result with and without escaping the forward slash
就我而言,我使用 Solr 管理 UI 来运行查询
我必须搜索带有正斜杠的 URL。
文本:www.myurl.com/test =>返回不需要的结果
文本:“www.myurl.com/test”=>返回了想要的结果。
对于 Solr 搜索索引的实现,如果您使用 Solr 管理 UI,则将搜索字符串括在引号中就足够了。
In my case I was using Solr Admin UI to run queries
I had to search for a URL with a forward slash.
text:www.myurl.com/test => returned unwanted results
text:"www.myurl.com/test" => returned desired results.
For your implementation of Solr Search indexing, enclosing the search string in quotes if you're using Solr Admin UI would be sufficient.