Skip to content

Commit

Permalink
Dictionary constructor.
Browse files Browse the repository at this point in the history
Cache cleanup.
  • Loading branch information
coady committed Jul 7, 2024
1 parent 103fe79 commit 319fc5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lupyne/engine/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -677,4 +682,4 @@ def commit(self, merge=False, **caches):
else:
self.forceMerge(merge)
super().commit()
self.refresh(**caches)
self.refresh()
2 changes: 2 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 319fc5e

Please sign in to comment.