mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
Search now scores documents without allocations and builds highlights only for the documents it returns. - `PreparedQuery` lowercases each field into a reusable `QueryScratch` buffer. ASCII text uses ASCII lowercase and skips UTF-16 tables. Other text uses `str::to_lowercase()`, and maps lowercase bytes to source UTF-16 ranges only when the field contains the query. - `score_with_scratch` returns the field score without highlight spans. `match_utf16_with_scratch` returns the same result as `match_utf16`. - With a limit, `WeightedSearchEngine::search_refs` keeps the best documents in a bounded heap. Then it builds hits for those documents only. Ties resolve as in a stable full sort. - With no limit, search matches each document once and sorts the hits. On 4,096 documents with 2,048-byte bodies and a limit of 20, a query that matches every document allocates 0.04 MB instead of 188 MB.