lunr.js | A bit like Solr , but much smaller and not as bright | Search Engine library
kandi X-RAY | lunr.js Summary
kandi X-RAY | lunr.js Summary
Lunr.js is a small, full-text search library for use in the browser. It indexes JSON documents and provides a simple search interface for retrieving documents that best match text queries.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lunr.js
lunr.js Key Features
lunr.js Examples and Code Snippets
Community Discussions
Trending Discussions on lunr.js
QUESTION
I need a client-side fulltext search for big offline website. The site is opened by browser. I've made a research and found some solutions - fullproof, fuse.js, flexsearch.js, elasticlunr.js. I searched for js libs, because as i inderstand, it's the single solution (please correct me if i'm wrong).
Also i can't clearly understand some moments:
- As i know, browsers due to security policy block all scripts' execution from javascripts files. I couldn't run examples from fullproof git because of this problem, but i managed to run flexsearch example, because script execution was included in html code with tag. Can i implement some search system for my local website because i don't use any local server for hosting (like xampp)?
- From documentation for different js libs i undestand, that all they use for indexing either variable with list of key words or json file. Maybe i have a luck of information, but how i can use search system to find words/expressions from the whole website (it has a main page and a lot of included pages with information)? Do i have to create some sort of database or some json file?
I'll be very grateful for your answers, explanations, solutions or maybe examples about this problem, thank you!
...ANSWER
Answered 2020-Dec-26 at 14:13Firts of all, browsers doesn't block js scripts execution. Secondly, i managed to find two ways to solve my problem - keywords search and fulltext search: 1) I created a database with keywords (json file) and used flexsearch library to search in this database. Example of usage u can find on their website, either an example of json file. 2) This time i created a database (json file), in which one recording is a text content of a website. Then again i used flexsearch to find a word in this database. After appropriate site was found, it opened up and the searched word was highlighted (u can find such js libraries in net). All the solutions don't require any internet connection and can be used for offline websites.
QUESTION
I'm making a Hybrid app using cordova and currently when users use the search function a list of clickable search results return with the users search query highlighted in each result. The problem is when a user clicks on a result and it brings them to the exact location of the search query in the said book, I can not figure out how to run my highlight function to hightlight search query on the newly loaded page? New to Javascript here and I Hope I am clear on what I am trying to say. Here is a screen recording of the problem https://osaintilien55-gmail.tinytake.com/tt/NDU0MzA5OF8xNDQwMDE2Ng. I am using Lunr.js for search functionality and Mark.js for highlighting.
Here is the search function in my code
...ANSWER
Answered 2020-Aug-16 at 21:11You could use query strings. For example, the parameters of a function are stored in a query string called params
.
You could read the query string. Then use JSON.parse()
on the query string. Then run the function with the parsed array using the ES6 spread operator (...
).
Example:
QUESTION
I'm having a bit of trouble trying to display the search result in a new page titled results.html
using this guide here.
It seems as though its setup to display results on the page where the search is being made which isn't what I'm looking for.
What I'm trying to do is have a search box in index.html
, which opens a new page after pressing a button that contains search results.
Currently any search that is made on any page, just shows the results there.
_includes/search-lunr.html
ANSWER
Answered 2020-Apr-22 at 04:57If you want the search results only on a separate page, you'll want the search form to have an action that points to it. The term will be passed to that page, which can then process it and display the search results.
This template demonstrates this exact flow:
- Repo: https://github.com/CloudCannon/edition-jekyll-template
- Live demo: https://long-pig.cloudvent.net/
It's a pretty good solution since your site viewers only have to load and run that code if they perform a search, which can be a substantial saving with a reasonably sized index.
To replicate it roughly with your code above:
Remove
{% include search-lunr.html %}
from yourindex.html
.Have this on
index.html
:
QUESTION
I am using lunr.js.
This Javascript code below
- gets the query parameters from the first search
- replaces the binding + characters with spaces
- stores the modified query in the search field for the next search
- Then it finally searches using the modified query
ANSWER
Answered 2020-Mar-16 at 17:24You need a negative lookbehind query (?
QUESTION
So I am using lunr.js in my Jekyll application to implement a search feature and the results return correctly. The aim is to then display the list of results in the browser.
Here I get the results, then pass them to a func which handles the DOM manipulation.
...ANSWER
Answered 2020-Feb-18 at 23:05You can use Object.values()
to access only the values of the object. Example:
QUESTION
I'm trying to build a simple search interface for a dataset that I have created.
I have followed the Lunr guides to create an index. I put an input box on my webpage that gets the search value typed by the user, then runs that value against the index.
When I run console.log(results[0])
- I happily get the right result in my console:
The problem comes when I try to get "legal and legislation compliance" to show up on my webpage. Two things happen:
When I try to output console.log(results[0].ref)
to the console, the program freezes and I can't type anymore.
When I try to output document.getElementById("demo").innerHTML= results[0]
to the webpage I get [object object] - which is surprising because the console line gives the actual data associated to the object.
ANSWER
Answered 2019-Jul-23 at 12:35You should use a value for innerHTML
. Here results[0]
is a object. So this should be document.getElementById("demo").innerHTML = results[0].ref
QUESTION
Background:
My web project with following bower.json
was successfully compiled 4 months back with no modifications till date using gitlab ci pipeline (there is no change in code since then). Today, when i re-executed pipeline, bower started throwing ENOTFOUND errors as mentioned later in this question.
Errors in various run are ENOTFOUND Package mkdirp not found
or ENOTFOUND Package minimist not found
. How to rectify or trace source of this error maybe in terms of 3rd party package problems considering no change in bower.json and source code and also log file does not mention from which 3rd party mkdirp or minimist
is demanded. As such, This is wired as Why would bower remove pre-existing packages from repository.
bower.json snippet
...ANSWER
Answered 2017-Nov-29 at 14:58Gave up with random ENOTFOUND Package * not found
errors for very long and display of package names even am not aware of or searchable in google like package ENOTFOUND Package which not found
.
Thereafter came across this article which referred to Yarn as better replacement to NPM and Bower. Thus i've used stackoverflow article to migrate my project from npm/bower to yarn and errors are gone.
Code used for same after installation of yarn is: (it needs previous copy of bower_components folder to exist with node_modules)
QUESTION
I have a set of documents, each annotated with a set of tags, which may contain spaces. The user supplies a set of possibly misspelled tags and I wants to find the documents with the highest number of matching tags (optionally weighted).
There are several thousand documents and tags but at most 100 tags per document.
I am looking on a lightweight and performant solution where the search should be fully on the client side using JavaScript but some preprocessing of the index with node.js is possible.
My idea is to create an inverse index of tags to documents using a multiset, and a fuzzy index that that finds the correct spelling of a misspelled tag, which are created in a preprocessing step in node.js and serialized as JSON files. In the search step, I want to consult for each item of the query set first the fuzzy index to get the most likely correct tag, and, if one exists to consult the inverse index and add the result set to a bag (numbered set). After doing this for all input tags, the contents of the bag, sorted in descending order, should provide the best matching documents.
My Questions
- This seems like a common problem, is there already an implementation for it that I can reuse? I looked at lunr.js and fuse.js but they seem to have a different focus.
- Is this a sensible approach to the problem? Do you see any obvious improvements?
- Is it better to keep the fuzzy step separate from the inverted index or is there a way to combine them?
ANSWER
Answered 2017-Oct-12 at 20:42You should be able to achieve what you want using Lunr, here is a simplified example (and a jsfiddle):
QUESTION
I'm currently working on a project to implement a full-text search client-side in JavaScript based on lunr.js.
The thing is, I'm struggling in building then saving the index because I have several asynchronous calls.
...ANSWER
Answered 2017-Jul-28 at 14:12There are four problems:
- Your function
buildIndex
does notreturn
the promise, so one cannot wait for the result when calling it - When encountering a directory, you call
buildIndex
recursively but don't try to wait for its result like you did withpromesse
in the else case. - You have the
promesses.push(promesse);
call inside the asynchronous callback that executes only after the file was read in. The idea of putting the promise in the array is right, but you must do it immediately so that it happens beforePromise.all
is called upon the array. - You for some reason removed
Promise.all
from the code.
Basically the function should have this general schema:
QUESTION
I used elasticlunr.js search engine.
I edited their example source code
...ANSWER
Answered 2017-Feb-14 at 09:07The input
tag exists in between the form
tag. This implies that upon pressing enter the form is submitted and therefore the page reloads thus removing any information you placed and showing the unadulterated results .
In the example provided by the developer, $('input').bind('keyup', debounce(function () {
is used. Therefore, upon entering text the tags are searched. However, in your case, the control doesn't even shift to code that you are intending to run.
Please check this https://jsfiddle.net/kaminasw/rqj68xt5/ where it should show alert upon pressing enter in the input.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lunr.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page