Skip to content

Commit

Permalink
kv index search
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <praneethbedapudi@gmail.com>
  • Loading branch information
bedapudi6788 committed Jan 21, 2024
1 parent e42360e commit d0ad74d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
9 changes: 5 additions & 4 deletions liteindex/kv_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,11 @@ def search(

sort_by = "updated_at" if self.preserve_order else "ROWID"

if isinstance(params[0], (int, float)):
sort_by = "num_value"
else:
sort_by = "string_value"
if sort_by_value:
if isinstance(params[0], (int, float)):
sort_by = "num_value"
else:
sort_by = "string_value"

sort_by = f"ORDER BY {sort_by} {'DESC' if reversed_sort else ''}"

Expand Down
26 changes: 16 additions & 10 deletions liteindex/kv_index_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,25 @@ def create_where_clause(query):
wheres.append("{} REGEXP ?".format(__get_column_name(value)))
args.append(value)
else:
column_name = __get_column_name(value)
if column_name == "pickled_value":
if not isinstance(value, bytes):
value = pickle.dumps(value, protocol=pickle.HIGHEST_PROTOCOL)

if isinstance(value, bool):
if value is None:
# num_value, string_value, pickled_value all should be NULL
wheres.append(
f"(pickled_value {op_map[op]} ? AND num_value = {int(value)})"
"num_value IS NULL AND string_value IS NULL AND pickled_value IS NULL"
)
args.append(b"")
else:
wheres.append(f"{column_name} {op_map[op]} ?")
args.append(value)
column_name = __get_column_name(value)
if column_name == "pickled_value":
if not isinstance(value, bytes):
value = pickle.dumps(value, protocol=pickle.HIGHEST_PROTOCOL)

if isinstance(value, bool):
wheres.append(
f"(pickled_value {op_map[op]} ? AND num_value = {int(value)})"
)
args.append(b"")
else:
wheres.append(f"{column_name} {op_map[op]} ?")
args.append(value)

return " AND ".join(wheres), args

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
EMAIL = "praneeth@bpraneeth.com"
AUTHOR = "BEDAPUDI PRANEETH"
REQUIRES_PYTHON = ">=3.6.0"
VERSION = "0.0.2.dev40"
VERSION = "0.0.2.dev41"

# What packages are required for this module to be executed?
REQUIRED = []

# What packages are optional?
EXTRAS = {
'all': ['zstandard'],
"all": ["zstandard"],
}

# The rest you shouldn't have to touch too much :)
Expand Down
2 changes: 1 addition & 1 deletion tests/kv_index_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
assert index.search("value1", n=10, offset=0) == {"key1": "value1"}
assert index.search("value1", n=10, offset=1) == {}

# assert index.search(None) == {"keyNone": None}
assert index.search(None) == {"keyNone": None}
assert index.search(True) == {"keyTrue": True}

assert index.search({"$gt": 6}, n=10, offset=0) == {
Expand Down

0 comments on commit d0ad74d

Please sign in to comment.