Closed jlegewie closed 11 years ago
As far as I can tell, this looks terrific. Though some of it is Greek to me, I'll take it on your word. Thank you so much; this is a fantastic contribution, and something that, after my failure, I thought we'd be stuck without. I'll update the docs as well to reflect your changes.
Hi,
so here is my shot at fuzzy search. I hope I don`t embarrass myself... :)
The idea is similar to what you know from the quick panel in ST. Here is an example: The queries
nor20
,n2013
,NordAmid
, andnorld3frs
all match the stringNordland 2013 - Amid Fears of Releases
. There are three criteria for a match:Matches are ranked based on two criteria:
nor
,nor
is better thennxoxr
)nor
,xnor
is better thenxxnor
)The import function is
fuzzy_search
, which takes two required and three optional arguments.query
: search stringkey
: function to access string element in dictionaries, tulpes, or listsrank
: rank the elements in the return list by quality of match (currently not supported)seq
: minimum sequence of characters to matchfuzzy_search
returns a ranked list of elements that matches the query.key
has to be specified ifelements
is not a list of strings andkey(elements[i])
has to return a string for every element in the listelements
.I am sure this can be optimized performance wise but it's pretty fast in my tests with a list of over 2000 elements and
seq=3
. There is also an small example at the bottom of the code (commented out). By they way you can also use this to directly filter a list of feedback dictionaries withkey = lambda x: '%s - %s' % (x['title'], x['subtitle']
(in this case the search would be based on a string 'title - subtitle')Another thing is that you have to feedback a random uid to preserve the ranking. I think it would be great to add an option
random
toalp.feedback
, which assigns uses a random uid and set this option toFalse
by default. Here are details about this.Let me know if you have questions!