From 319fc5e87721a9d4e04b3ef3ddc1897539487cf1 Mon Sep 17 00:00:00 2001 From: Aric Coady Date: Sun, 7 Jul 2024 10:21:34 -0700 Subject: [PATCH] Dictionary constructor. Cache cleanup. --- lupyne/engine/indexers.py | 15 ++++++++++----- tests/test_engine.py | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lupyne/engine/indexers.py b/lupyne/engine/indexers.py index 6d0520e..7009518 100644 --- a/lupyne/engine/indexers.py +++ b/lupyne/engine/indexers.py @@ -137,6 +137,11 @@ def fieldinfos(self) -> dict: fieldinfos = index.FieldInfos.getMergedFieldInfos(self.indexReader) return {fieldinfo.name: fieldinfo for fieldinfo in fieldinfos.iterator()} + def dictionary(self, name: str, *args) -> spell.Dictionary: + """Return lucene Dictionary, suitable for spellcheckers.""" + cls = spell.HighFrequencyDictionary if args else spell.LuceneDictionary + return cls(self.indexReader, name, *args) + def suggest(self, name: str, value, count: int = 1, **attrs) -> list: """Return spelling suggestions from DirectSpellChecker. @@ -660,11 +665,11 @@ def __iter__(self): def __getitem__(self, id): return self.indexSearcher[id] - def refresh(self, **caches): - """Store refreshed searcher with [reopen][lupyne.engine.indexers.IndexSearcher.reopen] caches.""" - self.indexSearcher = self.indexSearcher.reopen(**caches) + def refresh(self): + """Store refreshed searcher from [reopening][lupyne.engine.indexers.IndexSearcher.reopen].""" + self.indexSearcher = self.indexSearcher.reopen() - def commit(self, merge=False, **caches): + def commit(self, merge: int = False): """Commit writes and [refresh][lupyne.engine.indexers.Indexer.refresh] searcher. Args: @@ -677,4 +682,4 @@ def commit(self, merge=False, **caches): else: self.forceMerge(merge) super().commit() - self.refresh(**caches) + self.refresh() diff --git a/tests/test_engine.py b/tests/test_engine.py index 3cdea12..f6b1067 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -210,6 +210,8 @@ def test_spellcheck(tempdir, fields, constitution): for doc in constitution: indexer.add(doc) indexer.commit() + assert indexer.dictionary('text') + assert indexer.dictionary('text', 0.5) assert indexer.complete('missing', '', 1) == [] assert ['the', 'shall'] == indexer.complete('text', '', 2) assert indexer.complete('text', 'con', 2) == ['congress', 'constitution']