简体   繁体   English

Lucene空查询字符串与过滤器

[英]Lucene empty query string with filter

I am using Lucene.Net in a personal project and need to handle to cases but can't find a nice way that lucene will handle the two cases using the same type of query. 我在个人项目中使用Lucene.Net,需要处理案例,但是找不到一个好的方法,Lucene将使用相同类型的查询来处理两个案例。

The basic query uses a MultiFieldQueryParser with the StandardAnalyzer and a NumericRangedFilter to filter by date (dates are saved as long values). 基本查询使用带有StandardAnalyzer和NumericRangedFilter的MultiFieldQueryParser来按日期过滤(日期保存为长值)。

The problem being that I would like the filter to handle an empty search string, without having to use two different query parsers, one for an empty search string and one where the user enters a search string. 问题是我希望过滤器处理一个空的搜索字符串,而不必使用两个不同的查询解析器,一个用于一个空的搜索字符串,另一个用于用户输入搜索字符串。 Currently the MultiFieldQueryParser throws a ParseException when an empty string is used. 当前,当使用空字符串时,MultiFieldQueryParser引发ParseException。

Any advice on the best way to handle this? 关于解决此问题的最佳方法有什么建议吗? Or is this a flaw (intentional or otherwise) in Lucene or Lucene.Net. 还是Lucene或Lucene.Net中的缺陷(有意或无意)。

RESULT 结果

I ended up using the MatchAllDocsQuery if the query string was empty with a normal query otherwise. 如果查询字符串为空,而正常查询则为空,我最终使用MatchAllDocsQuery。

Also I had to remove the use of NumericFields and the NumericRangeFilter as the query returned no results when I used them. 另外我还必须删除对NumericFields和NumericRangeFilter的使用,因为当我使用它们时查询没有返回结果。 I ended up doing the date range filter the old way with strings and a normal RangeFilter. 我最终使用字符串和普通的RangeFilter用旧的方式进行了日期范围过滤。

The best way to handle it is to generate a MatchAllDocsQuery and bypass the parser if the input is an empty string. 最好的处理方法是生成MatchAllDocsQuery并在输入为空字符串时绕过解析器。

http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/search/MatchAllDocsQuery.html http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/search/MatchAllDocsQuery.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM