shape-image
Today we will take this data 👇
[{
  title: "The Creator",
  text: `The Creator is a 2023 American science fiction action film produced and directed by Gareth Edwards, who co-wrote the screenplay with Chris Weitz. It stars John David Washington, Gemma Chan, Ken Watanabe, Sturgill Simpson and Allison Janney. Set in 2070, 15 years after a nuclear detonation in Los Angeles and a war against artificial intelligence, an ex-special forces agent is recruited to hunt down and kill the \"Creator,\" who has developed a mysterious weapon with the power to end the war.`,
},
{
  title: "Kill Bill",
  text: `Kill Bill: Volume 1 is a 2003 American martial arts film written and directed by Quentin Tarantino. It stars Uma Thurman as the Bride, a former assassin who swears revenge on a group of assassins (Lucy Liu, Michael Madsen, Daryl Hannah, and Vivica A. Fox) and their leader, Bill (David Carradine), who tried to kill her and her unborn child. Her journey takes her to Tokyo, where she battles the yakuza.`,
},
{
  title: "The Animatrix",
  text: `The Animatrix (Japanese: アニマトリックス, Hepburn: Animatorikkusu) is a 2003 American-Japanese adult animated science-fiction anthology film produced by the Wachowskis.[2] The film compiles nine animated short films, detailing the backstory of The Matrix film series, revealing the major events of the apocalyptic war between humanity and machines which led to the creation of the Matrix in the two parts of The Second Renaissance short, in addition to providing side stories that expand the universe and tie into the film series.`,
},
{
  title: "John Wick: Chapter 2",
  text: `John Wick:  Chapter 2 is a 2017 American neo-noir action thriller film directed by Chad Stahelski and written by Derek Kolstad. The film is sequel to John Wick (2014) and the second installment in the John Wick franchise. It stars Keanu Reeves as the eponymous character, alongside Common, Laurence Fishburne, Riccardo Scamarcio, Ruby Rose, Lance Reddick, Peter Stormare, Bridget Moynahan, Franco Nero, John Leguizamo, and Ian McShane. In the film, retired hitman John Wick is forced back into his old life to fulfill a blood oath to crime lord Santino D'Antonio (Scamarcio).`,
},
{
  title: "Good Burger",
  text: `Good Burger is a 1997 American teen comedy film directed by Brian Robbins, written by Dan Schneider with Kevin Kopelow and Heath Seifert, and starring Kenan Thompson and Kel Mitchell. The film is a spin-off of the \"Good Burger\" comedy sketch from the Nickelodeon variety series All That, with Mitchell reprising his role as Ed. The story follows Dexter, a high school student who takes a job at a fast-food restaurant called Good Burger in order to pay off the damages he made to his teacher's car as he and Ed, his dimwitted co-worker, stumble upon an evil plot by a rival fast-food restaurant.`,
},
{
  title: "Spider-Man",
  text: `Spider-Man follows Peter Parker (Tobey Maguire), an orphaned high schooler who pines after popular girl-next-door Mary Jane Watson (Kirsten Dunst). While on a science class field trip at Columbia University, a genetically-engineered \"super spider\" bites Peter. As a result, Peter gains superhuman abilities, including increased strength, speed, and the abilities to scale walls and generate organic webbing. After his beloved Uncle Ben (Cliff Robertson) is murdered, the teenager realizes that he must use his newfound abilities to protect New York City. Meanwhile, wealthy industrialist Norman Osborn (Willem Dafoe), the father of Peter's best friend Harry Osborn (James Franco), subjects himself to an experimental performance-enhancing serum, which creates a psychotic and murderous split personality. Donning a military battle suit, Norman becomes a freakish \"Green Goblin\", who begins to terrorize the city. Peter, as Spider-Man, now must battle with the Goblin, all while dealing with personal situations involving his domestic and his love life.`,
},
{
  title: "Pan's Labyrinth",
  text: `Pan's Labyrinth (Spanish: El laberinto del fauno, lit. 'The Labyrinth Of The Faun') is a 2006 dark fantasy film[4] written, directed and co-produced by Guillermo del Toro. The film stars Ivana Baquero, Sergi López, Maribel Verdú, Doug Jones, and Ariadna Gil. The story takes place in Spain in the summer of 1944, during the early Francoist period, five years after the Spanish Civil War. The narrative intertwines this real world with a mythical world centered on an overgrown, abandoned labyrinth and a mysterious faun creature, with whom the main character, Ofelia, interacts. Ofelia's stepfather, the Falangist Captain Vidal, hunts the Spanish Maquis who fight against the Francoist regime, while Ofelia's pregnant mother grows increasingly ill. Ofelia meets several strange and magical creatures who become central to her story, leading her through the trials of the old labyrinth garden. The film employs make-up, animatronics, and CGI effects to bring life to its creatures.`,
},
{
  title: "Akira",
  text: `Akira (Japanese: アキラ) is a 1988 Japanese animated cyberpunk action film directed by Katsuhiro Otomo, produced by Ryōhei Suzuki and Shunzō Katō, and written by Otomo and Izo Hashimoto, based on Otomo's 1982 manga of the same name. Set in a dystopian 2019, it tells the story of Shōtarō Kaneda, the leader of a biker gang whose childhood friend, Tetsuo Shima, acquires incredible telekinetic abilities after a motorcycle accident, eventually threatening an entire military complex amid chaos and rebellion in the sprawling futuristic metropolis of Neo-Tokyo.`,
}]
And make this Search feature👉

Some years ago, before I knew how to code I remember what prompted me on the path was this desire to make an app that had a full text search feature (mainly for an NGO I was working for). At the time I had no idea how to do it but I knew I would need more than HTML and CSS, hence my coding journey began. At the outset, I thought I would have to know the language so well in order to literally make a search engine from scratch, I mean like making binary trees!

However, to my good fortune, I learned it's not at all complicated. Using NPM which is basically a bag of tools that add "special powers" to websites, I found a multitude of options that could get the job done. And so without further ado, let us explore just how easy it is to add custom search using Lunrjs. The good news is that once you know one, you know them all (for the most part). Why? Because a good majority of them (Mini Search, Elastic Search ), work the same way (at least the client-side ones do). Let's Begin!

“Lunrjs - Designed to be small, yet full featured, Lunr enables you to provide a great search experience without the need for external, server-side, search services.”

For this tutorial we will use Visual Studio and Node so make sure you have them installed. First let's open Visual Studio Code and designate a folder for the project to live in. Here we want to open our terminal and run these commands to install the libraries we will need for the project. Type this -->npm install lunr webpack webpack-cli<-- into the terminal and then hit enter. Great! Now I am going to use a list of Movies as the data to be searched. You of course can make your own list or copy what I have here below.

                
              

Now the fun part. Let's import the Lunr module using require. And then build our index by using this function here.

                  
                const lunr = require('lunr');

                const index = lunr(function () {
                  this.ref('title')
                  this.field('text')
              
                  documents.forEach(function (doc) {
                      this.add(doc)
                  }, this)
              })
                  
                  
                

This function is where the magic happens, basically it takes the movie data we made and procceses it to produce an index object which contains maps between the content and the title, so that when we use the search function it provides (index.search("japanese")), it will return the references that match the query we give it. Hence the snippet this.ref("title") is basically where we the title as the reference of the content. In other words whatever we assign to this.ref(?) will be returned to us by the index object if there is a match to it's contents when we make a query. And so in this instance, this.ref gets assigned the "title" key. Becuase logically the title should be the point of reference for the content to be searched. Next, the snippet this.field("text") gets assigned the words to be searched. And so in this instance that would be the "text" key of our movie data. And so for example, if we search "japenese", it'll return an array carrying these two movie titles "Akira" and "The Creator". Why? Because in the movie data the text value for these two movies contain the word "japanese". I hope you get what I'm dishing!

Finally we output the data to html with some basic js. And voila we are done.

              
                results.forEach(item => {
                  const d = document.createElement("div")
                  d.style = "display:flex; flex-direction: row;"
                  const title = document.createElement("h3")
                  const text = document.createElement("p")
                  text.style = "flex: .7; "
                  title.style = "flex:     .2; text-align:right; padding-right: 10px"
                  title.textContent = item.ref
                  text.textContent = documents.filter(docItem => docItem.title === title.textContent)[0].text
                  d.appendChild(title)
                  d.appendChild(text)
                  console.log(item);
                  listContainer.appendChild(d)
              })
              
            

You can download an entire copy of the repo here. A full working example is embeded at the top of the page, just enter any word found in the movie data and it should return a list of matches. Now it's important to note that what I covered here is just the bare minimum. There is so much more that can be done to customize the search and further enhance the user experience on your website and/or app. Hope this has helped!

details-thumbanil
details-thumbanil

Tumligula class vulputate dis a iaculis praesent

Nulla purus non orci nec nullam aenean molestie tellus libero blandit duis mauris, aliquam faucibus magnis viverra platea mi risus nostra nisl lacus augue placerat diam, suscipit arcu ornare in vivamus elementum maecenas sollicitudin etiam est pretium. Eu platea curabitur laoreet luctus natoque eget cras mus scelerisque aptent, fermentum ligula class vulputate dis a iaculis praesent imperdiet ornare, inceptos auctor neque vestibulum condimentum quisque velit feugiat erat. Fusce tellus facilisis mollis purus augue risus libero cubilia dapibus aliquet, fames imperdiet suscipit himenaeos gravida pellentesque sagittis nullam a, curae cursus praesent sem curabitur fermentum justo commodo dui. Praesent vitae ad laoreet mus luctus litora nec dictum vel class, Nisl vehicula morbi sapien volutpat integer conubia justo sem fermentum cum porta condimentum neque, nibh sodales vulputate donec duis felis class nunc et semper blandit ut. Montes vivamus augue enim curabitur ad orci ut massa parturient feugiat, phasellus proin integer class morbi natoque nisl nunc varius,

Tags
blog-details
Developer
Oliver Saintilien

Nullam varius luctus pharetra ultrices volpat facilisis donec tortor, nibhkisys habitant curabitur at nunc nisl magna ac rhoncus vehicula sociis tortor nist hendrerit molestie integer online service service provide

M A Z I N

Loading