Skip to content

Commit

Permalink
Fixed #141 -- Added configuration setting for stemming strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrast authored and jorgecarleitao committed Jan 12, 2015
1 parent 1ea3549 commit 82ba90b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -85,6 +85,11 @@ The backend has the following optional settings:
See `here <http://xapian.org/docs/apidoc/html/classXapian_1_1QueryParser.html>`_ for more information
on what they mean.

- ``HAYSTACK_XAPIAN_STEMMING_STRATEGY``: This option lets you chose the stemming strategy used by Xapian. Possible
values are ``STEM_NONE``, ``STEM_SOME``, ``STEM_ALL``, ``STEM_ALL_Z``, where ``STEM_SOME`` is the default.
See `here <http://xapian.org/docs/apidoc/html/classXapian_1_1QueryParser.html#ac7dc3b55b6083bd3ff98fc8b2726c8fd>`_ for
more information about the different strategies.


Testing
-------
Expand Down
6 changes: 5 additions & 1 deletion xapian_backend.py
Expand Up @@ -192,6 +192,9 @@ def __init__(self, connection_alias, **connection_options):
self.flags = connection_options.get('FLAGS', DEFAULT_XAPIAN_FLAGS)
self.language = getattr(settings, 'HAYSTACK_XAPIAN_LANGUAGE', 'english')

stemming_strategy_string = getattr(settings, 'HAYSTACK_XAPIAN_STEMMING_STRATEGY', 'STEM_SOME')
self.stemming_strategy = getattr(xapian.QueryParser, stemming_strategy_string, xapian.QueryParser.STEM_SOME)

# these 4 attributes are caches populated in `build_schema`
# they are checked in `_update_cache`
# use property to retrieve them
Expand Down Expand Up @@ -273,6 +276,7 @@ def update(self, index, iterable):
term_generator = xapian.TermGenerator()
term_generator.set_database(database)
term_generator.set_stemmer(xapian.Stem(self.language))
term_generator.set_stemming_strategy(self.stemming_strategy)
if self.include_spelling is True:
term_generator.set_flags(xapian.TermGenerator.FLAG_SPELLING)

Expand Down Expand Up @@ -805,7 +809,7 @@ def parse_query(self, query_string):
qp = xapian.QueryParser()
qp.set_database(self._database())
qp.set_stemmer(xapian.Stem(self.language))
qp.set_stemming_strategy(xapian.QueryParser.STEM_SOME)
qp.set_stemming_strategy(self.stemming_strategy)
qp.set_default_op(XAPIAN_OPTS[DEFAULT_OPERATOR])
qp.add_boolean_prefix('django_ct', TERM_PREFIXES['django_ct'])

Expand Down

0 comments on commit 82ba90b

Please sign in to comment.