关于Lucene 中Field 的疑惑,懂Lucene者请进

any0007 2009-03-19 09:03:10
刚开始学习Lucene

按照Lucene in Action 中的例子在eclipse 中运行,结果发现一点问题,由于对Lucene API还不太了解

请高手帮忙解释一下;


问题是这样的

doc.add(Field.Text("content",new FileReader(f)));
doc.add(Field.Keyword("filename",f.getCanonicalPath()));


eclipse 提示 Field没有域或方法 Text 和 Keyword

自己在API中也没有找到 Text 和 Keyword,这到底是什么原因呢?
...全文
294 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
muzuan.cn 2009-04-09
  • 打赏
  • 举报
回复
一起研究吧
养成回帖的习惯。
虽然没回答问题,也标示尊重别人。
any0007 2009-03-21
  • 打赏
  • 举报
回复
问一个关于Lucene的问题,2.0的时候添加了一个类indexModifier看过API后发现全都是Deprecated的了,这中间是有什麽问题吗,谢了
zlz3907 2009-03-19
  • 打赏
  • 举报
回复
Lucene in Action 那里面的列子是好久以前的了哟!lucene都更新好多版了!
建议上apache官网里的lucene里去看下里的例子,那是最新的!

官网:http://lucene.apache.org/

现在都2.4了,下面是段官网上的示例代码供参考(我没试的,呵呵,因为我以前用的还是2.1):

原文地址:http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc//demo/index.html



Analyzer analyzer = new StandardAnalyzer();

// Store the index in memory:
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.getDirectory("/tmp/testindex");
IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
new IndexWriter.MaxFieldLength(25000));
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, Field.Store.YES,
Field.Index.ANALYZED));
iwriter.addDocument(doc);
iwriter.close();

// Now search the index:
IndexSearcher isearcher = new IndexSearcher(directory);
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.parse("text");
ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
assertEquals(1, hits.length);
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
}
isearcher.close();
directory.close();

possibleonline 2009-03-19
  • 打赏
  • 举报
回复
应该是版本问题

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧