18. Code: Searcher Otis Gospodnetic, Sematext Int’l public void search(String indexDir, String q) throws IOException, ParseException { Directory dir = FSDirectory.open (new File(indexDir)); IndexSearcher is = new IndexSearcher(dir, true); QueryParser parser = new QueryParser("contents", new StandardAnalyzer(Version.LUCENE_CURRENT)); Query query = parser.parse(q); TopDocs hits = is.search(query, 10); System.err.println("Found " + hits.totalHits + " document(s)"); for (int i=0; i<hits.scoreDocs.length; i++) { ScoreDoc scoreDoc = hits.scoreDocs[i]; Document doc = is.doc(scoreDoc.doc); System.out.println( doc.get("filename") ); } is.close(); }
19.
20. Code: Doc Updates Otis Gospodnetic, Sematext Int’l void updateDocument(Term term, Document doc, Analyzer analyzer) Updates a document by first deleting the document(s) containing term and then adding the new document. void Via IndexWriter facade void updateDocument(Term term, Document doc) Updates a document by first deleting the document(s) containing term and then adding the new document. void
21.
22.
23.
24. Community [email_address] [email_address] Otis Gospodnetic, Sematext Int’l "I posted, went to get a sandwich, and came back to see two answers. The change works, and I can get the fix into production today. This list is magic."