查询两个字段相等的文档? [英] query for document that two fields are equal?

查看:78
本文介绍了查询两个字段相等的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

solr中有两个文本字段,它们都被空格标记并具有小写过滤器.下面是模式:

<fieldType name="text_ac" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

<field name="field1" type="text_ac" indexed="true" stored="true" required="false" omitNorms="true" default=""/>

<field name="field2" type="text_ac" indexed="true" stored="true" required="false" omitNorms="true" default=""/>

如何查询solr以返回查询时field1的整个字符串与field2相同的结果(field1 == field2)?

谢谢.

解决方案

有关如何正确查询两个字段之间相等性的Solr,请参阅尼古拉斯·迪皮亚扎(Nicholas DiPiazza)的答案

考虑到该问题指定比较两个文本(即经过分析)字段的全部内容,我认为这不适用于函数查询之类的方法,因此有两种方法:

  • 重新考虑您要做什么,或更改索引结构.这些应该是字符串而不是文本吗?如果是这样,请按照上面的说明尼古拉斯·迪皮亚扎(Nicholas DiPiazza)的答案.

  • (这里是原始答案)一种简单的实现方法是在索引时执行比较,并将结果存储在索引中.也就是说,如果您具有field1field2,则创建一个字段1_equals_2,并使用true对其进行索引(如果基于添加文档时的比较它们相等).然后,您只需搜索1_equals_2:true.

There are two text fields in solr, both of them are white space tokenized and have lower case filter. below is the schema:

<fieldType name="text_ac" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

<field name="field1" type="text_ac" indexed="true" stored="true" required="false" omitNorms="true" default=""/>

<field name="field2" type="text_ac" indexed="true" stored="true" required="false" omitNorms="true" default=""/>

How to query solr to return results that the whole string of field1 is same as field2 at query time (field1==field2)?

Thanks.

解决方案

For how to correctly query Solr on equality between two fields, please see Nicholas DiPiazza's answer

Given that the question specifies comparing the full contents of two text (that is analyzed) fields, I believe that won't work well with function queries and the like, so two approaches:

  • Rethink what you are trying to do, or change the index structure. Should those be strings instead of text? If so, do that then refer, as above, to Nicholas DiPiazza's answer.

  • (Original Answer here) A simple way to accomplish this would be to perform the comparison at index time, and store the result in the index. That is, if you have field1 and field2, create a field 1_equals_2, and index it with true, if they are equal based on your comparison when adding the document. Then you can simply search for 1_equals_2:true.

这篇关于查询两个字段相等的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆