diff --git a/AUTHORS b/AUTHORS index 4c07544..75481f0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,4 +23,4 @@ Thanks to: * Sym Roe for a patch that improved performance in "more-like-this" and suggestion the removal of FLAG_PARTIAL. * liranz for pointing out a potential conflict with arguments pass into `SearchResult` * Jacob Kaplan-Moss for pointing out that write permission shouldn't be required for searching. - * glassresistor for assistance troubleshooting an issue with boosting a phrase query. \ No newline at end of file + * glassresistor for assistance troubleshooting an issue with boosting a phrase query & a patch to make weighting schemes overridable. \ No newline at end of file diff --git a/README.rst b/README.rst index 26e5800..858713c 100644 --- a/README.rst +++ b/README.rst @@ -44,7 +44,11 @@ Installation Configuration ------------- -As well as the flags described `here `_, the xapian backend includes and additional `HAYSTACK_XAPIAN_FLAGS` variable to further configure how indexes are stored and manipulated. By default, this value is set to `FLAG_PHRASE | FLAG_BOOLEAN | FLAG_LOVEHATE | FLAG_WILDCARD | FLAG_PURE_NOT`. See the `Xapian documentation `_ for further explanation of the available Xapian.QueryParser flags. +As well as the flags described `here `_, the xapian backend includes two additional variables: + + - `HAYSTACK_XAPIAN_FLAGS` -- used to further configure how indexes are stored and manipulated. By default, this value is set to `FLAG_PHRASE | FLAG_BOOLEAN | FLAG_LOVEHATE | FLAG_WILDCARD | FLAG_PURE_NOT`. See the `Xapian::QueryParser::feature_flag in the Xapian documentation `_ for further explanation of the available Xapian.QueryParser flags. + + - `HAYSTACK_XAPIAN_WEIGHTING_SCHEME` -- used to override the default weighting scheme used during search. `HAYSTACK_XAPIAN_WEIGHTING_SCHEME` is assumed to be a tuple that corepsonds to the arguments to a BM25Weight constructor. See `Xapian::BM25Weight::BM25Weight in the Xapian documentation `_ for further information. Testing ------- diff --git a/xapian_backend.py b/xapian_backend.py index fbbe221..a600adb 100755 --- a/xapian_backend.py +++ b/xapian_backend.py @@ -396,6 +396,8 @@ class SearchBackend(BaseSearchBackend): ) enquire = xapian.Enquire(database) + if hasattr(settings, 'HAYSTACK_XAPIAN_WEIGHTING_SCHEME'): + enquire.set_weighting_scheme(xapian.BM25Weight(*settings.HAYSTACK_XAPIAN_WEIGHTING_SCHEME)) enquire.set_query(query) if sort_by: