97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/jekyll_search.rb', line 97
def process(options, query)
options = configuration_from_options(options)
site = Jekyll::Site.new(options)
settings = site.config['search']
client = Elasticsearch::Client.new host: settings['host'], log: false
result = client.search index: settings['index']['name'], body: { query: { match: { content: query } }, highlight: { fields: { content: {} }} }
puts "Query: #{query}"
puts "Total: #{result['hits']['total']}"
puts "Max score: #{result['hits']['max_score']}"
for hit in result['hits']['hits']
puts "Hit at #{hit['_source']['url']} (#{hit['_score']})"
hit['highlight']['content'].each { |c| puts '- ' + c }
end
end
|