@@ -83,13 +83,18 @@ def _field_term_to_q(field: str, term: str) -> Q:
8383 # prefer them to partial matches within TeXisms.
8484 if is_tex_query (term ):
8585 return Q ("match" , ** {f'{ field } .tex' : {'query' : term , 'boost' : 2 }})
86+
87+ # "english" fields are analyzed with the English stoplist, so they're
88+ # safe for all kinds of searches.
89+ _fields = [f'{ field } .english' , f'{ field } _utf8__english' ]
90+
91+ # If this is a literal query, however, we should search against the
92+ # the base field, too.
93+ if is_literal_query (term_sans_tex ):
94+ _fields += [field , f'{ field } _utf8' ]
95+
8696 q = (
87- Q ("query_string" , fields = [
88- field ,
89- f'{ field } _utf8' ,
90- f'{ field } __english' ,
91- f'{ field } _utf8__english'
92- ],
97+ Q ("query_string" , fields = _fields ,
9398 default_operator = 'AND' ,
9499 analyze_wildcard = True ,
95100 allow_leading_wildcard = False ,
@@ -193,8 +198,8 @@ def _fielded_terms_to_q(query: AdvancedQuery) -> Match:
193198 # authors respond and also titles (and, to a lesser extent,
194199 # abstracts) respond.
195200 q |= Q ("multi_match" ,
196- fields = ["title* ^30" , "abstract*^10" , "authors* " ],
197- query = escape ( term .term ) , boost = 4 , type = "cross_fields" )
201+ fields = ["title.english ^30" , "abstract.english *^10" ],
202+ query = term .term , boost = 4 , type = "cross_fields" )
198203 else :
199204 q = _field_term_to_q (term .field , term .term )
200205
@@ -212,17 +217,17 @@ def simple(search: Search, query: SimpleQuery) -> Search:
212217 q_ar = [_field_term_to_q (field , query .value )
213218 for field in use ]
214219 q = reduce (ior , q_ar )
220+
215221 if not is_literal_query (query .value ):
216222 # When searching in "all fields", users will include terms from
217223 # various different fields. This additional multi-match treats
218- # title, abstract, and authors as one big field, and boosts
224+ # title and abstract as one big field, and boosts
219225 # matching results. Since authors get boosted strongly elsewhere,
220226 # this effectively surfaces results for which authors respond and
221227 # also titles (and, to a lesser extent, abstracts) respond.
222228 q |= Q ("multi_match" ,
223- fields = ["title* ^30" , "abstract*^10" , "authors* " ],
229+ fields = ["title.english ^30" , "abstract.english *^10" ],
224230 query = query .value , boost = 4 , type = "cross_fields" )
225- pass
226231 else :
227232 q = _field_term_to_q (query .search_field , query .value )
228233 search = search .query (q )
@@ -261,6 +266,7 @@ def highlight(search: Search) -> Search:
261266 post_tags = [HIGHLIGHT_TAG_CLOSE ]
262267 )
263268 search = search .highlight ('title' , type = 'plain' , number_of_fragments = 0 )
269+ search = search .highlight ('title.english' , type = 'plain' , number_of_fragments = 0 )
264270 search = search .highlight ('title.tex' , type = 'plain' , number_of_fragments = 0 )
265271 search = search .highlight ('title_utf8' , type = 'plain' ,
266272 number_of_fragments = 0 )
@@ -279,4 +285,6 @@ def highlight(search: Search) -> Search:
279285 search = search .highlight ('abstract' , type = 'plain' , number_of_fragments = 0 )
280286 search = search .highlight ('abstract.tex' , type = 'plain' ,
281287 number_of_fragments = 0 )
288+ search = search .highlight ('abstract.english' , type = 'plain' ,
289+ number_of_fragments = 0 )
282290 return search
0 commit comments