Search Kick Gem – To Make Your Search Intelligent On Rails App

Search kick Gem is a Ruby gem that runs on top of Elasticsearch and makes it easy to make searches in a Rails-friendly fashion. In addition, it allows you to add more features including analytics, autocomplete, and personalized results. Searchkick realizes what your users are searching for. As more individuals hunt, it gets more brilliant and the outcomes improve. It’s benevolent for designers – and supernatural for your users. It handles stemming, special characters, extra whitespace, misspellings, custom synonyms. To get started, make sure that you have Elasticsearch installed on your home computer. Depending on your operating system, the installation process is slightly different and make sure you have at least Java 7. Once you have that done, add and install searchick to your Rails application by adding the following to your Gemfile and running bundle install.
gem ‘searchkick’
Une fois que vous avez installé les deux et que vous êtes prêt à l'utiliser, vous devez indiquer les modèles que vous souhaitez pouvoir rechercher dans votre application. Ajoutez simplement searchkick au fichier modèle pour le faire fonctionner. Ensuite, nous devons réindexer les modèles pour qu'Elasticsearch puisse fonctionner correctement. Dans votre terminal, exécutez :
râteau searchkick: réindexation: tous
Seeking with searchkick is entirely straightforward. Basically run YourModel.search, trailed by the parameters of the search and any filters that you want to add on. For instance, one of more complex searches is below: @offers = Offer.search params[:search], page: params[:page], per_page: 10, order: {starttime: :desc}, fields: [{offer_name: :word_start}, {offer_request_name: :word_start}:price], where: { starttime: { gte: DateTime.strptime(params[:fromdate], ‘%m/%d/%Y’), lte: DateTime.strptime(params[:todate], ‘%m/%d/%Y’) } } In this search, we take the search query of the user with params[:search], and look through of the lessons with the following conditions: Pagination: Cette partie de code renvoie les résultats de la recherche en pages de 10. Vous pouvez modifier le nombre d'éléments de liste dont vous avez besoin sur chaque page en utilisant cette méthode. Cela fonctionne à la fois avec will_paginate et kaminari. Commande: order: {starttime: :desc} - Cette méthode détermine dans quel ordre les résultats sont renvoyés. En utilisant cela, nous pouvons modifier l'affichage des résultats par ordre croissant ou décroissant. Dans ce cas, nous avons renvoyé en premier les résultats les plus récents. Des champs: [{offer_name: :word_start},{offer_request_name: :word_start} :price]- In this method, we allowed users to search by offer name, offer type, or the offer price. The word_start method allows for users to only type in the first part of the offer name and still get the offer in search results. For example, a search of “ch” would still reveal “chat”. You can also use word_middle and word_end. For longer text, searchkick also supports text_start, text_middle, and text_end. Où: starttime: {gte: DateTime.strptime(params[:fromdate], ‘%m/%d/%Y’), lte: DateTime.strptime(params[:todate], ‘%m/%d/%Y’)}. It allows users to easily use filters in their application. We wanted to filter between dates we used starttime to find the offers Définition d'attributs de recherche personnalisés Une dernière fonctionnalité intéressante de searchkick est la méthode search_data que vous pouvez ajouter à vos modèles. Cela vous permet d'ajouter ou de remplacer des attributs que l'utilisateur peut rechercher. Ce faisant, vous pouvez créer des paramètres de recherche personnalisés ou effectuer une recherche basée sur les associations d'un modèle. Vous trouverez ci-dessous un exemple de l'une des méthodes search_data que nous avons implémentées. déf search_data       attributs.merge(         offer_request_name : offer_requests.map(&:name),        ) fin Indices multiples Effectuez une recherche dans plusieurs index avec :
Searchkick.search « search_query », index_name : [Offer, OfferRequest]
Notre Développeurs Ruby on Rails Ici à RailsCarma ne se contentent pas de créer des applications mais créent des phénomènes. En utilisant des techniques futuristes, ils fournissent des applications brillantes, conçoivent une UI/UX belle et attrayante, développent des frontaux clairs, créent des applications évolutives et les gèrent sur le Cloud. En bref, nos développeurs Ruby on Rails – « Donnez vie à vos idées ». Commentez ci-dessous ou Contactez-nous en cas de question.
Katneni Naga Sai Tejaswi
Développeur de logiciels senior

Abonnez-vous pour les dernières mises à jour

Articles Similaires

Laissez un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

French
English
English
Japanese
German
French
Spanish

WhatsApp nous

Quitter la version mobile