diff --git a/src/morphodict/paradigm/preferences.py b/src/morphodict/paradigm/preferences.py index 425053f4e..1e5126d3f 100644 --- a/src/morphodict/paradigm/preferences.py +++ b/src/morphodict/paradigm/preferences.py @@ -22,4 +22,4 @@ class DisplayMode(Preference): # nêhiyawêwin labels; e.g., niya → kiya, mêkwâc "source_language": str(settings.MORPHODICT_LANGUAGE_ENDONYM) + " labels", } - default = "english" \ No newline at end of file + default = "english" diff --git a/src/morphodict/search/__init__.py b/src/morphodict/search/__init__.py index 38ee44e5b..e17237390 100644 --- a/src/morphodict/search/__init__.py +++ b/src/morphodict/search/__init__.py @@ -1,6 +1,7 @@ from .runner import search from .core import SearchResults + def search_with_affixes( query: str, include_auto_definitions=False, inflect_english_phrases=False ) -> SearchResults: diff --git a/src/morphodict/search/affix.py b/src/morphodict/search/affix.py index 20c51f15c..17342fcc2 100644 --- a/src/morphodict/search/affix.py +++ b/src/morphodict/search/affix.py @@ -97,7 +97,9 @@ def do_affix_search(query: InternalForm, affixes: AffixSearcher) -> Iterable[Wor return Wordform.objects.filter(id__in=matched_ids) -def do_target_language_affix_search(query: core.Query, search_results: core.SearchResults): +def do_target_language_affix_search( + query: core.Query, search_results: core.SearchResults +): matching_words = do_affix_search( query.query_string, cache.target_language_affix_searcher, @@ -106,7 +108,9 @@ def do_target_language_affix_search(query: core.Query, search_results: core.Sear search_results.add_result(Result(word, target_language_affix_match=True)) -def do_source_language_affix_search(query: core.Query, search_results: core.SearchResults): +def do_source_language_affix_search( + query: core.Query, search_results: core.SearchResults +): matching_words = do_affix_search( query.query_string, cache.source_language_affix_searcher, diff --git a/src/morphodict/search/core.py b/src/morphodict/search/core.py index 21e30d5b9..7bd95325d 100644 --- a/src/morphodict/search/core.py +++ b/src/morphodict/search/core.py @@ -24,11 +24,11 @@ class SearchResults: and to add results to the result collection for future ranking. """ - def __init__(self, query: Query, include_auto_definitions=None): + def __init__(self, auto=None, verbose=False, include_auto_definitions=None): self.include_auto_definitions = first_non_none_value( - query.auto, include_auto_definitions, default=False + auto, include_auto_definitions, default=False ) - self.verbose = query.verbose + self.verbose = verbose self._results = {} self._verbose_messages = [] @@ -150,7 +150,6 @@ def add_verbose_message(self, message=None, **messages): def verbose_messages(self): return self._verbose_messages - def __repr__(self): return f"SearchResults" diff --git a/src/morphodict/search/cvd_search.py b/src/morphodict/search/cvd_search.py index 13c116925..39bd84b80 100644 --- a/src/morphodict/search/cvd_search.py +++ b/src/morphodict/search/cvd_search.py @@ -71,4 +71,6 @@ def do_cvd_search(query: Query, search_results: SearchResults): else: for wf in wordforms_for_query: if wordform_query_matches(wordform_query, wf): - search_results.add_result(Result(wf, cosine_vector_distance=distance)) + search_results.add_result( + Result(wf, cosine_vector_distance=distance) + ) diff --git a/src/morphodict/search/lookup.py b/src/morphodict/search/lookup.py index 258ffd1b0..5a2be8b56 100644 --- a/src/morphodict/search/lookup.py +++ b/src/morphodict/search/lookup.py @@ -136,7 +136,9 @@ def best_lemma_matches(analysis, possible_lemmas) -> list[Wordform]: ] -def fetch_results_from_target_language_keywords(query: core.Query,search_results: core.SearchResults): +def fetch_results_from_target_language_keywords( + query: core.Query, search_results: core.SearchResults +): for stemmed_keyword in stem_keywords(query.query_string): for wordform in Wordform.objects.filter( target_language_keyword__text__iexact=stemmed_keyword @@ -146,7 +148,9 @@ def fetch_results_from_target_language_keywords(query: core.Query,search_results ) -def fetch_results_from_source_language_keywords(query: core.Query, search_results: core.SearchResults): +def fetch_results_from_source_language_keywords( + query: core.Query, search_results: core.SearchResults +): res = SourceLanguageKeyword.objects.filter( Q(text=to_source_language_keyword(query.query_string)) ) diff --git a/src/morphodict/search/runner.py b/src/morphodict/search/runner.py index 5a015ede7..c887e5d9b 100644 --- a/src/morphodict/search/runner.py +++ b/src/morphodict/search/runner.py @@ -34,8 +34,9 @@ def search( search_query = Query(query) search_results = SearchResults( - search_query, - include_auto_definitions=include_auto_definitions + auto=search_query.auto, + verbose=search_query.verbose, + include_auto_definitions=include_auto_definitions, ) initial_query_terms = search_query.query_terms[:] @@ -49,9 +50,9 @@ def search( if settings.MORPHODICT_ENABLE_CVD: cvd_search_type = first_non_none_value( - search_query.cvd, - default=CvdSearchType.DEFAULT) - + search_query.cvd, default=CvdSearchType.DEFAULT + ) + # For when you type 'cvd:exclusive' in a query to debug ONLY CVD results! if cvd_search_type == CvdSearchType.EXCLUSIVE: @@ -74,8 +75,7 @@ def sort_by_cvd(r: Result): if settings.MORPHODICT_ENABLE_CVD: if cvd_search_type.should_do_search() and not is_almost_certainly_cree( - search_query, - search_results + search_query, search_results ): do_cvd_search(search_query, search_results) @@ -90,8 +90,10 @@ def sort_by_cvd(r: Result): return search_results + CREE_LONG_VOWEL = re.compile("[êîôâēīōā]") + def is_almost_certainly_cree(query: Query, search_results: SearchResults) -> bool: """ Heuristics intended to AVOID doing an English search. @@ -105,7 +107,9 @@ def is_almost_certainly_cree(query: Query, search_results: SearchResults) -> boo return True if CREE_LONG_VOWEL.search(query.query_string): - search_results.add_verbose_message("Skipping CVD because query has Cree diacritics") + search_results.add_verbose_message( + "Skipping CVD because query has Cree diacritics" + ) return True return False diff --git a/src/morphodict/tests/espt/test_espt_crk.py b/src/morphodict/tests/espt/test_espt_crk.py index 2f98313bf..2500f3fec 100644 --- a/src/morphodict/tests/espt/test_espt_crk.py +++ b/src/morphodict/tests/espt/test_espt_crk.py @@ -93,8 +93,8 @@ def test_search_with_tags(query, has_tags, tags, filtered_query): ) def test_espt_search(db, search, params): search_query = Query(search) - search_results = SearchResults(search_query) - espt_search = EsptSearch(search_query,search_results) + search_results = SearchResults() + espt_search = EsptSearch(search_query, search_results) espt_search.convert_search_query_to_espt() assert search_query.query_terms == params["expected_query_terms"] assert search_query.query_string == " ".join(params["expected_query_terms"]) @@ -118,8 +118,8 @@ def test_espt_search(db, search, params): def test_espt_search_doesnt_crash_when_no_analysis(db): search_query = Query("my little bears") - search_results = SearchResults(search_query) - espt_search = EsptSearch(search_query,search_results) + search_results = SearchResults() + espt_search = EsptSearch(search_query, search_results) espt_search.convert_search_query_to_espt() wordform = Wordform(text="pê-")