Skip to content

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

Open
matthias-stemmler wants to merge 1 commit into
korpling:mainfrom
matthias-stemmler:feature/find-extra-with-alternative
Open

Add CorpusStorage::find_extra returning the query alternative for each match#342
matthias-stemmler wants to merge 1 commit 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.

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

1 participant