solr - 所有字段的默认搜索

标签 solr lucene

只有当我在查询中包含字段时,我才能让 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/

相关文章:

java - 从 Solr 中检索对象

java - Solr 与现有 Web 应用程序的集成

java - 在版本 > 4.3 的 lucene 中获取文档分数?

lucene 短语查询不起作用

Lucene索引结构问题

tomcat - 带有 tomcat 的 solr 4.8 - 运行 zkcli.sh 时我得到 "Packet len1213486160 is out of range"

mysql - 提高 Solr 和 MySQL 对的性能(使用 JPA 通过 "WHERE IN"连接)

elasticsearch - 如何将 Lucene 查询字符串转换为 Elasticsearch Match/Match_Prefix 等等效项

php - Zend_Search_Lucene 尝试分配 3503812093817007931 字节

java - 为什么 Solr 不按最大相似度因子进行排名?