Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Aug 16, 2024
1 parent eac2c1d commit d05e623
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion share/search/index_strategy/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses
import datetime
import json
import typing


def timestamp_to_readable_datetime(timestamp_in_milliseconds):
Expand All @@ -20,6 +21,9 @@ def encode_cursor_dataclass(dataclass_instance) -> str:
return _cursor_bytes.decode()


def decode_cursor_dataclass(cursor: str, dataclass_class) -> dict:
_SomeDataclass = typing.TypeVar('_SomeDataclass')


def decode_cursor_dataclass(cursor: str, dataclass_class: type[_SomeDataclass]) -> _SomeDataclass:
_as_list = json.loads(base64.urlsafe_b64decode(cursor))
return dataclass_class(*_as_list)
11 changes: 6 additions & 5 deletions share/search/index_strategy/trovesearch_flattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ def _cardsearch_response(
cursor.result_count = _es8_total['value']
if cursor.random_sort and not cursor.is_first_page():
# account for the filtered-out first page
assert cursor.result_count is not None
cursor.result_count += len(cursor.first_page_pks)
_results = []
for _es8_hit in es8_response['hits']['hits']:
Expand Down Expand Up @@ -852,6 +853,7 @@ class _SimpleCursor:
def from_page_param(cls, page: PageParam) -> '_SimpleCursor':
if page.cursor:
return decode_cursor_dataclass(page.cursor, cls)
assert page.size is not None
return cls(
start_index=0,
page_size=page.size,
Expand Down Expand Up @@ -891,7 +893,7 @@ def max_index(self) -> int:
return (
self.MAX_INDEX
if self.has_many_more()
else min(self.result_count, self.MAX_INDEX)
else min(self.result_count or 0, self.MAX_INDEX)
)

def is_valid_cursor(self) -> bool:
Expand All @@ -909,6 +911,7 @@ class _CardsearchCursor(_SimpleCursor):
def from_cardsearch_params(cls, params: CardsearchParams) -> '_CardsearchCursor':
if params.page.cursor:
return decode_cursor_dataclass(params.page.cursor, cls)
assert params.page.size is not None
return cls(
start_index=0,
page_size=params.page.size,
Expand Down Expand Up @@ -1040,9 +1043,7 @@ def walk_twoples(
_path = (_pred,)
if isinstance(_obj, frozenset):
for _innerpath, _innerobj in walk_twoples(_obj):
yield (
(*_path, *_innerpath),
_innerobj,
)
_fullpath = (*_path, *_innerpath)
yield (_fullpath, _innerobj)
else:
yield (_path, _obj)
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def valuesearch_simple_cases(self) -> Iterator[tuple[dict[str, str], set[str]]]:
{BLARG.b, BLARG.c},
)
yield (
{'valueSearchPropertyPath': 'created'},
{'valueSearchPropertyPath': 'dateCreated'},
{'1999', '2012', '2024'},
)
# TODO: more
Expand Down
2 changes: 1 addition & 1 deletion trove/trovesearch/search_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def parse_queryparams(cls, queryparams: QueryparamDict) -> dict:

def to_querydict(self):
_querydict = super().to_querydict()
_querydict['valueSearchPropertyPath'] = propertypath_set_key(self.valuesearch_propertypath)
_querydict['valueSearchPropertyPath'] = propertypath_key(self.valuesearch_propertypath)
for _qp_name, _qp_value in Textsegment.queryparams_from_textsegments('valueSearchText', self.valuesearch_textsegment_set):
_querydict[_qp_name] = _qp_value
for _filter in self.valuesearch_filter_set:
Expand Down

0 comments on commit d05e623

Please sign in to comment.