Order by relevance during keyword search

Order by relevance during keyword search

tardigradtardigrad Posts: 9Questions: 4Answers: 0
edited May 2015 in Free community support

Hello,

I very much like the search feature of datatables, it's an amazingly usefull tool.
However I was wondering if it was possible to order the search results by "relevance" during the typing of keywords. (instead of the order which was previously selected)
By relevance I mean a little bit like in Sublime Text : when you search for something, the first results are those that match best the typed keywords.

e.g. when I type "xxxx yyyy", a record containing "xxxx yyyy" in the same property would be better above another having "xxxx" in one property and "yyyy" in another.
e.g. when I type "zzzzzzz" and one record contains in one property, exactly and nothing more than "zzzzzzz" this record would be better on top.

I imagine a relevance index should be computed at each keystroke to achive this.

Thanks for your input on this matter !

Answers

  • allanallan Posts: 61,798Questions: 1Answers: 10,115 Site admin
    edited May 2015

    What you would have to do, as you say is compute the relevance on each search input and then enter that value into a column for that row. The table would be sorted on that column, thus giving the relevance ordering.

    The key thing would be devising (or using an existing) relevance algorithm to get the relevance value.

    Interested to hear if you look into this further - sounds like a fun thing to do!

    Allan

  • tardigradtardigrad Posts: 9Questions: 4Answers: 0
    1 Find the algorithm  
    2 for each record, at each keystroke:  
        A compute the relevance index ;  
        B write it in a column ;  
        C sort on that column ;  
    3 make that variable invisible  
    4 change the sort on that variable when you begin to type  
    5 revert the sort on the originally sorted variable when you empty the search field.  
    

    This is may be a little too difficult for me.
    But I'm sure this would be a very nice feature to add to the core of datatables.

  • allanallan Posts: 61,798Questions: 1Answers: 10,115 Site admin

    It won't be added to DataTables core (far too much code weight) but it sounds like a fun thing for a plug-in.

    Allan

This discussion has been closed.