def _parse_named(key: str, value: str, negated: bool) -> tokens.NamedToken: original_value = value if key.endswith("-min"): key = key[:-4] value += ".." elif key.endswith("-max"): key = key[:-4] value = ".." + value criterion = _create_criterion(original_value, value) return tokens.NamedToken(key, criterion, negated)
def on_search_query_parsed(self, search_query: SearchQuery) -> SaQuery: new_special_tokens = [] for token in search_query.special_tokens: if token.value in ('fav', 'liked', 'disliked'): assert self.user if self.user.rank == 'anonymous': raise errors.SearchError('이 기능을 사용하기 위해서는 로그인해야 합니다.') criterion = criteria.PlainCriterion( original_text=self.user.name, value=self.user.name) setattr(criterion, 'internal', True) search_query.named_tokens.append( tokens.NamedToken(name=token.value, criterion=criterion, negated=token.negated)) else: new_special_tokens.append(token) search_query.special_tokens = new_special_tokens
def on_search_query_parsed(self, search_query: SearchQuery) -> SaQuery: new_special_tokens = [] for token in search_query.special_tokens: if token.value in ("fav", "liked", "disliked"): assert self.user if self.user.rank == "anonymous": raise errors.SearchError( "Must be logged in to use this feature.") criterion = criteria.PlainCriterion( original_text=self.user.name, value=self.user.name) setattr(criterion, "internal", True) search_query.named_tokens.append( tokens.NamedToken( name=token.value, criterion=criterion, negated=token.negated, )) else: new_special_tokens.append(token) search_query.special_tokens = new_special_tokens