durfdoen-2.0/lib/helpers/search.rb
2020-09-15 21:44:23 +02:00

37 lines
983 B
Ruby

require 'json'
require 'nokogiri'
module SearchHelper
class CreateFullTextIndex
COMMON_WORDS = %w{ a about above across ... } unless defined?(COMMON_WORDS)
def initialize(articles)
@articles = articles
end
def call
@articles.map do |item|
words = item.raw_content().downcase.split(/\W+/)
keywords = words.uniq - COMMON_WORDS
{
url: item.path,
id: item[:id],
title: item[:titel],
verkort: item[:verkorte_naam],
konvent: item[:konvent],
body: keywords.join(" ")
}
end.to_a
end
end
def to_partials_search(items)
my_hash = {}
items.each do |item|
my_hash[(item.path)] = (render '/partials/pretty_link.*', :item => item).gsub("\n", '')
end
my_hash.to_json
end
end