如何为Mysql数据库创建Lucene索引?

时间:2016-03-14 08:23:48

标签: mysql database indexing lucene full-text-search

我在MySQL中有这个表项,

ItemId | ItemName| Category | Description | price | bidderCount

如何为此表创建Lucene索引,以便我可以搜索是否存在我想知道的ItemName或Description中的术语?

public class Indexer {
    public Indexer() {}
    public static IndexWriter indexWriter;
    public static void main(String args[]) {
    String usage = "java Indexer";
    rebuildIndexes("indexes");
    }
    public static void insertDoc(IndexWriter i, String doc_id, String line){
    Document doc = new Document();
    doc.add(new TextField("doc_id", doc_id, Field.Store.YES));
    doc.add(new TextField("line", line,Field.Store.YES));
    try { i.addDocument(doc); } catch (Exception e) {  e.printStackTrace(); }
}
    public static void rebuildIndexes(String indexPath) {
    try {
        Path path = Paths.get(indexPath);
        System.out.println("Indexing to directory '" + indexPath + "'...\n");
        Directory directory = FSDirectory.open(path);
        IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
        //IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
        //IndexWriterConfig config = new IndexWriterConfig(new EnglishAnalyzer());
        IndexWriter i = new IndexWriter(directory, config);

我可以为我插入的文本构建索引,但不知道如何将数据库作为平面文档,因此我可以为它构建lucene索引。提前谢谢。

0 个答案:

没有答案