Skip to content

Commit ae69ae9

Browse files
adds TextQuery class
1 parent 9025bfe commit ae69ae9

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

redisvl/query/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
BaseVectorQuery,
55
CountQuery,
66
FilterQuery,
7+
HybridQuery,
78
RangeQuery,
89
TextQuery,
910
VectorQuery,

redisvl/query/query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum
22
from typing import Any, Dict, List, Optional, Set, Tuple, Union
33

4+
from redis.commands.search.aggregation import AggregateRequest, Desc
45
from redis.commands.search.query import Query as RedisQuery
56

67
from redisvl.query.filter import FilterExpression
@@ -790,6 +791,7 @@ def set_stopwords(self, stopwords: Optional[Union[str, Set[str]]] = "english"):
790791

791792
def tokenize_and_escape_query(self, user_query: str) -> str:
792793
"""Convert a raw user query to a redis full text query joined by ORs"""
794+
from redisvl.utils.token_escaper import TokenEscaper
793795

794796
escaper = TokenEscaper()
795797

@@ -811,7 +813,7 @@ def _build_query_string(self) -> str:
811813
else:
812814
filter_expression = ""
813815

814-
text = f"(@{self._text_field}:({self.tokenize_and_escape_query(self._text)}))"
816+
text = f"~(@{self._text_field}:({self.tokenize_and_escape_query(self._text)}))"
815817
if filter_expression and filter_expression != "*":
816818
text += f"({filter_expression})"
817819
return text

tests/unit/test_query_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_text_query():
204204
assert text_query._num_results == 10
205205
assert (
206206
text_query.filter
207-
== f"(@{text_field_name}:({text_query.tokenize_and_escape_query(text_string)}))"
207+
== f"(~@{text_field_name}:({text_query.tokenize_and_escape_query(text_string)}))"
208208
)
209209
assert isinstance(text_query, Query)
210210
assert isinstance(text_query.query, Query)

0 commit comments

Comments
 (0)