我有一个Lucene索引设置,我可以查询。我只是无法得到一个"字段不等于空字符串"工作的条件。例如,在下面的代码示例中,我想要有3个条件
" date"范围介于" 20110101T000000"和" 20121001T000000"。
WildcardQuery taggingQuery = new WildcardQuery(new Term("country tag", "*" + ShortID.Encode("{4ED2F7EE-5C2A-418C-B2F6-236F94166BA1}").ToLowerInvariant() + "*"));
TermQuery taggingNotQuery = new Term("country tag", " "));
RangeQuery rangeQuery = new RangeQuery(new Term("date", "20110101T000000"), new Term("date", "20121001T000000"), true);
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.Add(taggingQuery, BooleanClause.Occur.MUST);
booleanQuery.Add(taggingNotQuery, BooleanClause.Occur.MUST_NOT);
booleanQuery.Add(rangeQuery, BooleanClause.Occur.MUST);
我有一种感觉我做错了或者我的查询错了。我不应该需要一个条件,我应该注意空或空字段。
感谢任何帮助!
答案 0 :(得分:0)
如果您允许'*'作为搜索字符串中的第一个字符,Lucene可以使用“countrytag:*”之类的查询来查找 countrytag 字段中包含任何内容的所有文档。 (Lucene的默认设置是在查询字符串中禁用初始'*'。)
答案 1 :(得分:0)
设置索引时我应该多加注意。我忘了为每个领域添加现场分析仪。多列表字段使用不同的分析器而不是标准分析器进行索引。我将此添加到我的配置部分以进行字段抓取并且我的查询已开始工作
<fieldTypes hint="raw:AddFieldTypes">
<!-- Text fields need to be tokenized -->
<fieldType name="single-line text" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="multi-line text" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="word document" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="html" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="rich text" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="memo" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="text" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<!-- Multilist based fields need to be tokenized to support search of multiple values -->
<fieldType name="multilist" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="treelist" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="treelistex" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<fieldType name="checklist" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
<!-- Legacy tree list field from ver. 5.3 -->
<fieldType name="tree list" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
</fieldTypes>