Reputation: 353
I'm trying to implement a search bar for my website that uses Firebase as its database. It's a bunch of links to certain images and embed videos. I'm thinking is it best to have a "tag" field for each link, that the lunr library would query for? I'd split each tag field into an array of strings and the lunr would look for each one?
My database has the JSON format of:
{ "Featured" : {
"Link1" : {
"isEmbed" : false,
"priority" : 4,
"url" : "https://s3.amazonaws.com/hagshs8282n23/image7.jpg",
"tag" : nba nfl nhl mlb yahoo
},
"Link2" : {
"isEmbed" : false,
"priority" : 3,
"url" : "https://s3.amazonaws.com/hagshs8282n23/image6.jpg",
"tag" : fire base stuff art cool
} }
Is this a slow way to go about searching for objects or is there a better way to think about it?
Alternatively, I was thinking that whenever a file is added to the database, I would export that new JSON structure to a folder in the home directory of the website (/dir/ or something like that) and then have lunr read from that instead of Firebase. Would that be quicker since the files would be local and not in Firebase or would it not make a difference?
Upvotes: 0
Views: 397
Reputation: 1835
If you want/need full text search then lunr could certainly be used for providing an index on the tags in those documents.
If these links had a description, then lunr (or any other full text search) would be a good fit, you really are then doing a full text search.
Tags, to me anyway, imply a faceted search. I would imagine that you would have a finite list of these tags, and you would then want to find which links have these exact tags. You could approximate something similar with lunr, but there are probably better tools for the job.
Now, if you had a large list of tags, potentially with some kind of description, then you could use lunr to allow users to search for tags, and then use those tags to perform the faceted search on your links.
As for using lunr with firebase, as long as lunr has access to all of the link data for indexing, it doesn't care where you actually store the documents. I'm not at all familiar with firebase so can't comment on the practicality of integrating lunr with that service, perhaps someone else can help you out with that aspect.
Upvotes: 2