Terms based entities search#10991
Conversation
|
How will this affect the performance? Some users have a huge amount of entities and therefore a very long list to be filtered. |
|
Well, Regex matching is really fast, and I took care to compile the regex only once per search in order to minimize overhead. I use the same exact code in professional apps I develop and honestly it feels instantaneous. I made a benchmark locally, and searching across 1000 entities took 10ms. Edit Actually, my benchmark was with 4000 entities for 10ms search time :-) |
|
Should we use the Sequence matching instead that is implemented in the Quick Bar? |
Hi @zsarnett, The behavior is not really the same, what I propose here is more permissive (except it does no fuzzy matching) and is totally different in it's usage. The quick bar uses the FuzzyFilterSort, seems sensitive to words order and does not play well with multiple terms separated with spaces from my experience. I wanted exact partial matching for all the search terms, in any order. Maybe I don't get it, but I almost never find what I want when using the quick bar :-( As soon as I don't enter search terms in the right order, quick bar does not find what I am looking for. If you look at the example screenshot I provided in the description, fuzzy match does not return any result. Same for the unit tests I provided, fuzzy search does not match most of the time. |
|
Try reversing you input (3 p), I think it does not work anymore. That seems inconsistant to me. I understand we don't want to introduce too many different search mecanisms. I Just wanted to introduce a simple improvement for all basic search inputs, because currently the simple "contains" approach is really frustrating. |
|
@zsarnett BTW : Congrats for your new position at Nabu Casa ! Exciting news :-) |
|
The quick bar and entity picker should use the same search logic. |
Agreed, but which one ? Have anyone tried to use the one I propose ? Let me know, I'm willing to adapt the proposal to your feedbacks. Using the current entity picker is a pain, just want to improve it in any way. |
|
Definitely open to better logic for the quick bar and entity search. |
|
Would love to have the Quickbar logic implemented into the entities search. Is that still something you want to tackle? |
|
Hi, So you basically just want to apply the current quick bar matching function to the entity search ? No room for improvements here ? I honestly don't understand how quick bar matching function is supposed to work, from a user perspective but also from a developer perspective after reading it's code and associated unit tests frontend/test/common/string/sequence_matching.test.ts Lines 25 to 45 in 03677c3 But anyway, yes, based on this PR, changing the matching function is a one-liner (just have to change the implementation for termsSearchFunction) |
We are open to better logic but the quick bar logic and the entity logic should be the same logic |
|
OK. I will first adapt this PR to use the same logic for both and mutualize as much code as possible, then we'll see what can be done to get an improved search logic. |
1f4128f to
cfdd4ff
Compare
|
Hi @zsarnett I just pushed an update including some intermediary work on this, in order to be able to test and evaluate different matching logic. I refactored quick bar and entity picker in order to use the same search function. It can be switched by just reassigning the There are currently 3 implementations available :
The good part here is that other matching algorithms can be easily tested. Let me know what you think about this work in progress and how you think we can move on from here. |
|
Let's go ahead and remove the old logic and the Fuzzball logic for the new Regex Logic. I think the REGEX is definitely more difficult to maintain though... Fuzzball is a large package so I would rather not use that. |
|
The thing that is missing in the regex approach is that there is no scoring. I hadn't that in mind when I implemented it first because I was just trying to replace entities filtering, not the quick bar. |
|
I looked at the history of the current fuzzy matching feature : #7367 I have a version of the search functionnality that combine the old behavior, using the fuzzysort library, and with a few tweaks it also supports all the test cases I added for my initial Regex proposition. |
|
Yea I think that would be great. Not having to maintain that logic would be nice. |
|
I just finished cleaning everything, seems ok for me. |
|
Another interesting feature for future use : fuzzysort provide the location of the matches => It would be possible to use it for end users |
|
Nice. Ill take a look soon! |
| const sortableEntityStates = this._states.map((entityState) => ({ | ||
| strings: [entityState.entity_id, computeStateName(entityState)], | ||
| entityState: entityState, | ||
| })); |
There was a problem hiding this comment.
This seems expensive to do each time. Can we store this? Possibly memoize?
There was a problem hiding this comment.
Can you fix this in a new PR?
There was a problem hiding this comment.
Ok, I'll have a look at this



Proposed change
The entity picker component currently just look for searched entities using simple contains comparison. It is sometimes hard to find the entity you are looking for because you have to remember the exact order if the words used in the entity id or friendly name.
This PR introduce flexible terms based search for entities ids and name in the entity picker component.
For exemple, given the following entities :
Currently, if you want to match the last one, you have to search for 'kitchen_h' at minimum in order to refine your search to the desired input.
With the proposed change, you just have to type 'k hu' for instance, in any order. Thats much more flexible does not require user to remember the exact order and full naming of its entities.
You can find many more usage samples in the included tests.
The code for matching regexp and search function is isolated from the entity picker component. I also applyied it to the worker in charge of filtering data tables. If it seems ok, I could easily extend this behavior to various other search boxes (devices/services/integrations/automations...)
Here is a screenshot of this search in action :

Type of change
Example configuration
No extra configuration required
Additional information
None
Checklist
If user exposed functionality or configuration variables are added/changed: