File file=new File(argv[]);
IndexWriter writer = new IndexWriter("index", new StandardAnalyzer(), true);
Document doc = new Document();
doc.add(Field.Text("path", file.getPath()));
doc.add(Field.Keyword("modified",DateField.timeToString(file.lastModified())));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text("contents", reader));
writer.addDocument(doc);
writer.optimize();
writer.close();
/*关于检索的主要函数*/
Searcher searcher = new IndexSearcher("index");
Analyzer analyzer = new StandardAnalyzer();
Query query = QueryParser.parse(lineforsearch, "contents", analyzer);
Hits hits = searcher.search(query);
for (int i = start; i < hits.length(); i++) {
Document doc = hits.doc(i);
String path = doc.get("path");
System.out.println(i + ". " + path);
}