问题描述
我是Lucene的初学者。曾经在C#中实现它,但是在Java上实现时遇到了问题。现在用Java做一个简单的POC,但是没有得到正确的输出。我正在使用Lucene 8.6。将包括代码以及当前输出和所需的输出。谢谢
```
public class App
{
public static void main( String[] args ) throws IOException,ParseException
{
//System.out.println( "Hello World!" );
Path index_path = Paths.get("D:\\Index");
Directory dir = FSDirectory.open(index_path);
Analyzer an = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(an);
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
IndexWriter writer = new IndexWriter(dir,config);
Document doc = new Document();
FieldType fType = new FieldType();
fType.setStored(true);
fType.setTokenized(true);
// fType.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
Field fld = new Field("content","Hello what is up".getBytes(),fType);
doc.add(fld);
writer.addDocument(doc);
writer.close();
IndexReader ireader = DirectoryReader.open(dir);
IndexSearcher searcher = new IndexSearcher(ireader);
// Term t = new Term("content","what");
// Query query = new TermQuery(t);
QueryParser queryParser = new QueryParser("content",an);
Query query = queryParser.parse("what");
TopDocs hits = searcher.search(query,1);
System.out.println(hits.totalHits);
}
}
```
现在输出为“ 0”,但由于存在硬编码文档,因此应为“ 1”。假定所有必需的类均已导入。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)