Search-Problems: select search-fields, priority for matching words

Search-Problems: select search-fields, priority for matching words

mbaasmbaas Posts: 67Questions: 24Answers: 1

As part of a larger project I am using DT to display a list of various HTML-Examples with their descriptions. And I'd like the list to be searchable.

Now, there is a problem when users search for tags such as a/i/b as well as br/ol etc., since entering a will match nearly everything, "ol" also matchs "control", "old" etc., so a lot of irrelevant stuff is being shown.
Currently discussing two ideas with the other devs (I'm the only one with DT-experience):
1. dropdowns to select search-fields (name of control, description, everything)
2. prioritize elements that match completely over partial matches (I guess this will also require to fiddle with the sorting...)

I was surprised to see that not many search-plugins are available in general and also these two features were not addressed. So I wonder if the ideas are "too far out" or perhaps even impossible (have I overlooked anything?). Or maybe (hopyfully) they are too trivial? I'd be happy for any comments/suggestions/code you may have :-)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Thanks for posting this. Funnily enough I was thinking about this "issue" on the way in this morning. The search is currently designed to match anywhere in a string, but the next major version is going to change that so it will search at the start of a word only.

    There are two options, to do this at the moment:

    • Hack DataTables core to change its smart search to work that way
    • Use search() with a regex filter that does what you are looking for.

    The third option is to wait for me to commit the required change to a branch of DataTables core (although not sure when that will be yet...)!

    Allan

This discussion has been closed.