query for document that two fields are equal?

前端 未结 3 1364
有刺的猬
有刺的猬 2021-01-13 16:07

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



        
3条回答
  •  一生所求
    2021-01-13 16:29

    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.

提交回复
热议问题