Sorry, you can see the script below: Thanks
//******************** Index Method ******************************************/ public void index(DoubleMap doubleMap, String dirPath, String originalPath) throws IOException { File f = new File(dirPath); IndexWriter writer = null; if(f.exists()) { writer = new IndexWriter(dirPath, new WhitespaceAnalyzer(), false); } else { writer = new IndexWriter(dirPath, new WhitespaceAnalyzer(), true); } writer.setSimilarity(new WordsSimilarity()); Iterator it = doubleMap.getMap().entrySet().iterator(); int count = 0; int size = doubleMap.getMap().size(); while(it.hasNext()) { count++; Map.Entry entry = (Map.Entry) it.next(); String word = entry.getKey().toString(); Word w = new Word(); w.word = word; Date date = new Date(); System.out.println(date.toString() + " : Updateing word " + word + " ( " + count + " out of " + size + ") " + " FROM " + originalPath); Map<Long, Double> innerMap = (Map<Long, Double>) entry.getValue(); Document doc = WordIndex.getDoc(word, dirPath); if(doc != null) { doc = WordIndex.addToDoc(doc, innerMap); /// delete the document and then add it writer.deleteDocuments(new Term(WordIndex.FIELD_WORD, word)); writer.addDocument(doc); } else { w.worldsMap = innerMap; WordIndex wi = new WordIndex(w); wi.createDocument(); writer.addDocument(wi.getDocument()); } } System.out.println("Optimizing " + dirPath + " ..."); writer.optimize(); writer.close(); } //******************** WordIndex class ******************************************/ public class WordIndex extends Index { protected Word w; public static String FIELD_WORD = "word"; public static String FIELD_WORLDS = "worlds"; public WordIndex(Word w) { this.w = w; } public void createDocument() throws java.io.FileNotFoundException { // make a new, empty document doc = new Document(); // Add the id of the patent // indexed (i.e. searchable), but don't tokenize the field into words. doc.add(new Field(FIELD_WORD, w.word, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.add(new Field(FIELD_WORLDS, String.valueOf(w.getWorldIds()), Field.Store.YES, Field.Index.TOKENIZED)); // Iterator iter = w.worldsMap.entrySet().iterator(); // while(iter.hasNext()) // { // Map.Entry entry = (Map.Entry) iter.next(); // doc.add(new Field(entry.getKey().toString(), String.valueOf(entry.getValue()), Field.Store.YES, Field.Index.UN_TOKENIZED)); // } } public static Document addToDoc(Document doc, Map<Long, Double> map) { Iterator iter = map.entrySet().iterator(); String worlds = doc.getField(WordIndex.FIELD_WORLDS).stringValue(); doc.removeField(FIELD_WORLDS); while(iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String worldId = entry.getKey().toString(); if(doc.getField(worldId) == null) { // doc.add(new Field(entry.getKey().toString(), String.valueOf(entry.getValue()), Field.Store.YES, Field.Index.UN_TOKENIZED)); // also add to the field of worlds the current world worlds += entry.getKey().toString() + " "; } } System.out.println(worlds); doc.add(new Field(FIELD_WORLDS, String.valueOf(worlds), Field.Store.YES, Field.Index.TOKENIZED)); return doc; } public static Document getDoc(String word, String indexPath) throws IOException { IndexSearcher mapSearcher = new IndexSearcher(indexPath); TermQuery mapQuery = new TermQuery(new Term(FIELD_WORD, word)); Hits mapHits = mapSearcher.search(mapQuery); if(mapHits.length() != 0) { Document doc = mapHits.doc(0); return doc; } return null; } } 2009/4/21 Chris Hostetter <hossman_luc...@fucit.org> > > Erick means we need to see *all* of your code (inlcuding how you get the > score and the Explanation you are printing) to understand why they don't > match. > > All you've shown is the output of your program and the generation of a > Hits object. > > > > -Hoss > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > >