在不指定字段名称的情况下查询Solr

时间:2010-01-27 01:58:23

标签: lucene solr localsolr

我是使用Solr的新手,我必须遗漏一些东西。

我还没有在示例模式中触及太多,我导入了一些示例数据。我也设置了LocalSolr,这似乎运作良好。

我的问题只是一般查询Solr。我有一个文档,其中名称字段设置为 tom。我一直在查看配置文件,我无法弄清楚我哪里出错了。索引和存储了一堆字段,我可以看到管理员中的值,但我无法查询正常工作。我尝试了各种查询(http://server.com/solr/select/?q=value),结果如下:

**Query:** ?q=tom
**Result:** No results

**Query:** q=\*:\*
**Result:** 10 docs returned

**Query:** ?q=*:tom
**Result:** No results

**Query:** ?q=name:tom
**Result:** 1 result (the doc with name : tom)

我想让第一个案例(?q=tom)正常工作。任何可能出错的输入以及我如何纠正它都将不胜感激。

6 个答案:

答案 0 :(得分:14)

在schema.xml中将<defaultSearchField>设置为name

  

使用<defaultSearchField>   Solr在解析查询时进行识别   应搜索哪个字段名称   查询显式字段名称   尚未使用过。

您可能还想查看(e)dismax

答案 1 :(得分:6)

我刚遇到类似的问题......即我已经定义了多个字段(schema.xml中不存在)来描述我的文档,并且想要搜索/查询文档的多个字段,不仅仅是其中之一(如上述例子中的“名称”)。

为了实现这一点,我创建了一个新字段(“compoundfield”),然后我将/ copyField放入我定义的字段(就像Solr发行版附带的schema.xml文档中的“text”字段) 。这导致如下:

coumpoundfield定义:

<field name="compoundfield" type="text_general" indexed="true" stored="false" multiValued="true"/>

defaultSearchField:

<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultSearchField>compoundfield</defaultSearchField>

<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>

<!-- copyField commands copy one field to another at the time a document
    is added to the index.  It's used either to index the same field differently,
    or to add multiple fields to the same field for easier/faster searching.  -->
<!-- ADDED Fields -->
<copyField source="field1" dest="compoundfield"/>
<copyField source="field2" dest="compoundfield"/>
<copyField source="field3" dest="compoundfield"/>

这对我来说很好,但我不确定这是否是进行这种“多场”搜索的最佳方式......

干杯!

答案 2 :(得分:1)

似乎DisMax parser 为此目的使用是正确的。

Related stackoverflow thread here.

答案 3 :(得分:1)

当前的解决方案在较新版本的lucene / solr中已弃用。要更改默认搜索字段,请使用df参数或更改位于以下位置的字段:

  <initParams 
path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
    <lst name="defaults">
      <str name="df">default_field</str>
    </lst>
  </initParams>

solrconfig.xml

注意我在编写本文时使用的是非托管模式和solr 7.0.0

答案 4 :(得分:0)

通过solr教程绝对值得你花时间: http://lucene.apache.org/solr/tutorial.html

我的猜测是“名称”字段未编入索引,因此您无法搜索它。您需要更改架构以使其编入索引。

还要确保您的XML实际上与架构对齐。因此,如果要在xml中添加名为“name”的字段,但架构不知道它,那么Solr将忽略该字段(即它不会被“存储”或“索引”)。

祝你好运

答案 5 :(得分:0)

好吧,尽管设置了默认搜索字段非常有用但我不明白你为什么不使用solr查询语法:

......./?q=name:tom

....... / Q = &安培; FQ =名:汤姆