只有当我在查询中包含字段时,我才能让 Solr 工作,例如:
http://localhost:8983/solr/collection1/select?q=lastname:johnson
上述查询返回大约 18 个结果。
难道不应该可以在不指定字段的情况下使用 Solr (/Lucene) 吗?如:
http://localhost:8983/solr/collection1/select?q=johnson
我还尝试添加字段列表:
http://localhost:8983/solr/collection1/select?q=johnson&fl=cus_id%2Cinitials%2Clastname%2Cpostcode%2Ccity
但是所有这些查询都返回零结果。
这些是我的 schema.xml 中的字段:
<field name="cus_id" type="string" indexed="true" stored="true"/>
<field name="initials" type="text_general" indexed="true" stored="true" />
<field name="lastname" type="text_general" indexed="true" stored="true"/>
<field name="postcode" type="string" indexed="true" stored="true" />
<field name="city" type="text_general" indexed="true" stored="true"/>
我不知道还能尝试什么。有什么建议吗?
最佳答案
对于 Solr,如果未指定字段,则搜索将在默认字段 (df
) 上进行。
因此,当您搜索 q=johnson 并调试查询时,您会发现它在默认字段上搜索,该字段通常是字段 text
。
您可以copyfield将所有字段添加到单个字段文本并将其作为默认字段(如果还不是默认字段),以便您的所有搜索查询都将在默认字段中搜索。
此外,fl
列出了将作为结果的一部分返回的字段,并且与执行搜索的字段无关。
使用 dismax,您可以检查 qf 参数来指定具有可变提升的多个字段。
关于solr - 所有字段的默认搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18268189/