Lucene 如何在数据库中建立索引 (Cassandra)
Lucene how to index in Database (Cassandra)
我只是在试验 Lucene,并希望将数据库 (Cassandra) 中的对象索引为 table。但是,我没有意识到索引在 Cassandra 上是如何工作的。特别是搜索...
当我举一个简单的例子时
Lucene 中的索引:
Document doc = new Document();
doc.add(new TextField("id", "Hotel-1345", Field.Store.YES));
doc.add(new TextField("description", "A beautiful hotel", Field.Store.YES));
writer.addDocument(doc);
然后 Lucene 将创建索引文件 (C:..) 并且使用 indexSearcher 查询效果很好。但是...
索引数据库?
我想我不能像那样创建一个简单的 table
Table1:
ID , Description
------------------
Hotel-1345, A beautiful hotel
lucene 的搜索过程是如何工作的?数据库结构应该如何?
希望我能得到一些答案:/
它看起来不像关系数据库table,而是Lucene使用倒排索引和余弦相似度公式来搜索任何搜索词。
为了更好地理解您需要查找在 lucene 中使用的各种术语和公式,
可以上lucene官网查看,
https://lucene.apache.org/core/3_5_0/scoring.html#Query%20Classes
要索引数据,您需要使用 Lucene 索引器和搜索器 API
使用此伪代码进行索引:
Directory directory = null;
IndexWriter writer = null;
try {
directory = FSDirectory.open(new File(args[0]));
IndexWriterConfig iwConf = new IndexWriterConfig(Version.LUCENE_48,
new KeywordAnalyzer());
iwConf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(directory, iwConf);
Document document = new Document();
document.add(new StringField("title", "Cat", Store.YES));
writer.addDocument(document);
writer.commit();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
我只是在试验 Lucene,并希望将数据库 (Cassandra) 中的对象索引为 table。但是,我没有意识到索引在 Cassandra 上是如何工作的。特别是搜索...
当我举一个简单的例子时
Lucene 中的索引:
Document doc = new Document();
doc.add(new TextField("id", "Hotel-1345", Field.Store.YES));
doc.add(new TextField("description", "A beautiful hotel", Field.Store.YES));
writer.addDocument(doc);
然后 Lucene 将创建索引文件 (C:..) 并且使用 indexSearcher 查询效果很好。但是...
索引数据库? 我想我不能像那样创建一个简单的 table
Table1:
ID , Description
------------------
Hotel-1345, A beautiful hotel
lucene 的搜索过程是如何工作的?数据库结构应该如何?
希望我能得到一些答案:/
它看起来不像关系数据库table,而是Lucene使用倒排索引和余弦相似度公式来搜索任何搜索词。
为了更好地理解您需要查找在 lucene 中使用的各种术语和公式, 可以上lucene官网查看, https://lucene.apache.org/core/3_5_0/scoring.html#Query%20Classes
要索引数据,您需要使用 Lucene 索引器和搜索器 API 使用此伪代码进行索引:
Directory directory = null;
IndexWriter writer = null;
try {
directory = FSDirectory.open(new File(args[0]));
IndexWriterConfig iwConf = new IndexWriterConfig(Version.LUCENE_48,
new KeywordAnalyzer());
iwConf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(directory, iwConf);
Document document = new Document();
document.add(new StringField("title", "Cat", Store.YES));
writer.addDocument(document);
writer.commit();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}