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

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

问题描述:

我是使用Solr的新手,我必须缺少一些东西。在没有指定字段名称的情况下查询Solr

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

我的问题是一般查询Solr。我有一个文件,其中名称字段设置为汤姆。我一直在看配置文件,我只是无法弄清楚我要去哪里。一堆字段被索引并存储,并且我可以在管理中看到这些值,但我无法查询正常工作。我已经试过各种查询(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)工作。任何可能出错的输入,以及我如何纠正它,将不胜感激。

设置<defaultSearchField>name在schema.xml中

解析查询时<defaultSearchField>所使用的 Solr的识别 哪些字段名称应该在 查询,其中一个显式搜索字段名称 尚未使用。

您可能还想检出(e)dismax

+0

好!这正是我所需要的。我之前没有看到这个选项,现在有一堆指向大型“文本”字段的复制字段是合理的。非常感谢! – 2010-01-27 12:03:19

+0

我已经在我的solconfig.xml文件中更改了它,我正在使用SOLR 7.2.0 – 2018-01-04 10:19:49

通过Solr的教程去,这绝对值得你的时间: http://lucene.apache.org/solr/tutorial.html

我的猜测是,“名称”字段不被索引,所以你不能搜索就可以了。你需要改变你的模式来使它索引。

还要确保您的XML实际上与模式对齐。所以,如果你在xml中添加一个名为“name”的字段,但是schema不知道它,那么Solr会忽略该字段(即它不会被“存储”或“索引”)。

好运

+1

字段绝对索引。另外,如果不是,我不能做一些我列出的查询,对吧?像名字:汤姆不会工作,如果我理解文档。 – 2010-01-27 02:12:05

+0

对Mauricio是否正确,您需要指定solrconfig中的defaultSearchField。此外,如果您正在使用DisMax(这将允许?q = tom同时在多个字段中进行搜索),还有另一个名为“qf”的设置。 – mlathe 2010-01-27 06:28:22

好,尽管设置默认搜索领域是非常有用的,我不明白你为什么不只是使用Solr的查询语法:

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

..... ../?q= & FQ =名称:汤姆

+0

好,错过了阅读标题:-( – Lici 2010-01-27 16:53:50

我只是碰到了类似问题就来了......也就是说我已经定义了多个字段(未在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"/> 

这工作对我很好,但我不知道这是否是最好的方式做出这样“多领域”查寻...

干杯!

这似乎是一个DisMax parser 是正确的使用为此。

Related stackoverflow thread here.

+0

关于第二个想法;使用copyField到统一字段可能是更简单的选项。 – worldsayshi 2012-10-24 10:00:08

目前的解决方案是在lucene的/ solr的较新版本的弃用。要更改默认搜索字段要么使用df参数或更改领域:

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

我使用一个非管理模式和Solr 7.0.0当时solrconfig.xml

注意里面写作