Yegappan wrote: 

> On Sun, Sep 13, 2020 at 3:44 AM Bram Moolenaar <b...@moolenaar.net> wrote:
> 
> >
> > > >> On Sat, Sep 12, 2020 at 1:09 PM Prabir Shrestha <
> > > >> vim-dev-git...@256bit.org> wrote:
> > > >>
> > > >>> +1 for adding fuzzy match.
> > > >>>
> > > >>> A bit late to this. But few questions.
> > > >>>
> > > >>> How do we use matchfuzzy for a list of dictionary instead of item.
> > > >>> Primary reason for this is LSP (language server protocol) makes
> > heavy use
> > > >>> of user_data. Can you add an example for sorting a list whose type
> > is dict [
> > > >>> { 'word': 'foo', user_data: 1}, { 'word': 'foobar', user_data: 2}, {
> > > >>> 'word': 'bar', user_data: 3} ]. Should we have a 3rd optional
> > parameter
> > > >>> that takes a callback?
> > > >>>
> > > >>> let completeitems = [
> > > >>>  \ { 'word': 'foo', user_data: 1},
> > > >>>  \ { 'word': 'foobar', user_data: 2},
> > > >>>  \ { 'word': 'bar', user_data: 3}
> > > >>>  \ ]
> > > >>> let filtertedlist = matchfuzzy(completeitems, 'foo',
> > {item->item['word']})
> > > >>>
> > > >>>
> > > >> That is a good idea. We can add a callback argument that will be
> > called
> > > >> for each item
> > > >> if the list item is dictionary.
> > > >>
> > > >
> > > > You can try the attached diff which implements the above and see how
> > this
> > > > works with a
> > > > very large list of dictionaries.
> > > >
> > > >
> > > I used the below functions to measure the time it takes to fuzzy search a
> > > million entries
> > > in a List and a Dict:
> > >
> > >
> > > For a list, it took around a second to search all the entries and for a
> > > dict,
> > > it took around 5.5 seconds.
> >
> > A list is always going to be more efficient than a dict.  It uses less
> > memory and doesn't require hashing for the lookup.
> >
> > Also, when using a dict the key will be the same and rather meaningless?
> 
> The key is used to lookup the value in the dict which will be used for fuzzy
> matching. So the value will be different for each list item.
> 
> > I can only imagine this being useful if you already have a list of
> > dicts.  How often does that happen?
> >
> For example, the getbufinfo(), gettagstack(), readdirex(), getqflist(),
> getloclist(),
> getmatches() and getwininfo() functions return a list of Dicts.
> 
> Without the support for fuzzy searching list of Dicts, the user needs
> to first convert it to a List (while still retaining the rest of the
> information
> in the Dict) and then search.
> 
> For example, to fuzzy search 'eval' in a list of buffers returned by
> getbufinfo():
> 
> With the support for fuzzy searching a list of Dicts using a 'key':
> 
>      echo getbufinfo()->matchfuzzy('eval', 'name')
> 
> Generating a list of buffer names and then search (but the other
> buffer related information is not kept):
> 
>     echo getbufinfo()->map({_, v -> v.name})->matchfuzzy('quickfix.c')
> 
> Generating a list of lists with two elements and then searching using
> the first element:
> 
>     echo getbufinfo()->map({_, v -> [v.name, v]})->matchfuzzy('quickfix')
> 
> The first approach is more natural. In the last approach, the user needs
> to generate a temporary list of lists for fuzzy search.

All makes sense.  If you already have a list of dicts and there aren't
too many entries, the conversion to a list of lists is cumbersome.

Only when you do have a lot of entries (e.g. all files in a directory
tree, with size and date as secondary info) and speed is crucial then
the list of lists may be desired.

The callback is the most flexible and most likely also the slowest.

I suspect it's actually not that complicated to support all of these.
Wen can make the third argument a dict, like we often do for functions
with various options.

-- 
What do you get when you cross a joke with a rehtorical question?

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202009131955.08DJtKMI1452830%40masaka.moolenaar.net.

Raspunde prin e-mail lui