Sha256: 1120bbe5a43a52dd20d11e03971fbf5f3c86a146e044a7c37667b1c1a08f3714
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
require 'thor' module SearchKit class Search class CLI < Thor autoload :Actions, 'search_kit/search/cli/actions' include Messaging namespace :search desc "search SLUG PHRASE", "Search an index".ansi(:cyan, :bold) option :filters, aliases: ['-f'], type: :hash, required: false option :display, aliases: ['-d'], type: :array, required: false def search(slug, phrase) search = Actions::Search.perform( client: client, phrase: phrase, slug: slug ) info "Searching `#{slug}` for titles matching `#{phrase}`:" info " - Found #{search.results} titles in #{search.time}ms" display = options.fetch('display', []) search.documents.each do |document| if display.any? fields = display.map { |field| document.get(field) } info " -- #{fields.join(' | ')} | score: #{document.score}" else info " -- #{document.id} | score: #{document.score}" end end end no_commands do alias_method :s, :search end private def client @client ||= Client.new end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
search-kit-0.0.2 | lib/search_kit/search/cli.rb |
search-kit-0.0.1 | lib/search_kit/search/cli.rb |