Exemplo n.º 1
0
def _create_criterion(original_value: str,
                      value: str) -> criteria.BaseCriterion:
    if ',' in value:
        return criteria.ArrayCriterion(original_value, value.split(','))
    if '..' in value:
        low, high = value.split('..', 1)
        if not low and not high:
            raise errors.SearchError('Empty ranged value')
        return criteria.RangedCriterion(original_value, low, high)
    return criteria.PlainCriterion(original_value, value)
Exemplo n.º 2
0
def _create_criterion(original_value: str,
                      value: str) -> criteria.BaseCriterion:
    if re.search(r'(?<!\\),', value):
        values = re.split(r'(?<!\\),', value)
        if any(not term.strip() for term in values):
            raise errors.SearchError('Empty compound value')
        return criteria.ArrayCriterion(original_value, values)
    if re.search(r'(?<!\\)\.(?<!\\)\.', value):
        low, high = re.split(r'(?<!\\)\.(?<!\\)\.', value, 1)
        if not low and not high:
            raise errors.SearchError('Empty ranged value')
        return criteria.RangedCriterion(original_value, low, high)
    return criteria.PlainCriterion(original_value, value)
Exemplo n.º 3
0
def _create_criterion(original_value: str,
                      value: str) -> criteria.BaseCriterion:
    if re.search(r"(?<!\\),", value):
        values = re.split(r"(?<!\\),", value)
        if any(not term.strip() for term in values):
            raise errors.SearchError("Empty compound value")
        return criteria.ArrayCriterion(original_value, values)
    if re.search(r"(?<!\\)\.(?<!\\)\.", value):
        low, high = re.split(r"(?<!\\)\.(?<!\\)\.", value, 1)
        if not low and not high:
            raise errors.SearchError("Empty ranged value")
        return criteria.RangedCriterion(original_value, low, high)
    if value.lower() in ["null", "none", "unknown", "?"]:
        return criteria.NullCriterion(original_value)
    return criteria.PlainCriterion(original_value, value)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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