Skip to content

Filter the cheap searches as the term is typed - #293

Merged
danielplohmann merged 6 commits into
masterfrom
feat/sample-search-as-you-type
Oct 29, 2026
Merged

danielplohmann merged 6 commits into
masterfrom
feat/sample-search-as-you-type

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Looking a function up on a sample's page meant typing offset:0x6840 and pressing Enter, and every change to the term reloaded the whole page. Four search boxes now filter their table as you type: a sample's functions, the sample list, the family list and a family's samples. On a sample's page a bare hex number is taken as an offset, so 0x6840 finds the function at 0x6840 and a part of a name finds the functions with that name.

Change.

  • mcritweb/static/live_search.js handles any search form marked data-live-search="<id>".
    • Once typing pauses (300 ms), it fetches the page the form would load: the same URL, the new query, and the cursor dropped so the results start from the first page. Sort and page size stay; a chosen page size gets page=1 along with it, since the pagination reads a size only with a page number (mcritweb/views/cursor_pagination.py:163-168).
    • It swaps in that page's element of the given id (the table and its pagination) and the messages flashed with it, and updates the address with history.replaceState, so the URL can be reloaded or shared.
    • A request still in flight is aborted when the term changes, also when it changes back to the term on screen. Scripts in the swapped content run, as on a page load; the edit modals carry their own (toggle_delete_family and toggle_delete_sample).
    • An answer that is not that page, such as the login page once the session has expired or an error, makes the browser load the page instead.
    • Enter still loads the whole page, as it does without script.
    • A visually hidden role="status" line says how many rows are on the page, or that the search failed, for screen readers, without the table being read out.
    • An edit modal open when an answer arrives is left alone: it lives in the swapped region, and swapping it out left its backdrop over a page nobody could use. The search runs again once the modal is closed.
  • The four templates mark their form and wrap the table and pagination in a div with that id: single_sample.html, samples.html, families.html and single_family.html. The sample page's placeholder says the box takes a name or an offset.
  • On a sample's page, sample_function_query() (mcritweb/views/explore.py:630) turns a term that is only a hex number (0x or 0X and hex digits) into offset:<term>; mcrit reads the value with int(value, 0). Anything else is passed as typed. Before, such a term was matched as a substring of the function names and found nothing. An offset of 2^63 or more fails in mcrit's search, with or without the shortcut (offset:0xffffffff81000000 answers 500 on mcrit 1.13.0), because MongoDB stores such an offset as a signed value. Answer bad search input with 400, keep minhashes a recalculation can't rebuild mcrit#276 makes that search find the function.
  • Following ADR-0014, the row clicks of the function, sample and family tables are delegated to document. ADR-0014 names that as the precondition for swapping a table: bindings made on load stay with the rows that were there. The edit modals' show.bs.modal listeners are delegated too, since a list that loaded without rows had no modal to bind to. Before Fix the accessibility and SEO audits Lighthouse fails across the app (#243) #244, /explore/samples?query=zzzzqq threw "Cannot read properties of null (reading 'addEventListener')" at load; Fix the accessibility and SEO audits Lighthouse fails across the app (#243) #244's ?. stops the throw, but a modal a search brings in later would still get no listener, so the delegated listener replaces it. ac_family_names.html also attaches the family-name type-ahead on first focus, for a modal that a search brings in.

Half-typed terms. On mcrit 1.13.0, a term cut off mid-way (offset:, offset:0x, function_name:, an unclosed ") answers no rows. One that does not parse (an unclosed (, a trailing AND) is refused, and the page shows its existing "Could not search MCRIT's functions" message until the term is complete again.

Where it is not used.

  • The function list and the combined search page still wait for Enter. A bare term there is matched against every function name in the corpus, which takes tens of seconds on the backend (docs/adr/0016-slow-function-search-is-mcrits.md), and aborting the request in the browser does not stop the query in mcrit. Bound what search and function listing can make the server do mcrit#271 caps a search at 30 s on mongod, still far too long to run on every pause.
  • The sample pickers of compare, cross compare and unique blocks keep the selection in the page, which a swap would lose.

Verification. On the testbed (mcrit 1.13.0), a side instance of this branch against the live backend, in headless Chromium:

page typed result
sample 18 (100 functions) pre_c 2 rows (pre_c_init, pre_cpp_init), one request, no page load, address ?query=pre_c
sample 18 0x401010 1 row, function 4689 at 0x401010
sample 18 cleared 100 rows again, focus still in the box
sample list (25 on the page) fastlist 2 rows; the edit modal of a swapped-in row opens prefilled, with the family type-ahead
family list (16) launcher 3 rows; the edit modal opens prefilled
family 1 zzzz 0 rows

Clicking a swapped-in row opens its function, sample or family. Enter still loads the page. No script errors. A sample page with a search answers in 30 to 55 ms on the testbed, its job queue read included (master, /explore/samples/23, three runs each, best of three), so a request per pause is cheap there. Only GET requests were sent. After merging master (6564602), on a side instance of 916d701: pre_c on sample 18 narrows 100 rows to 2 and marks pre_c in both, 0x401010 gives 1 row, fastlist on the sample list 2 rows with the term marked, launcher on the family list 3, each without a page load and with no script errors. An independent browser review also found the page at rest unchanged against master at 1280 and 375 px, and back, forward and reload of a replaced address restoring the term and rows.

Tests.

  • tests/testLiveSearch.py:

    • the four pages carry the form, the region and the status line, and load the script;
    • the function list and the search page do not;
    • a bare hex number on a sample page reaches the backend as offset: (4 cases);
    • other terms are sent as typed (6 cases, guards);
    • the three row bindings are delegated.
  • tests/testLiveSearchBrowser.py, in Chromium on the offline corpus:

    • the sample list follows the term without a page load;
    • an answer held back until the term was put back to the one on screen is not shown;
    • a chosen page size is kept;
    • an edit modal open when an answer arrives stays, and the table follows once it is closed;
    • the rows a search swaps in carry Mark the search term in the rows that matched it (#45) #136's marks of the term;
    • a swapped-in row opens its sample;
    • the edit modal of a swapped-in row opens prefilled, for families and samples;
    • an edit modal a search brings into a list that loaded empty gets its title, the type-ahead and its script;
    • a failed fetch (session gone) loads the page;
    • Enter loads the page.

    They skip without Playwright, as in CI.

21 of the 30 new tests fail on master (6564602). Each guard was checked by taking it out: making the family or sample row binding direct again, the modal listener direct, dropping the script re-run, the focus hook, the abort, the page size, the open-modal check, the fallback or the offset rule fails at least one test. Full suite with Chromium on 916d701: 2109 passed, 11 skipped, none of them in this branch's files. ruff check . clean.

Relation to open PRs.

The search boxes of a sample's page, the family and sample lists and a
family's page now update their table once typing pauses. live_search.js
fetches the page the form would load and swaps in its table, pagination
and flashed messages; Enter still loads the page, and anything that is
not that page (an expired session, an error) loads it too.

The function list and the combined search page keep waiting for Enter:
an unscoped function search can take tens of seconds on the backend,
and aborting the request in the browser does not stop it (ADR-0016).

Following ADR-0014, the row clicks of the function, sample and family
tables and the edit modals' listeners are delegated, so rows swapped in
later behave like the ones loaded with the page, and the family-name
type-ahead also attaches to a modal on first focus.

On a sample's page a term that is only a hex number, like 0x6840, is
searched as offset:0x6840. It used to be matched against function names
and found nothing.
mcrit 1.15.0, which CI now installs, makes McritClient send through a
requests.Session() it opens in its constructor. The test swaps the
client's requests module for a stub with get and post only, so creating
the client raised AttributeError and all eight tests in the file
errored. The stub now hands itself back as the session. Same change as
in #285; it works with 1.13 and 1.15.
@r0ny123

r0ny123 commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

@danielplohmann a note on CI before this is merged: please merge #297 first.

The green run here is from 13 October, when CI installed mcrit 1.15.0. mcrit 1.16.0 came out on 16 October, and its McritClient opens its session from _McritSession, a requests.Session subclass that the stub in tests/testSubmitMetadata.py does not replace. So the next CI run here, on master or on any PR, fails those 8 tests trying to reach backend.invalid, as #253 shows now. Nothing in this PR is involved.

#297 fixes the stub for both 1.15 and 1.16. Once it is on master, this PR needs no change; I have left the fix out of it on purpose, so it stays in one place. This branch was also checked against master after the security batch (1db3833): the full suite passes on the merge, 1409 passed and 7 skipped, with mcrit 1.15.0.

Master brings #244, #136 and #119 into the pages this branch swaps.
- README: the unreleased lines this branch carried were folded into
  1.6.0; only the live search line stays above it.
- single_sample.html: #244's h2 headings and #119's empty message and
  #136's highlighting go inside the swapped region, next to this
  branch's form and status line.
- family_row.html, sample_row.html: #244 made the modal lookups
  null-safe with ?.; the delegated listener here already covers a page
  without the modal, and also a modal a search brings in, so it stays.
- testSubmitMetadata.py: master's fix from #297, in place of the port.
#119 replaced "No functions available" and "No samples available" with
messages per page; the region test now expects those. #136 marks the
search term in the rows; a new browser test types into the sample list
and checks that the rows swapped in carry the marks.
No conflicts. #174's search adapter now runs the sample page's function
search; the query it is given is still built by sample_function_query(),
so a bare hex number reaches the backend as offset:<term>.
@danielplohmann
danielplohmann merged commit 16364ca into master Oct 29, 2026
8 checks passed
danielplohmann added a commit that referenced this pull request Oct 29, 2026
r0ny123 added a commit that referenced this pull request Oct 29, 2026
The tests that came with #253, #254, #293, #303 and #305 put only user_id in the session, which this branch ends on the next request, so the pages they opened were the login page. They sign in with log_in_as and session_cookie_for.
r0ny123 added a commit that referenced this pull request Oct 29, 2026
#293 loads live_search.js with a plain script tag on the four listing
pages, so it was fetched before the first paint, which this branch moves
every page script past (ADR-0021). It is queued with later() now. The
search box has autofocus, so a term can be typed before the queue has
run: the script takes the term the page was rendered for as the one on
screen and searches what the box holds by the time it runs.
r0ny123 added a commit that referenced this pull request Oct 30, 2026
Master's #293 loads live_search.js with a plain script tag on the four
listing pages, so it was fetched before the first paint, which this
branch moves every page script past (ADR-0021). It is queued with later()
now. The search box has autofocus, so a term can be typed before the
queue has run: the script takes the term the page was rendered for as the
one on screen and searches what the box holds by the time it runs.
r0ny123 pushed a commit to r0ny123/mcritweb that referenced this pull request Oct 30, 2026
Bumps setup.py and adds the version history entry, folding in the five
"unreleased" lines (familiary#263, familiary#262, familiary#261, familiary#293, familiary#254).

48 PRs since 1.6.0: batches C1 (familiary#298), C2 (familiary#299), security E (familiary#318),
UI F (familiary#339) and fixes G (familiary#340). No dependency changes.

The entry leads with the three things that affect existing deployments:
instance/ backups under WAL mode, the bounded result cache, and the
optional retirement of pre-1.5.0 API tokens.

Test count measured on the batch G tree, which master 30cbc8a is
identical to: 2428 passed, 19 skipped against mcrit 1.16.0, 2447
collected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HERmVhHo4ibp7HSTXr3Ya8
@r0ny123
r0ny123 deleted the feat/sample-search-as-you-type branch October 30, 2026 06:04
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.

2 participants