Start with the basics
Have the program running, you will learn how lucene indexes, this should help to index and search the documents containing fields
decide about your data, how the fields needs to be stored,. i.e.; DateFields shall be stored as Field.Index.NOT_ANALYZED instead of Field.Index.ANALYZED
now next step shall be
//indexmap ==> HashMap
//keywordfields ==> you master list of keywords/phrases
//selectfields ==> your document field (contained in lucene index)
String[] keywordfields = (String[]) indexmap.get("keywordfields").toString().split(",");
String[] selectFields = (String[]) indexmap.get("indexfields").toString().split(",");
//create a booleanquery
BooleanQuery bq = new BooleanQuery();
//iterate the keywordfields
for (int i = 0; i < keywordfields.length; i++) {
bq.add(new BooleanClause(new TermQuery(new Term(keywordfields[i], (String)params.get(SEARCH_QUERYSTRING))),BooleanClause.Occur.SHOULD));
}
//pass the boolean query object to the indexsearcher
topDocs = indexSearcher.search(rq, 1000);
//get a reference to ScoreDoc
ScoreDoc[] hits = topDocs.scoreDocs;
//Iterate the hits
Map <String, Object> resultMap = new HashMap<String, Object>();
List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
for (ScoreDoc scoreDoc : hits) {
int docid = scoreDoc.doc;
FieldSelector fieldselector = new MapFieldSelector(selectFields);
Document doc = indexSearcher.doc(docid, fieldselector);
Map<String, String> searchMap = new HashMap<String, String>();
// get all fields for documents we got
List<Field> fields = doc.getFields();
for (Field field : fields) {
searchMap.put(field.name(), field.stringValue());
System.out.println("Field Name:" + field.name());
System.out.println("Field value:" + field.stringValue());
}
resultList.add(searchMap);
resultMap.put(TOTAL_RESULTS, hits.length);
resultMap.put(RS, resultList);
}
} catch (Exception e) {
e.printStackTrace();
}
This shall be one of the implementation using Lucene =]