简体   繁体   English

Solr Boost查询语法

[英]Solr boost query syntax

The Solr function query documentation says: Solr函数查询文档说:

exists(query({!v='year:2012'})) will return true for docs with year =2012 exists(query({!v='year:2012'}))对于year = 2012的文档将返回true

I have a document like: 我有一个像这样的文件:

{
  id: 1,
  user_type: ADMIN,
  like_score: 1
}

id , user_type and like_score are all indexed and stored files, with id being int, user_type being string and like_score being int. iduser_typelike_score都是已索引和存储的文件,其中id为int, user_type为字符串, like_score为int。

I issue a query like this: 我发出这样的查询:

q={!boost b=if(true,10,1)}id:1&rows=1&fl=*,score

which works. 哪个有效。 But this query does not work: 但是此查询不起作用:

q={!boost b=if(exists(query({!v='user_type:ADMIN'})),10,1)}id:1&rows=1&fl=*,score

It gives an error like this: 它给出了这样的错误:

"error":{
  "msg":"org.apache.solr.search.SyntaxError: Cannot parse ')),5,10)}id:1': Encountered \" \")\" \") \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <LPARAMS> ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ",
  "code":400
}

How do I fix the query? 如何解决查询?

This syntax works: 此语法有效:

q={!func}if(exists(query({!v='user_type:ADMIN'})),5,10)&rows=1&fl=*,score

but it doesn't do what I want to the score. 但这并没有达到我想要的分数。

Asked solr-user group. 询问solr用户组。 Here is answer from Chris Hostetter: 这是克里斯·赫斯特的答案:

The problem is the way you are trying to nest queries inside of each other w/o any sort of quoting -- the parser has no indication that the "b" param is if(exists(query({!v='user_type:ADMIN'})),10,1) it thinks it's "if(exists(query({!v='user_type:ADMIN'" and the rest is confusing it. 问题是您尝试将查询嵌套在彼此之间而不使用任何形式的引用的方式-解析器没有指示“ b”参数为if(exists(query({!v='user_type:ADMIN'})),10,1)认为它是"if(exists(query({!v='user_type:ADMIN'" ,其余的使它感到困惑。

If you quote the "b" param to the boost parser, then it should work... 如果您在boost解析器中引用“ b”参数,则它应该可以工作...

http://localhost:8983/solr/select?q={!boost b="if(exists(query({!v='foo_s:ADMIN'})),10,1)"}id:1

...or if you could use variable derefrencing, either of these should work... ...或者如果您可以使用变量解引用,则这两种方法都应该起作用...

http://localhost:8983/solr/select?q={!boost b=$b}id:1&b=if(exists(query({!v='foo_s:ADMIN'})),10,1)

http://localhost:8983/solr/select?q={!boost b=if(exists(query($nestedq)),10,1)}id:1&nestedq=foo_s:ADMIN

-Hoss -霍斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM