惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
S
Schneier on Security
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
GbyAI
GbyAI
L
LINUX DO - 热门话题
大猫的无限游戏
大猫的无限游戏
Hacker News: Ask HN
Hacker News: Ask HN
A
Arctic Wolf
罗磊的独立博客
S
Securelist
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
C
Cisco Blogs
G
GRAHAM CLULEY
P
Proofpoint News Feed
美团技术团队
MongoDB | Blog
MongoDB | Blog
Cyberwarzone
Cyberwarzone
T
Tor Project blog
P
Proofpoint News Feed
NISL@THU
NISL@THU
J
Java Code Geeks
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
D
Docker
博客园 - 聂微东
I
InfoQ
AI
AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News | PayPal Newsroom
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
T
Tenable Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
K
Kaspersky official blog

博客园 - 追梦华仔

Openfire服务器MySQL优化 放开Linux内核对用户进程可打开文件数和TCP连接的限制 SSL 握手协议 非对称密码学(Asymmetric Cryptography)- 转载 Visual Studio 2008下载 Visual Studio 2008 提示“无法识别工具版本4.0” 改造MUC实现Openfire群 Openfire S2S 经验分享 注册Jmail组件的三种方法 读取excel文件的时候 出错提示:外部表不是预期的格式 - 追梦华仔 - 博客园 System.Runtime.InteropServices.COMException: 服务器出现意外情况 Excel表格导入出错,提示“拒绝访问”的错误,ExcelObj = new Excel.Application(); 在 ASP.NET 中执行 URL 重写 XP下如何解决“ASP.NET 未被授权访问所请求的资源”的问题 - 追梦华仔 - 博客园 无法在web服务器上启动调试 您不具备调试此应用程序的权限 - 追梦华仔 - 博客园 Server Application Error ---Http 500错误解决方法 [转载]Ruby on Rails:开源技术将深入企业 Lucene.Net中按时间范围查询,结果没有查到数据 Lucene.Net.Search.Highlight.FragmentQueue 中的派生方法 LessThan 不能减少访问
用Lucene实现在检索结果中再检索
追梦华仔 · 2007-07-06 · via 博客园 - 追梦华仔

http://www.matrix.org.cn/thread.shtml?topicId=753ba0a5-125e-11dc-b33a-df989147150e&forumId=32

Lucene是可以做到的,利用lucene的Filter,具体可以查看lucene的api中的org.apache.lucene.search.CachingWrapperFilter,它可以缓存上次的搜索结果,从而实现在结果中的搜索。

测试实例:
package com.wsjava;
import java.io.IOException;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.CachingWrapperFilter;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryFilter;

public class IndexTest {

        /**
         * @param args
         * @throws ParseException
         * @throws IOException
         */
        public static void main(String[] args) throws IOException, ParseException {
                index();
                search("day"); //简单搜索
                searchInResult("day", "you"); //在结果集中搜索
        }
        
        public static void index() throws IOException {
                IndexWriter writer = new IndexWriter("d:/tesindex",new SimpleAnalyzer(), true);
                writer.setMaxMergeDocs(1000);
                writer.setMergeFactor(100);
                for (int i = 0; i < 10; i++) {
                        Document doc = new Document();
                        String content = "How do you do?";
                        if (i >= 5) {
                                content = "What's a good day. ";
                        }
                        if (i >= 7) {
                                content = "Nice day. Thanks you!";
                        }
                        doc.add(new Field("content", content, Field.Store.YES,Field.Index.TOKENIZED));
                        writer.addDocument(doc);
                }

        }
        
        //简单实现对qw的搜索.
        public static void search(String qw) throws IOException, ParseException {
                QueryParser queryParser = new QueryParser("content",new SimpleAnalyzer());
                Query query = queryParser.parse(qw.trim());
                QueryFilter filter = new QueryFilter(query);
                
                search(query, filter);
        }
        
        //在搜索oldqw的结果集中搜索qw.
        public static void searchInResult(String qw, String oldqw) throws ParseException, IOException {                
                QueryParser queryParser = new QueryParser("content",new SimpleAnalyzer());
                Query query = queryParser.parse(qw.trim());
                Query oldQuery = queryParser.parse(oldqw.trim());
                QueryFilter oldFilter = new QueryFilter(oldQuery);
                CachingWrapperFilter filter = new CachingWrapperFilter(oldFilter);
                
                search(query, filter);
        }
        
        private static void search(Query query, Filter filter) throws IOException, ParseException {
                IndexSearcher ins = new IndexSearcher("d:/tesindex");
                Hits hits = ins.search(query, filter);
                for (int i = 0; i < hits.length(); i++) {
                        Document doc = hits.doc(i);
                        System.out.println(doc.get("content"));
                }
                System.out.println();
        }
}

上面是简单的测试程序。当然在实际应用中可以做得比较复杂。