如何在Lucene 7.6中从数据库的列/字段检索中创建Lucene索引?

时间:2019-03-12 19:07:01

标签: apache elasticsearch solr lucene lucene.net

我这样从数据库中获取json数组中的数据:

[
  {
    "_id": "1",
    "column1": "sales value trend of abc store",
    "column2": "Sales value",
    "column3": "of",
    "column4": "Sarees And Suitings"
  },
  {
    "_id": "2",
    "column1": "sales value trend of SS AND CO",
    "column2": "Sales volume",
    "column3": "on",
    "column4": "City Fashion"
  }

我想创建一个Lucene索引,以便可以搜索不在列中的数据。并检索在其中找到数据的列名。

我使用的是这样的代码:

JSONArray querydata= ((JSONArray) Query.executeQuery();

for (int i = 0; i < querydata.length(); i++) {
    JsonObject data = querydata.getJSONObject(i);
    createindex(data);
}

createindex(JsonObject data) {
    document.add(new StringField(LuceneConstants.column_NAME, "column1", Field.Store.YES));
    document.add(new TextField(LuceneConstants.CONTENTS, data.optString("column1"), Field.Store.YES));
    document.add(new StringField(LuceneConstants.Row_Name, data.optString("_id"), Field.Store.YES));

    document.add(new StringField(LuceneConstants.column_NAME, "column2", Field.Store.YES));
    document.add(new TextField(LuceneConstants.CONTENTS, data.optString("column2"), Field.Store.YES));
    document.add(new StringField(LuceneConstants.Row_Name, data.optString("_id"), Field.Store.YES));     
}

writer.addDocument(document);

0 个答案:

没有答案