zoukankan      html  css  js  c++  java
  • lucene3.0_IndexSearcher过滤

    系列汇总:

    lucene3.0_基础使用及注意事项汇总

    lucene中的过滤行为

    将带有过滤行为的检索分成三个过程:

    过程1:根据用户指定的检索式获得初步目标结果

    过程2:根据指定的条件(可以是检索式)获得过滤器,简单理解过滤器——即哪些文档必须从初步目标结果中kill掉。

    过程3:将初步目标结果“通过”过滤器的“校验”,获得最终的目标结果。

    上面三个步骤是一种最基础的过滤行为,用实例简单演示一下:

    正常检索结果(不适用过滤器,将所有文档打印出来):

    Document<stored,indexed<f:0> stored,indexed<f1:20050719> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:10> stored,indexed<f1:20100215> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:10> stored,indexed<f1:20090512> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:5> stored,indexed<f1:20101019> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:-2> stored,indexed<f1:20000128> stored,indexed<a:fox>>

    定义过滤器,过滤掉字段 f1不在(20050101 TO 20101010)范围之内的数据。

    Query query1 = parser.parse("f1:[20050101 TO 20101010]");
    QueryWrapperFilter filter
    =new QueryWrapperFilter(query1);
    TopFieldDocs docs
    = searcher.search(query, filter, 10, sort);

    过滤后的结果为:

    Document<stored,indexed<f:0> stored,indexed<f1:20050719> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:10> stored,indexed<f1:20090512> stored,indexed<a:fox>>
    Document
    <stored,indexed<f:10> stored,indexed<f1:20100215> stored,indexed<a:fox>>

    也许有人会说——“这样做是何苦呢?直接和并到一个query中不得了?何况还是用QueryParser!”

    这样得到的效果也是一样的啊~!?

    Query query = parser.parse("a:fox AND f1:[20050101 TO 20101010]");

    的确,在这个实例中用过滤器有点过了,但是本着举一反三、触类旁通、灵活多变的思维方式(= =!无聊~)

    那么想想:

    要过滤掉某个字段中的负数呢?

    用全文数据库实现阅读权限呢?

    ......

    这个时候过滤器就v5了!

    -----------------------------------------------------

    未完待续!

    1.自定义过滤器;

    2.过滤器分析

  • 相关阅读:
    etymology-R
    arp与免费arp的差别,arp老化
    基于S3C2440的linux-3.6.6移植——LED驱动【转】
    《unix环境高级编程》学习笔记【原创】
    安装截图工具 Shutter【转】
    《UNIX环境高级编程第三版》apue.h等源码文件的编译安装【转】
    Ubuntu 下安装Source Insight [转]
    "makefile:5: *** missing separator. Stop."【转】
    深入浅出剖析C语言函数指针与回调函数(一)【转】
    总结与反思、理想与规划---嵌入式学习之旅【原创】
  • 原文地址:https://www.cnblogs.com/huangfox/p/1854634.html
Copyright © 2011-2022 走看看