用于搜索引擎样式搜索的JavaScript库? [英] JavaScript library for search engine style searching?

查看:87
本文介绍了用于搜索引擎样式搜索的JavaScript库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个JavaScript库可以确定字符串是否与搜索查询匹配?它应该是高效的,并提供类似Google或LexisNexis的高级查询功能(诸如和/或运算符,同义词和括号之类的东西)。任何类型的高级搜索功能都会很棒;它不必与任何特定的搜索引擎完全匹配。

Is there a JavaScript library that can determine if a string matches a search query? It should be efficient and provide advanced query functionality like that of Google or LexisNexis (things like and/or operators, synonyms, and parentheses). Any kind of advanced search features would be great; it doesn't have to be an exact match to any particular search engine.

动机:我有一个带有搜索框的HTML页面,后跟一堆段落(其中具有唯一ID并从JavaScript数组生成)。当用户在框中键入搜索查询并按Enter键时,所有段落都应隐藏(即他们的显示设置为)如果它们与查询不匹配。

Motivation: I have an HTML page with a search box followed by a bunch of paragraphs (which have unique ids and are generated from a JavaScript array). When the user types a search query in the box and presses enter, all paragraphs should be hidden (i.e. their display set to none) if they don't match the query.

我当前的策略(使用jQuery):

My current strategy (using jQuery):


  1. 通过将查询字符串拆分为空格来将查询字符串分隔为关键字数组。

  2. 使用 $('p')隐藏所有段落。 hide()

  3. 对于每个关键字,使用 $('p:contains('+ + keyword +')显示包含它的段落)')。show()

  1. Separate the query string into an array of keywords by splitting it over whitespace.
  2. Hide all paragraphs with $('p').hide().
  3. For each keyword, show a paragraph containing it with $('p:contains("'+keyword+'")').show().

这是一个非常有限的搜索功能,例如 - 敏感,将所有关键字视为可选,并且不提供或括号等运算符。这也是低效的,因为即使它已经匹配,它也会为每个关键字遍历每个字符串一次。

Which is an extremely limited search feature that is case-sensitive, treats all keywords as optional, and doesn't provide operators like and, or, or parentheses. It's also inefficient because it goes through each string once for each keyword even if it has already been matched.

推荐答案

这里有一些库我正在评估项目(2013年7月)。其中任何一个都应该能够提供搜索功能的核心。

Here are some libraries that I am evaluating for projects (in July 2013). Any of these should be able to provide the core of the search feature.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆