New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ivy--regex-ignore-order matches too many results #296
Comments
I tried generating such big regexp to test emacs behavior. You can generate them with the following python snippet:
With only 5 elements (a to e), there is no problem in a small buffer. With 6 elements, emacs complains that the regexp is too big... |
This implies 24 times slower matching. Considering that e.g. I added |
I already have it since I contribute to org-mode :-). I think that indeed it is too slow. Did you know ivy--regex-ignore-order had the behavior I describe? |
No. But it's not too bad: choosing |
You are right. Nonetheless, I have the feeling that you get more candidate than you expect when you use the function. I propose to add a comment in the documentation string to indicate its behavior. |
* ivy.el (ivy--regex-ignore-order): Return a list of regexps rather than a single regexp. (ivy--re-filter): New defun, extracted from `ivy--filter'. (ivy--filter): Update. (ivy--format-minibuffer-line): Add special highlighting for `ivy--regex-ignore-order'. * counsel.el (counsel--find-file-matcher): Use `ivy--re-filter'. Fixes #296 Fixes #329
AFAICU, the function ivy--regex-ignore-order should match the elements of the search in any order, but still make sure that ALL the elements are in the candidates
In practice, it matches candidates that contain as many elements as in the query, but not necessarily that match ALL the elements of the query one.
As an example, say you run
then search for "foo bar". I would expect it to match only two candidates: "foo bar" and "bar foo".
Instead, the four candidates are matched.
This is understandable, because the generated regexp is
I think that we would need to transposing the logic to match all possibilities of order, resulting in a query more like:
The problem with this proposal is that the regexp grows exponentially with the number of elements (more precisely, n elements need n! groups) to match. For instance "foo bar egg" would result in 6 groups:
IIRC my language theory lectures, there is no other way to perform such match as ignore order with regexp since by definition they don't have a memory of the matched results. I don't know if it is still true with extended regexp.
We can take a look at the number of groups needed for few elements:
IMHO, we can assume that people barely use more than 5 elements in such a query
The text was updated successfully, but these errors were encountered: