1、使用ChainedFilter将其它过滤器链接起来,在过滤器中执行AND、OR、XOR和ANDNOT的位操作。
2、ChianedFilter没有缓存,只要把它封装进CachingWrappingFilter就可以提供对过滤器结果的缓存操作。
3、
public class ChainedFilterTest extends TestCase{
public static final intMAX=500;
private RAMDirectorydirectory;
private IndexSearchersearcher;
private Query query;
private DateFilterdateFilter;
private QueryFilterbobFilter;
privateQueryFilter sueFilter;
public void setUp() throwsException{
directory =newRAMDirectory();
IndexWriter writer=new IndexWriter(directory,newWhitespaceAnalyzer(),true);
Calendarcal=Calendar.getInstance();
cal.setTimeInMillies(1041397200000L);
for (int i=0;i<MAX;i++){
Document doc=new Document();
doc.add(Field.Keyword("key",""+(i+1)));
doc.add(Field.Keyword("owner",(i<MAX/2)?"bob":"sue"));
doc.add(Field.Keyword("date",cal.getTime()));
writer.addDocument(doc);
cal.add(Calendar.DATE,1);
}
writer.close();
searcher=new IndexSearcerh(directory);
BooleanQueryquery=newBooleanQuery();
bq.add(new TermQuery(newTerm("owner","bob")),false,false);
bq.add(new TermQuery(new Term("owner","sue")),false,false);
query=bq;
DatapastTheEnd=parseDate("2009 Jan 1");
dateFilter=DateFilter.Before("date",pastTheEnd);
bobFilter=newQueryFilter(new TermQuery(new Term("owner","bob")));
sueFilter=new QueryFilter(new TermQuery(newTerm("owner","sue")));
}
//.........
}
4、测试单个过滤器
ChaindFilter chain=new ChainedFilter(new Filter[]{dateFilter});
Hits hits=searcher.search(query,chain);
chain=new ChainedFilter(new Filter[] {bobFilter});
hits=searcher.search(query,chain);
5、测试OR过滤器
ChainedFilter chain=new chainedFilter(newFilter[]{sueFilter,bobFilter});
Hits hits=searcher.search(query,chain);
6、测试AND过滤器
//2个都要匹配
ChainedFilter chain=new chainedFilter(new Filter[]{dateFilter,bobFilter},Chainedfilter.AND);
Hits hits=searcher.search(query,chain);
7、测试XOR过滤器
//只能匹配其中的一个过滤器,不能2个都匹配
ChainedFilter chain=new chainedFilter(new Filter[]{dateFilter,sueFilter},Chainedfilter.XOR);
Hits hits=searcher.search(query,chain);
8、测试ANDNOT过滤器
ChainedFilter chain=new chainedFilter(new Filter[]{dateFilter,sueFilter},new int[]{Chainedfilter.AND,Chainedfilter.ANDNOT);//结果符合第一个过滤器,而不能匹配第二个过滤器
Hits hits=searcher.search(query,chain);
分享到:
相关推荐
赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
赠送jar包:lucene-core-7.7.0.jar; 赠送原API文档:lucene-core-7.7.0-javadoc.jar; 赠送源代码:lucene-core-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.7.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-analyzers-common-6.6.0.jar; 赠送原API文档:lucene-analyzers-common-6.6.0-javadoc.jar; 赠送源代码:lucene-analyzers-common-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
- **Analyzer模块**:提供了各种分词器和过滤器,如`lucene-analyzers-common-4.7.0.jar`。 - **QueryParser模块**:实现了查询解析功能,如`lucene-queryparser-4.7.0.jar`。 - **Memory模块**:提供了内存中的...
赠送jar包:lucene-suggest-6.6.0.jar; 赠送原API文档:lucene-suggest-6.6.0-javadoc.jar; 赠送源代码:lucene-suggest-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-6.6.0.pom; 包含翻译后的API...
赠送jar包:lucene-core-7.2.1.jar; 赠送原API文档:lucene-core-7.2.1-javadoc.jar; 赠送源代码:lucene-core-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.2.1.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-backward-codecs-7.3.1.jar; 赠送原API文档:lucene-backward-codecs-7.3.1-javadoc.jar; 赠送源代码:lucene-backward-codecs-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-core-6.6.0.jar; 赠送原API文档:lucene-core-6.6.0-javadoc.jar; 赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-memory-6.6.0.jar; 赠送原API文档:lucene-memory-6.6.0-javadoc.jar; 赠送源代码:lucene-memory-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-memory-6.6.0.pom; 包含翻译后的API文档...
赠送jar包:lucene-suggest-7.7.0.jar; 赠送原API文档:lucene-suggest-7.7.0-javadoc.jar; 赠送源代码:lucene-suggest-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-7.7.0.pom; 包含翻译后的API...
赠送jar包:lucene-spatial-extras-7.3.1.jar; 赠送原API文档:lucene-spatial-extras-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...
赠送jar包:lucene-sandbox-7.2.1.jar; 赠送原API文档:lucene-sandbox-7.2.1-javadoc.jar; 赠送源代码:lucene-sandbox-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-sandbox-7.2.1.pom; 包含翻译后的API...
赠送jar包:lucene-spatial-6.6.0.jar; 赠送原API文档:lucene-spatial-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-6.6.0.pom; 包含翻译后的API...
赠送jar包:lucene-misc-6.6.0.jar; 赠送原API文档:lucene-misc-6.6.0-javadoc.jar; 赠送源代码:lucene-misc-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-misc-6.6.0.pom; 包含翻译后的API文档:lucene...
赠送jar包:lucene-spatial-extras-7.2.1.jar; 赠送原API文档:lucene-spatial-extras-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-spatial-extras-6.6.0.jar; 赠送原API文档:lucene-spatial-extras-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-extras-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...
赠送jar包:lucene-highlighter-6.6.0.jar; 赠送原API文档:lucene-highlighter-6.6.0-javadoc.jar; 赠送源代码:lucene-highlighter-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-highlighter-6.6.0.pom;...
赠送jar包:lucene-backward-codecs-6.6.0.jar; 赠送原API文档:lucene-backward-codecs-6.6.0-javadoc.jar; 赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...
赠送jar包:lucene-backward-codecs-6.6.0.jar; 赠送原API文档:lucene-backward-codecs-6.6.0-javadoc.jar; 赠送源代码:lucene-backward-codecs-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...