Skip to content

Add CorpusStorage::find_extra returning the query alternative for each match - #342

Merged
thomaskrause merged 3 commits into
korpling:mainfrom
matthias-stemmler:feature/find-extra-with-alternative
Aug 11, 2026
Merged

Add CorpusStorage::find_extra returning the query alternative for each match#342
thomaskrause merged 3 commits into
korpling:mainfrom
matthias-stemmler:feature/find-extra-with-alternative

Conversation

@matthias-stemmler

Copy link
Copy Markdown
Contributor

This adds a CorpusStorage::find_extra method that returns for each match which query alternative produced it. In case multiple alternatives produce the same match, it gets attributed to the first alternative.

The new method has the same signature as CorpusStorage::find, except that it returns a Vec<MatchExtra> instead of a Vec<String>. The MatchExtra struct is marked #[non_exhaustive] so that adding more fields later isn't a breaking change. The names find_extra and MatchExtra follow the convention established for count_extra and CountExtra.

Performance: the alternative index is a plain usize carried alongside the numeric match group, so it stays out of the sort key and the uniqueness check, and match IDs are still resolved to strings at the end. I did extract the common parts of find and find_extra: The added cost for find is that usize per match in the temporary BTree index plus one iterator indirection; it showed no measurable effect on the GUM test corpus.

I didn't extend the FFI surface for now.

Closes #341.

@thomaskrause thomaskrause self-assigned this Aug 6, 2026
The current benchmarks suggest there is a about 6% worse performance for find()
queries and these benchmarks for find_extra() allow to compare the two methods
and isolate the source of the increased workload.

Since find_extra() and find() have roughly the same execution time, the source
could be the added usize added as value (which increases the memory stored in the
temporary BTreeMap) or some issue with refactoring out some of the work to
closures or sub-functions which might not be inlined.

@thomaskrause thomaskrause left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I had some questions about storing the alternatives as vectors, because I assumed that they always would be just using the index as value which was not the case so I deleted the comments.

I also added some benchmarks to compare find() with find_extra() and it seems the overhead is marginal. Also, benchmarking in comparision with the main branch did not find any difference outside what I would consider noise (in the first benchmark run I forgot to disable dynamic CPU throttling and got quite some noise, but this improved after running the benchmark correctly.

Comment thread graphannis/src/annis/db/corpusstorage/tests.rs
@thomaskrause
thomaskrause merged commit e405812 into korpling:main Aug 11, 2026
9 of 10 checks passed
@matthias-stemmler
matthias-stemmler deleted the feature/find-extra-with-alternative branch September 2, 2026 18:40
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.

Feature Request: Include alternative in query result

2 participants