请大家帮我看个lucene的问题
一个查询问题郁闷好长时间了
//建立索引
IndexWriter iw = new IndexWriter("index", new StandardAnalyzer(), true);
Document doc = new Document();
doc.add(new Field("title", "Lucene创建索引示例", Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("author", "chenlb", Field.Store.YES, Field.Index.NO));
doc.add(new Field("date", "2008-03-08", Field.Store.YES, Field.Index.NO));
doc.add(new Field("content", "Lucene索引的内容在这里,这些内容不被存储.", Field.Store.YES, Field.Index.TOKENIZED);
iw.addDocument(doc);
//搜索1(可以查到)
IndexSearcher searcher = new IndexSearcher("index");
QueryParser parser = new QueryParser("content", new StandardAnalyzer());
Query q = parser.parse("索引");
Hits hits = searcher.search(q);
//搜索2
IndexSearcher searcher = new IndexSearcher("index");
BooleanQuery query = new BooleanQuery();
//查不到
query.add(new TermQuery(new Term("content","索引")),BooleanClause.Occur.MUST);
//查的到
query.add(new TermQuery(new Term("content","引")),BooleanClause.Occur.MUST);
query.add(new TermQuery(new Term("content","索")),BooleanClause.Occur.MUST);
Hits hits = searcher.search(query);
请问下为什么query.add(new TermQuery(new Term("content","索引")),BooleanClause.Occur.MUST);这样查的时候查不到记录
当把
doc.add(new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED);//分词
改为
doc.add(new Field("content", content, Field.Store.YES, Field.Index.UN_TOKENIZED));//不分词
的时候我怎么都查不到记录我已经晕了请大家帮帮忙
//建立索引
IndexWriter iw = new IndexWriter("index", new StandardAnalyzer(), true);
Document doc = new Document();
doc.add(new Field("title", "Lucene创建索引示例", Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("author", "chenlb", Field.Store.YES, Field.Index.NO));
doc.add(new Field("date", "2008-03-08", Field.Store.YES, Field.Index.NO));
doc.add(new Field("content", "Lucene索引的内容在这里,这些内容不被存储.", Field.Store.YES, Field.Index.TOKENIZED);
iw.addDocument(doc);
//搜索1(可以查到)
IndexSearcher searcher = new IndexSearcher("index");
QueryParser parser = new QueryParser("content", new StandardAnalyzer());
Query q = parser.parse("索引");
Hits hits = searcher.search(q);
//搜索2
IndexSearcher searcher = new IndexSearcher("index");
BooleanQuery query = new BooleanQuery();
//查不到
query.add(new TermQuery(new Term("content","索引")),BooleanClause.Occur.MUST);
//查的到
query.add(new TermQuery(new Term("content","引")),BooleanClause.Occur.MUST);
query.add(new TermQuery(new Term("content","索")),BooleanClause.Occur.MUST);
Hits hits = searcher.search(query);
请问下为什么query.add(new TermQuery(new Term("content","索引")),BooleanClause.Occur.MUST);这样查的时候查不到记录
当把
doc.add(new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED);//分词
改为
doc.add(new Field("content", content, Field.Store.YES, Field.Index.UN_TOKENIZED));//不分词
的时候我怎么都查不到记录我已经晕了请大家帮帮忙
...全文
相关推荐
lucene实现过程中存在的问题
lucene在实际应用过程中存在的问题及解决方式。
Lucene 字符编码问题
NULL 博文链接:https://liuxinglanyue.iteye.com/blog/853285
有关Lucene的问题(8):用Lucene构建实时索引的文档更新问题[整理].pdf
有关Lucene的问题(8):用Lucene构建实时索引的文档更新问题[整理].pdf
基于Lucene的Lucene
一款基于Lucene开发的文件检索系统,支持Word、txt、Html等文本文件的检索,可以进行扩展,使之实现对其他文件的检索。
chinese_lucene.rar_Lucene C#_Lucene for .net_PanGu4Lucene_lucene
c#中文分词类库+可用来做搜索引擎分词+准确率90 +支持Lucene.net.rar


