X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/samples/LuceneInAction/lia/analysis/synonym/WordNetSynonymEngine.py diff --git a/samples/LuceneInAction/lia/analysis/synonym/WordNetSynonymEngine.py b/samples/LuceneInAction/lia/analysis/synonym/WordNetSynonymEngine.py index 9912458..8da55b3 100644 --- a/samples/LuceneInAction/lia/analysis/synonym/WordNetSynonymEngine.py +++ b/samples/LuceneInAction/lia/analysis/synonym/WordNetSynonymEngine.py @@ -13,22 +13,24 @@ # ==================================================================== from lucene import \ - Document, Term, IndexSearcher, TermQuery, FSDirectory, RAMDirectory, Hit + Document, Term, IndexSearcher, TermQuery, \ + SimpleFSDirectory, RAMDirectory, File class WordNetSynonymEngine(object): def __init__(self, indexDir): - self.directory = RAMDirectory(indexDir) + self.directory = RAMDirectory(SimpleFSDirectory(File(indexDir))) self.searcher = IndexSearcher(self.directory) def getSynonyms(self, word): synList = [] - - for hit in self.searcher.search(TermQuery(Term("word", word))): - doc = Hit.cast_(hit).getDocument() + topDocs = self.searcher.search(TermQuery(Term("word", word)), 50) + + for scoreDoc in topDocs.scoreDocs: + doc = self.searcher.doc(scoreDoc.doc) for value in doc.getValues("syn"): synList.append(value)