何时在 solr 中使用局部参数

When to use Local Params in solr

我正在努力思考 solr 中的局部参数。您什么时候会真正使用它们来做 q.op 之类的事情? ?q={!q.op=OR}solr rocks?q=solr rocks&q.op=OR 有什么不同,什么时候有用。我能想到的主要事情是,如果您只能通过您正在使用的 api 或 lib 访问 q= 参数。它主要是为了嵌套更复杂的搜索,如果是这样,文档中是否有示例?

似乎有些参数本质上是不同的,比如 {!boost...bq/bf,但我仍然不明白为什么你不能't/shouldn 如果局部参数相当可互换,则无法执行 ?q=solr rocks&boost=[some boost thing] 之类的操作。

我在这个过程中有什么误解吗?

Local parameters are arguments in a Solr request that are specific to a query parameter.

Local parameters provide a way to add meta-data to certain argument types such as query strings. (In Solr documentation, local parameters are sometimes referred to as LocalParams.)

重要的部分是“某些参数类型”。这意味着它不仅对 q 参数有效。

您在上面给出的示例也可以与 fq 参数一起使用,例如使用 dismax 搜索查询作为 fq:

fq={!dismax qf=myfield}solr rocks

另一个非常有用的事情是能够在创建方面时标记和排除 fq 参数 - 即 allow you to filter the result set 无需过滤用于方面的文档:

q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=true&facet.field={!ex=dt}doctype

此处 {!tag}{!ex} 参数针对 特定参数 而不是针对整个查询(查询参数会执行)更改某些内容。

在使用参数解引用支持将参数解耦时也很有用,这意味着您可以通过在 solrconfig 中对查询参数使用 invariant 来锁定参数本身(及其参数),然后使用将实际用户提供的字符串发送到查询的新查询参数:

q={!type=dismax qf=myfield v=$qq}&qq=solr rocks

在这种情况下,您可以将 q 参数锁定为上面给出的任何参数,然后仅通过 qq.

提供查询字符串

还有许多其他使用 localparams 来更改一个特定查询参数的行为方式的示例,但希望这能让您了解为什么以及如何使用它们。

过去Local Parameters and dereferencing were used by some applications to keep the query simpler and define certain values in the solrconfig.xml. This allows you to update the behavior of an application by just updating the values on the server (for example to configure the boost values of the fields used in searches) without having to update the client application(s). Applications using Blacklight就是这样的例子。

这在技术上仍然可行,但出于安全原因,在最新版本的 Solr 中 restricted 使用局部参数。

Starting a query string with local parameters {!myparser …​} is used to switch from one query parser to another, and is intended for use by Solr system developers, not end users doing searches. To reduce negative side-effects of unintended hack-ability, Solr now limits the cases when local parameters will be parsed to only contexts in which the default parser is "lucene" or "func".