jQuery的排序JSON数组按相关性基于搜索词 [英] Jquery Sort JSON array by relevance based on a search term
问题描述
我有一些搜索结果而要显示在一个jQuery数据表的阵列。我需要我得到了基于搜索项的行进行排序。我的意思是与搜索词最匹配的行应该在显示搜索结果的顶部。例如,如果我的搜索词是世界您好,我的数据如下。
I have an array with some search results which are to be displayed in a jQuery datatable. I need to sort the rows I got based on the search term. I mean the most matched rows with the search term should be on top of the search results displayed. For example, if my search term is 'Hello World and my data is as follows.
Hello 560 World
Hello Business World Guy
World of Hello
Hello World
100 Hello World's
World Hello Business
排序后,我需要得到有点像
After sorting, I need to get the sort the array like
Hello World
100 Hello World's
Hello 560 World
Hello Business World Guy
World of Hello
World Hello Business
是否有任何的JavaScript / jQuery的功能做到这一点?我只需要在一开始获得最匹配的行重排阵。
Is there any JavaScript / jQuery function to do this? I just need to get the rearranged array with the most matched rows at the beginning.
推荐答案
这听起来像你想的模糊字符串匹配。查看fuzzyset.js一个JavaScript解决方案。
It sounds like you want fuzzy string matching. Check out fuzzyset.js for a javascript solution.
http://glench.github.io/fuzzyset.js
这篇关于jQuery的排序JSON数组按相关性基于搜索词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!