Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use RegexTokenizer; add DerivationPlugin; fix error in fields.json #547

Open
wants to merge 2 commits into
base: v1-track
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/alfanous/engines.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
from whoosh import qparser
from whoosh.qparser import QueryParser
from whoosh.qparser import TaggingPlugin, syntax, QueryParser
from whoosh.query import Variations

from alfanous.searching import QSearcher, QReader
from alfanous.indexing import QseDocIndex, ExtDocIndex, BasicDocIndex
from alfanous.results_processing import Qhighlight
from alfanous.query_processing import QuranicParser, StandardParser, FuzzyQuranicParser

word_derivations = {
'ملك': ['ملك', 'ملائكة', 'الملك']
}
class Derivations(Variations):
def _btexts(self, ixreader):
for word in (word_derivations.get(self.text) or []):
yield word # to_bytes()

class DerivationPlugin(TaggingPlugin):
class DerivationNode(syntax.WordNode):
qclass = Derivations

def r(self):
return ">>%r" % self.text

expr = "(?P<text>\>\>.*)"
nodetype = DerivationNode
priority = 100

class BasicSearchEngine:
def __init__(self, qdocindex, query_parser, main_field, otherfields, qsearcher, qreader, qhighlight):
Expand All @@ -16,9 +34,10 @@ def __init__(self, qdocindex, query_parser, main_field, otherfields, qsearcher,
self._docindex = qdocindex
#
self._schema = self._docindex.get_schema()
#
self._parser = query_parser(main_field, self._schema, group=qparser.OrGroup)
#
self._parser = query_parser(main_field, self._schema, group=qparser.OrGroup)
self._parser.add_plugin(DerivationPlugin)

self._searcher = qsearcher(self._docindex, self._parser)
#
self._reader = qreader(self._docindex)
Expand Down
Loading