Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
ivy--regex-ignore-order matches too many results #296
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
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.
* 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