我认为应该是一个非常简单的CLucene实验,但它没有任何成功。
我有两个单独的程序,CreateIndex和Query。
据我所知,CreateIndex构建了可行的索引文件,但是Query返回零命中。操作系统是Centos 6.4,CLucene版本是2.3.3.4。
这是CreateIndex.cpp:
lucene::analysis::SimpleAnalyzer* analyzer;
int main(int argc, char** argv)
{
analyzer = new lucene::analysis::SimpleAnalyzer();
Directory* indexDir = FSDirectory::getDirectory("../Index");
IndexWriter* w = new IndexWriter(indexDir, analyzer, true, true);
int config = Field::STORE_YES && Field::INDEX_TOKENIZED;
Field* field;
Document* doc;
doc = new Document();
field = new Field(L"president", L"Nixon", config);
doc->clear();
doc->add(*field);
w->addDocument(doc);
field = new Field(L"president", L"Obama", config);
doc->clear();
doc->add(*field);
w->addDocument(doc);
field = new Field(L"president", L"Clinton", config);
doc->clear();
doc->add(*field);
w->addDocument(doc);
w->close();
indexDir->close();
}
Run Code Online (Sandbox Code Playgroud)
这是Query.cpp:
int main(int argc, char** argv)
{ …Run Code Online (Sandbox Code Playgroud) clucene ×1