Skip to content

Merge SearchLanguage.init() into __init__() #13562

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

Merged
merged 1 commit into from
May 16, 2025
Merged
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
5 changes: 1 addition & 4 deletions sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ class SearchLanguage:
_word_re = re.compile(r'\w+')

def __init__(self, options: dict[str, str]) -> None:
self.options = options
self.init(options)

def init(self, options: dict[str, str]) -> None:
"""Initialize the class with the options the user has given."""
self.options = options

def split(self, input: str) -> list[str]:
"""This method splits a sentence into words. Default splitter splits input
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class SearchDanish(SearchLanguage):
js_stemmer_rawcode = 'danish-stemmer.js'
stopwords = danish_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('danish')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class SearchGerman(SearchLanguage):
js_stemmer_rawcode = 'german-stemmer.js'
stopwords = german_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('german')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class SearchEnglish(SearchLanguage):
js_stemmer_code = js_porter_stemmer
stopwords = english_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('porter')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ class SearchSpanish(SearchLanguage):
js_stemmer_rawcode = 'spanish-stemmer.js'
stopwords = spanish_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('spanish')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/fi.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class SearchFinnish(SearchLanguage):
js_stemmer_rawcode = 'finnish-stemmer.js'
stopwords = finnish_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('finnish')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class SearchFrench(SearchLanguage):
js_stemmer_rawcode = 'french-stemmer.js'
stopwords = french_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('french')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/hu.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class SearchHungarian(SearchLanguage):
js_stemmer_rawcode = 'hungarian-stemmer.js'
stopwords = hungarian_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('hungarian')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ class SearchItalian(SearchLanguage):
js_stemmer_rawcode = 'italian-stemmer.js'
stopwords = italian_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('italian')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/ja.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ class SearchJapanese(SearchLanguage):
lang = 'ja'
language_name = 'Japanese'

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
dotted_path = options.get('type')
if dotted_path is None:
self.splitter = DefaultSplitter(options)
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class SearchDutch(SearchLanguage):
js_stemmer_rawcode = 'dutch-stemmer.js'
stopwords = dutch_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('dutch')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/no.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class SearchNorwegian(SearchLanguage):
js_stemmer_rawcode = 'norwegian-stemmer.js'
stopwords = norwegian_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('norwegian')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ class SearchPortuguese(SearchLanguage):
js_stemmer_rawcode = 'portuguese-stemmer.js'
stopwords = portuguese_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('portuguese')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SearchRomanian(SearchLanguage):
js_stemmer_rawcode = 'romanian-stemmer.js'
stopwords: set[str] = set()

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('romanian')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ class SearchRussian(SearchLanguage):
js_stemmer_rawcode = 'russian-stemmer.js'
stopwords = russian_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('russian')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class SearchSwedish(SearchLanguage):
js_stemmer_rawcode = 'swedish-stemmer.js'
stopwords = swedish_stopwords

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('swedish')

def stem(self, word: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/search/tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SearchTurkish(SearchLanguage):
js_stemmer_rawcode = 'turkish-stemmer.js'
stopwords: set[str] = set()

def init(self, options: dict[str, str]) -> None:
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.stemmer = snowballstemmer.stemmer('turkish')

def stem(self, word: str) -> str:
Expand Down
2 changes: 0 additions & 2 deletions sphinx/search/zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ class SearchChinese(SearchLanguage):
def __init__(self, options: dict[str, str]) -> None:
super().__init__(options)
self.latin_terms: set[str] = set()

def init(self, options: dict[str, str]) -> None:
dict_path = options.get('dict', JIEBA_DEFAULT_DICT)
if dict_path and Path(dict_path).is_file():
jieba_load_userdict(str(dict_path))
Expand Down
Loading