我这样从数据库中获取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);