`
deepfuture
  • 浏览: 4397152 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80019
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:69953
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103276
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:285495
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14999
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:67479
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32088
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45961
社区版块
存档分类
最新评论

lucene-链式过滤器ChainedFliter

阅读更多

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);

分享到:
评论

相关推荐

    lucene-analyzers-smartcn-7.7.0-API文档-中文版.zip

    赠送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-...

    lucene-core-7.7.0-API文档-中文版.zip

    赠送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...

    lucene-analyzers-common-6.6.0-API文档-中文版.zip

    赠送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-...

    lucene-4.7.0全套jar包

    - **Analyzer模块**:提供了各种分词器和过滤器,如`lucene-analyzers-common-4.7.0.jar`。 - **QueryParser模块**:实现了查询解析功能,如`lucene-queryparser-4.7.0.jar`。 - **Memory模块**:提供了内存中的...

    lucene-suggest-6.6.0-API文档-中文版.zip

    赠送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...

    lucene-core-7.2.1-API文档-中文版.zip

    赠送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...

    lucene-backward-codecs-7.3.1-API文档-中英对照版.zip

    赠送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-...

    lucene-core-6.6.0-API文档-中文版.zip

    赠送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...

    lucene-memory-6.6.0-API文档-中文版.zip

    赠送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文档...

    lucene-suggest-7.7.0-API文档-中文版.zip

    赠送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...

    lucene-spatial-extras-7.3.1-API文档-中英对照版.zip

    赠送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...

    lucene-analyzers-smartcn-7.7.0-API文档-中英对照版.zip

    赠送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-...

    lucene-sandbox-7.2.1-API文档-中文版.zip

    赠送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...

    lucene-spatial-6.6.0-API文档-中文版.zip

    赠送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...

    lucene-misc-6.6.0-API文档-中文版.zip

    赠送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...

    lucene-spatial-extras-7.2.1-API文档-中英对照版.zip

    赠送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...

    lucene-spatial-extras-6.6.0-API文档-中英对照版.zip

    赠送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...

    lucene-highlighter-6.6.0-API文档-中文版.zip

    赠送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;...

    lucene-backward-codecs-6.6.0-API文档-中文版.zip

    赠送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-...

    lucene-backward-codecs-6.6.0-API文档-中英对照版.zip

    赠送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-...

Global site tag (gtag.js) - Google Analytics