Zend Lucene和范围搜索具有多个值的字段 [英] Zend Lucene and range search on a field with multiple values

查看:45
本文介绍了Zend Lucene和范围搜索具有多个值的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我的索引包含带有称为年龄"的字段的文档.年龄"字段的示例条目:

Say my index contains documents with a field called "ages". Example entries for "ages" field:

  • 25
  • 24、28
  • 25、31

我将如何查询,以便获取其字段包含20到30岁之间的所有文档?我正在使用Zend Lucene.

How would I query this so that I get all the documents whose fields contain ages between 20 and 30? I'm using Zend Lucene.

推荐答案

lmgtfy:-

$from = new Zend_Search_Lucene_Index_Term(20, 'ages');
$to   = new Zend_Search_Lucene_Index_Term(30, 'ages');
$query = new Zend_Search_Lucene_Search_Query_Range(
             $from, $to, true // inclusive
         );
$hits  = $index->find($query);

文档:- lucene和solr都支持多值.
对于您的情况,您对数据的归一化不是很好.
将年龄字段重新分配为多值,
范围查询要匹配多值中的值之一.
就是这个意思

Both lucene and solr support multivalued.
For your case, you did not normalized the data very well.
Reassign the ages field as multivalued,
the range query is to match one of the value in multivalued.
That's mean

20,29 <-- matched
20,31 <-- matched
30,31 <-- does not matched

如果您需要在20到30之间匹配所有值,

If you need to match ALL value between 20 to 30,

20,21,30 <-- matched
19,21,30 <-- not matched

您可以使用其他字段,
像:-

You can use another field(s),
like :-

age_20_30 : store 1 (when all ages are between 20 to 30), else 0
age_30_40 : store 1 (when all ages are between 30 to 40), else 0
... etc

此后,您可以更改为在 age_20_30:1 上进行搜索.
这就像告诉lucene处理摘要结果一样

After that, you can change to search on age_20_30:1.
This is like telling lucene to work on the summary results

这篇关于Zend Lucene和范围搜索具有多个值的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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