我是SOLR的新手,目前我的查询返回公司及其各自的postCodes,postCode是一个数组类型字段,一些结果包含其postCode节点的多个值,而一些只有一个值。
结果集:
<doc>
<str name="company">Alien Technology</str>
<arr name="postCode">
<str>2068</str>
<str>2065</str>
<str>2066</str>
<str>2061</str>
<str>2077</str>
</arr>
....
</doc>
<doc>
<str name="company">Cris' Sports</str>
<arr name="postCode">
<str>2068</str>
</arr>
...
</doc>
<doc>
<str name="company">Hyper Consultation Firm</str>
<arr name="postCode">
<str>2068</str>
<str>2000</str>
<str>2071</str>
</arr>
...
</doc>
<doc>
<str name="company">DJ Goods & Gadgets</str>
<arr name="postCode">
<str>2068</str>
</arr>
...
</doc>
...
我的问题是,是否可以仅获取只有一个值为其postCode的数据,反之亦然,获取那些包含其postCode字段的多个值的数据,并排除其postCode只有一个值的其他数据。这可能是使用SOLR查询吗?
实施例
我搜索了postCode = 2068
我的第一个查询只返回Cris Sports和DJ Goods and Gadgets,因为它们只有一个postCode字段的值。
我的第二个查询只返回Alien Technology和Hyper Consultation Firm,因为它们都包含其postCode字段的多个值。
谢谢大家!
答案 0 :(得分:1)
没有直接的方法来获取多值字段中的项目数或计算相同的函数查询。
您始终可以在索引编制期间维护字段计数,并在查询时使用它。
答案 1 :(得分:0)
按分数(desc)排序时,只有一个值的字段将具有更高的分数,因此将在其他值之前列出。 不确定是否有办法将结果集限制为只有分数匹配max-score的文档。 也许可以在客户端完成?