最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript client-side search engine - Stack Overflow

programmeradmin0浏览0评论

I am developing a local web application with jQuery/JavaScript.

My goal is to create search engine for searching content from a JSON file. I already made it with regex, but it works slowly.

What is the best way? Is there a JavaScript search engine?

I am developing a local web application with jQuery/JavaScript.

My goal is to create search engine for searching content from a JSON file. I already made it with regex, but it works slowly.

What is the best way? Is there a JavaScript search engine?

Share Improve this question edited Oct 30, 2012 at 11:33 Quentin 944k132 gold badges1.3k silver badges1.4k bronze badges asked Oct 30, 2012 at 11:25 user1785360user1785360 4
  • 3 Is it a search engine or search option? – polin Commented Oct 30, 2012 at 11:26
  • I have html text field, when I enter a text and push "search" button, my search engine (or programme javascript, or search option) must find all occurrence in my JSON – user1785360 Commented Oct 30, 2012 at 11:30
  • 1 I'm sorry, but FTW?? you're going to use user input to generate a RegExp object (escaping any special chars, I hope) to process data that is JSON formatted? It could be me, but since JSON stands for JavScript Object Notation, I'm inclined to say that RegExp isn't the right tool for the job... in any case, you say you've already made it: show us how far you've come: post some code, or set up a fiddle – Elias Van Ootegem Commented Oct 30, 2012 at 11:36
  • yes, because I haven't another solution. the principe of algo must bee similar that Google Search – user1785360 Commented Oct 30, 2012 at 13:07
Add a comment  | 

7 Answers 7

Reset to default 6

Try lunr.js which supports full-text search in JavaScript.

Fuse.js is a lightweight fuzzy-search, in JavaScript, with zero dependencies. It has more github stars than Lunr, and has ongoing (and recent) commits as of August 2022.

The term "search engine" normally means that a large set of data is indexed (a resource intensive task). Searching the data set after indexing is then quick. If the data set is very large, it is more likely that indexing and search will be performed on the server (and only the search results are then returned to the browser).

If you just need to search fields in a JSON file that is small or medium in size, then consider JavaScript "search algorithms" rather than search engines.

I think it doesn't exist, you have developpe it

put your application contents in String object and developpe search function with indexOf (for target string) & substring (to extract fragment)

Have a look at fullproof, it's a basic search engine for use int he browser http://reyesr.github.com/fullproof/ There may be others though.

I think you have two options. Lunr that is mentioned earlier and search-index.

Elasticlunr is a lightweight full-text search engine in Javascript for browser search and offline search. Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js.

Elasticlunr.js provides Query-Time boosting and field search. Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration and query-time boosting.

发布评论

评论列表(0)

  1. 暂无评论