| Код | List<String> sentences = ... Directory d = new RAMDirectory(); StandardAnalyzer analyzer = new StandardAnalyzer(MATCH_VERSION, new HashSet<String>()); IndexWriterConfig conf = new IndexWriterConfig(MATCH_VERSION, analyzer); IndexWriter w = new IndexWriter(d, conf); for (String sentence : sentences) { Document doc = new Document(); doc.add(new Field("sentence", value, Field.Store.YES, Field.Index.ANALYZED)); w.addDocument(doc); } w.optimize(); w.close();
IndexReader ir = IndexReader.open(dir); TermEnum trms = ir.terms(); int count = 0; while (trms.next()){ Term t = trms.term(); System.out.println(++count + ". " + t.text() + ":" + trms.docFreq()); }
|
|