Skip to content

Answer searches as SearchResult objects from McritClient - #169

Open
r0ny123 wants to merge 2 commits into
danielplohmann:mainfrom
r0ny123:feat/64-typed-search-results
Open

Answer searches as SearchResult objects from McritClient#169
r0ny123 wants to merge 2 commits into
danielplohmann:mainfrom
r0ny123:feat/64-typed-search-results

Conversation

@r0ny123

@r0ny123 r0ny123 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Closes fkie-cad/mcritweb#64 (McritClient should return objects for search results).

Every accessor of McritClient hands out FamilyEntry / SampleEntry / FunctionEntry objects, except the three searches, which answer the raw wire dict. This adds the typed counterpart without changing the existing methods.

Changes

  • mcrit/storage/SearchResult.py: a small generic container. entries maps id to entry object, cursor carries the forward/backward paging cursors, id_match / sha_match are the entries a numeric or sha256 search term named directly (direct_matches gives them without duplicates). fromDict() reads the wire dict, toDict() gives it back in the client's form (string result keys, sha_match only where the endpoint answered it). It iterates over its entries and has a length.
  • McritClient.searchFamilies() / searchSamples() / searchFunctions(): the same request as search_families / search_samples / search_functions (same cursor, is_ascending, sort_by, limit parameters), answered as SearchResult[FamilyEntry] etc., None on a failed request. The search_* methods keep returning the dict, so no caller changes.

Verification

  • tests/testSearchResult.py: a function search answer becomes FunctionEntry objects with the cursor kept and round-trips through toDict(); id and sha matches on the sample search become entries and are deduplicated; the empty answer; the client builds the same URL as the dict method and answers objects; a failed request answers None.
  • Full suite: 208 passed, ruff check, ruff format --check, ty check clean.
  • Against a live MongoDB-backed server: search_*(...) == search*(...).toDict() for function, sample (with and without id match) and family searches.

The mcritweb side (consuming these in the search views) is fkie-cad/mcritweb#174.

Every accessor of McritClient hands out FamilyEntry/SampleEntry/FunctionEntry
objects, except the three searches, which answer the raw wire dict
(fkie-cad/mcritweb#64). Add SearchResult, a small generic container with the
entries deserialized, the paging cursor, the id_match/sha_match entries and a
toDict() that gives the wire format back, plus searchFamilies(),
searchSamples() and searchFunctions() on the client that answer it. The
existing search_* methods keep returning the dict, so nothing changes for
current callers.
The camel-case accessors answer the requests.Response itself when the client
was built with raw_responses=True; the new typed searches deserialised
regardless. Split the request out of _search_base so the typed searches can
return the response in raw mode. The dict methods are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McritClient should return objects (search results)

1 participant