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

推荐订阅源

W
WeLiveSecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
V
Visual Studio Blog
L
LangChain Blog
A
About on SuperTechFans
B
Blog
T
Tenable Blog
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
U
Unit 42
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Check Point Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
GbyAI
GbyAI
T
Troy Hunt's Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V2EX - 技术
V2EX - 技术
小众软件
小众软件
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed

博客园 - 追梦华仔

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

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