diff --git a/plugins/elasticsearch/Rakefile b/plugins/elasticsearch/Rakefile index c455af5..229a657 100644 --- a/plugins/elasticsearch/Rakefile +++ b/plugins/elasticsearch/Rakefile @@ -30,7 +30,7 @@ task :start do if elasticsearch_development sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' - sleep 2 + sleep 10 end end diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index a7f1ef8..908981f 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -18,6 +18,7 @@ class ElasticsearchPluginController < ApplicationController def define_results @query = params[:query] @results = process_results + @hits = @results.total end def define_searchable_types @@ -26,13 +27,8 @@ class ElasticsearchPluginController < ApplicationController end def define_search_fields_types - @search_filter_types = ElasticsearchHelper::search_filters - @selected_filter_field = (params[:selected_filter_field] || ElasticsearchHelper::search_filters.keys.first).to_sym + @filter_types = ElasticsearchHelper::filters + @selected_filter = (params[:filter] || :relevance).to_sym end - private - -# def permit_params -# params.require(:per_page, :query) -# end end diff --git a/plugins/elasticsearch/helpers/elasticsearch_helper.rb b/plugins/elasticsearch/helpers/elasticsearch_helper.rb index 05168f7..0279681 100644 --- a/plugins/elasticsearch/helpers/elasticsearch_helper.rb +++ b/plugins/elasticsearch/helpers/elasticsearch_helper.rb @@ -11,83 +11,99 @@ module ElasticsearchHelper } end - def self.search_filters + def self.filters { - :lexical => { label: _("Alphabetical Order")}, - :recent => { label: _("More Recent Order")}, - :access => { label: _("More accessed")} + :relevance => { label: _("Relevance")}, + :lexical => { label: _("Alphabetical")}, + :more_recent => { label: _("More Recent")}, } end - def fields_from_model - klass::SEARCHABLE_FIELDS.map do |key, value| - if value[:weight] - "#{key}^#{value[:weight]}" - else - "#{key}" - end - end - end - - def get_query text, klass=nil - query = {} - unless text.blank? - text = text.downcase - query = { - query: { - match_all: { - } - }, - filter: { - regexp: { - name: { - value: ".*" + text + ".*" } - } - }, - suggest: { - autocomplete: { - text: text, - term: { - field: "name", - suggest_mode: "always" - } - } - } - - } - end - query - end - def process_results - selected_type = (params[:selected_type]|| :all).to_sym - if selected_type == :all - search_from_all_models - else - search_from_model selected_type - end + selected_type = (params[:selected_type].presence|| :all).to_sym + selected_type == :all ? search_from_all_models : search_from_model(selected_type) end - def search_from_all_models - models = [] - query = get_query params[:query] + private - ElasticsearchHelper::searchable_types.keys.each {| model | models.append( model.to_s.classify.constantize) if model != :all } - Elasticsearch::Model.search(query, models, size: default_per_page(params[:per_page])).page(params[:page]).records + def search_from_all_models + query = get_query params[:query], sort_by: get_sort_by(params[:filter]) + Elasticsearch::Model.search(query,searchable_models, size: default_per_page(params[:per_page])).page(params[:page]).records end def search_from_model model begin klass = model.to_s.classify.constantize - query = get_query params[:query], klass + + query = get_query params[:query], klass: klass, sort_by: get_sort_by(params[:filter]) klass.search(query, size: default_per_page(params[:per_page])).page(params[:page]).records rescue [] end end - def default_per_page per_page + def default_per_page per_page=nil per_page ||= 10 end + def get_sort_by sort_by + case sort_by + when "lexical" + { "name.raw" => {"order" => "asc" }} + when "more_recent" + { "created_at" => {"order" => "desc"}} + end + end + + def searchable_models + begin + ElasticsearchHelper::searchable_types.except(:all).keys.map { | model | model.to_s.classify.constantize } + rescue + [] + end + end + + def query_method expression="", fields=[] + query_exp = {} + if expression.blank? + else + query_exp = { + query: { + query_string: { + query: "*"+expression.downcase.split.join('* *')+"*", + fields: fields, + tie_breaker: 0.4, + minimum_should_match: "100%" + }, + } + } + end + query_exp + end + + def get_query text="", options={} + klass = options[:klass] + sort_by = options[:sort_by] + + fields = klass.nil? ? (fields_from_models searchable_models) : (fields_from_models [klass]) + + query = query_method(text, fields) + query[:sort] = sort_by if sort_by + query + end + + def fields_from_models klasses + fields = Set.new + klasses.each do |klass| + klass::SEARCHABLE_FIELDS.map do |key, value| + if value and value[:weight] + fields.add "#{key}^#{value[:weight]}" + else + fields.add "#{key}" + end + end + end + fields.to_a + end + end diff --git a/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb b/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb index c3c7ab3..9051555 100644 --- a/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb +++ b/plugins/elasticsearch/lib/elasticsearch_indexed_model.rb @@ -2,14 +2,21 @@ module ElasticsearchIndexedModel def self.included base base.send :include, Elasticsearch::Model + base.send :include, Elasticsearch::Model::Callbacks + base.send :index_name, "#{Rails.env}_#{base.index_name}" base.extend ClassMethods base.class_eval do settings index: { number_of_shards: 1 } do mappings dynamic: 'false' do - base.indexable_fields.each do |field, value| + base.indexed_fields.each do |field, value| value = {} if value.nil? - indexes field, type: value[:type].presence + type = value[:type].presence + if type.nil? + indexes(field, fields: base.raw_field(field)) + else + indexes field, type: type + end print '.' end end @@ -28,9 +35,19 @@ module ElasticsearchIndexedModel end module ClassMethods - def indexable_fields - self::SEARCHABLE_FIELDS.update self.control_fields + def raw_field name + { + raw: { + type: "string", + index: "not_analyzed" + } + } + end + + def indexed_fields + self::SEARCHABLE_FIELDS.merge self.control_fields end + end end diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin.rb b/plugins/elasticsearch/lib/elasticsearch_plugin.rb index 06750e3..bceac96 100644 --- a/plugins/elasticsearch/lib/elasticsearch_plugin.rb +++ b/plugins/elasticsearch/lib/elasticsearch_plugin.rb @@ -17,12 +17,24 @@ class ElasticsearchPlugin < Noosfero::Plugin end def search_controller_filters - block = proc do - redirect_to controller: 'elasticsearch_plugin', action: 'search', params: params - end + block = proc do + + case action_name + when 'contents' + params[:selected_type] = :text_article + when 'index' + when 'articles' + params[:selected_type] = :text_article + else + params[:selected_type] = action_name.singularize.to_sym + end + + redirect_to controller: 'elasticsearch_plugin', action: 'search', params: params + end [{ :type => 'before_filter', :method_name => 'redirect_search_to_elastic', :block => block }] end + end diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin/entities.rb b/plugins/elasticsearch/lib/elasticsearch_plugin/entities.rb index 92936da..07e65e3 100644 --- a/plugins/elasticsearch/lib/elasticsearch_plugin/entities.rb +++ b/plugins/elasticsearch/lib/elasticsearch_plugin/entities.rb @@ -1,5 +1,6 @@ module Elasticsearch module Entities + class Result < Api::Entity root "results","result" @@ -7,11 +8,24 @@ module Elasticsearch options[:types].detect { |type| type.to_s.upcase if object.is_a? (type.to_s.classify.constantize) } end + expose :id expose :name expose :author, if: lambda { |object,options| object.respond_to? 'author'} do |object, options| object.author.present? ? object.author.name : "" end + + expose :description, if: lambda { |object,options| object.respond_to? 'description'} do |object, options| + object.description.present? ? object.description : "" + end + + expose :abstract, if: lambda { |object,options| object.respond_to? 'abstract'} do |object, options| + object.abstract.present? ? object.abstract : "" + end + + expose :created_at, :format_with => :timestamp + expose :updated_at, :format_with => :timestamp end + end end diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb index 8dd9d86..b64d1bf 100644 --- a/plugins/elasticsearch/lib/ext/community.rb +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -3,7 +3,9 @@ require_relative '../elasticsearch_indexed_model' class Community def self.control_fields - {} + { + :created_at => {type: 'date'} + } end include ElasticsearchIndexedModel end diff --git a/plugins/elasticsearch/lib/ext/event.rb b/plugins/elasticsearch/lib/ext/event.rb index d0a4b15..acd90b2 100644 --- a/plugins/elasticsearch/lib/ext/event.rb +++ b/plugins/elasticsearch/lib/ext/event.rb @@ -6,6 +6,7 @@ class Event { :advertise => {}, :published => {}, + :created_at => {type: 'date'} } end include ElasticsearchIndexedModel diff --git a/plugins/elasticsearch/lib/ext/person.rb b/plugins/elasticsearch/lib/ext/person.rb index c99e97e..3348442 100644 --- a/plugins/elasticsearch/lib/ext/person.rb +++ b/plugins/elasticsearch/lib/ext/person.rb @@ -6,6 +6,7 @@ class Person { :visible => {type: 'boolean'}, :public_profile => {type: 'boolean'}, + :created_at => {type: 'date'} } end include ElasticsearchIndexedModel diff --git a/plugins/elasticsearch/lib/ext/text_article.rb b/plugins/elasticsearch/lib/ext/text_article.rb index 2f3206f..7185aee 100644 --- a/plugins/elasticsearch/lib/ext/text_article.rb +++ b/plugins/elasticsearch/lib/ext/text_article.rb @@ -1,3 +1,7 @@ +# REQUIRE TO LOAD DESCENDANTS FROM TEXT_ARTICLE +require_dependency 'raw_html_article' +require_dependency 'tiny_mce_article' + require_dependency 'text_article' require_relative '../elasticsearch_indexed_model' @@ -6,6 +10,7 @@ class TextArticle { :advertise => {}, :published => {}, + :created_at => {type: 'date'} } end include ElasticsearchIndexedModel diff --git a/plugins/elasticsearch/lib/ext/uploaded_file.rb b/plugins/elasticsearch/lib/ext/uploaded_file.rb index 187f8d1..17b974d 100644 --- a/plugins/elasticsearch/lib/ext/uploaded_file.rb +++ b/plugins/elasticsearch/lib/ext/uploaded_file.rb @@ -6,6 +6,7 @@ class UploadedFile { :advertise => {}, :published => {}, + :created_at => {type: 'date'} } end include ElasticsearchIndexedModel diff --git a/plugins/elasticsearch/test/test_helper.rb b/plugins/elasticsearch/test/test_helper.rb index ff19baa..6cf0727 100644 --- a/plugins/elasticsearch/test/test_helper.rb +++ b/plugins/elasticsearch/test/test_helper.rb @@ -20,7 +20,7 @@ module ElasticsearchTestHelper model.__elasticsearch__.create_index! force: true model.import } - sleep 1 + sleep 2 end def setup_environment diff --git a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb index ce1b3f7..e149bd9 100644 --- a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb +++ b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb @@ -9,8 +9,8 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase end def create_instances - 7.times.each {|index| create_user "person_#{index}"} - 4.times.each {|index| fast_create Community, name: "community_#{index}", created_at: Date.new } + 7.times.each {|index| create_user "person #{index}"} + 4.times.each {|index| fast_create Community, name: "community #{index}" } end should 'show all types avaliable in /search/types endpoint' do @@ -28,14 +28,14 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase end should 'respond with query in downcase' do - get "/api/v1/search?query=person_" + get "/api/v1/search?query=person" json = JSON.parse(last_response.body) assert_equal 200, last_response.status assert_equal 7, json["results"].count end - should 'respond with query in upcase' do - get "/api/v1/search?query=PERSON_" + should 'respond with query in uppercase' do + get "/api/v1/search?query=PERSON" json = JSON.parse(last_response.body) assert_equal 200, last_response.status assert_equal 7, json["results"].count @@ -47,5 +47,4 @@ class ElasticsearchPluginApiTest < ActiveSupport::TestCase assert_equal 200, last_response.status assert_equal 4, json["results"].count end - end diff --git a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb new file mode 100644 index 0000000..415b9f3 --- /dev/null +++ b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb @@ -0,0 +1,122 @@ +require "#{File.dirname(__FILE__)}/../../test_helper" + +class ElasticsearchPluginEntitiesTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Person,TextArticle,UploadedFile,Community,Event] + end + + def create_instances + user = create_user "sample person" + + fast_create Community, name: "sample community", created_at: 10.days.ago,updated_at: 5.days.ago + fast_create UploadedFile, name: "sample uploadedfile", created_at: 3.days.ago, updated_at: 1.days.ago, author_id: user.person.id, abstract: "sample abstract" + fast_create Event, name: "sample event", created_at: 20.days.ago, updated_at: 5.days.ago, author_id: user.person.id, abstract: "sample abstract" + + fast_create RawHTMLArticle, name: "sample raw html article", created_at: 15.days.ago ,updated_at: 5.days.ago, author_id: user.person.id + fast_create TinyMceArticle, name: "sample tiny mce article", created_at: 5.days.ago, updated_at: 5.days.ago, author_id: user.person.id + end + + should 'show attributes from person' do + params = {:selected_type => "person" } + get "/api/v1/search?#{params.to_query}" + json= JSON.parse(last_response.body) + + expected_person = Person.find_by name: "sample person" + + assert_equal 200, last_response.status + assert_equal expected_person.id, json['results'][0]['id'] + assert_equal expected_person.name, json['results'][0]['name'] + assert_equal expected_person.type, json['results'][0]['type'] + assert_equal "", json['results'][0]['description'] + assert_equal expected_person.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] + assert_equal expected_person.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] + end + + should 'show attributes from community' do + params = {:selected_type => "community" } + get "/api/v1/search?#{params.to_query}" + json= JSON.parse(last_response.body) + + expected_community = Community.find_by name: "sample community" + + assert_equal 200, last_response.status + assert_equal expected_community.id, json['results'][0]['id'] + assert_equal expected_community.name, json['results'][0]['name'] + assert_equal expected_community.type, json['results'][0]['type'] + assert_equal "", json['results'][0]['description'] + assert_equal expected_community.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] + assert_equal expected_community.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] + end + + should 'show attributes from text_article' do + params = {:selected_type => "text_article" } + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + + expected_text_articles = TextArticle.all + + expected_text_articles.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal "TextArticle", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + + assert_equal expected_author, json['results'][index]['author'] + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + + should 'show attributes from uploaded_file' do + params = {:selected_type => "uploaded_file"} + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + + expected_uploaded_files = UploadedFile.all + expected_uploaded_files.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal object.abstract, json['results'][index]['abstract'] + assert_equal "UploadedFile", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + assert_equal expected_author, json['results'][index]['author'] + + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + + should 'show attributes from event' do + params = {:selected_type => "event"} + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + expected_events = Event.all + expected_events.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal object.abstract, json['results'][index]['abstract'] + assert_equal "Event", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + assert_equal expected_author, json['results'][index]['author'] + + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + +end diff --git a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb index 0266d66..b03dc70 100644 --- a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb +++ b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb @@ -15,13 +15,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase def create_people 5.times do | index | - create_user "person_#{index}" + create_user "person #{index}" end end def create_communities 6.times do | index | - fast_create Community, name: "community_#{index}", created_at: Date.new + fast_create Community, name: "community #{index}", created_at: Date.new end end @@ -30,8 +30,8 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase assert_response :success assert_not_nil assigns(:searchable_types) assert_not_nil assigns(:selected_type) - assert_not_nil assigns(:search_filter_types) - assert_not_nil assigns(:selected_filter_field) + assert_not_nil assigns(:filter_types) + assert_not_nil assigns(:selected_filter) end should 'return 10 results if selected_type is nil and query is nil' do @@ -54,31 +54,31 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase end should 'return results filtered by query' do - get :index, { 'query' => "person_"} + get :index, { 'query' => "person"} assert_response :success assert_select ".search-item", 5 assert_template partial: '_person_display' end - should 'return results filtered by query with uppercase' do - get :index, {'query' => "PERSON_1"} - assert_response :success - assert_select ".search-item", 1 - assert_template partial: '_person_display' - end + should 'return results filtered by query with uppercase' do + get :index, {'query' => "PERSON 1"} + assert_response :success + assert_template partial: '_person_display' + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) + end - should 'return results filtered by query with downcase' do - get :index, {'query' => "person_1"} - assert_response :success - assert_select ".search-item", 1 - end + should 'return results filtered by query with downcase' do + get :index, {'query' => "person 1"} + assert_response :success + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) + end should 'return new person indexed' do get :index, { "selected_type" => :community} assert_response :success assert_select ".search-item", 6 - fast_create Community, name: "community_#{7}", created_at: Date.new + fast_create Community, name: "community #{7}", created_at: Date.new Community.import sleep 2 @@ -108,7 +108,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase end should 'pass params to elastic search controller' do - get 'index', { query: 'community_' } + get 'index', { query: 'community' } assert_not_nil assigns(:results) assert_template partial: '_community_display' end diff --git a/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb b/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb new file mode 100644 index 0000000..c767b7c --- /dev/null +++ b/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb @@ -0,0 +1,86 @@ +require "#{File.dirname(__FILE__)}/../../test_helper" +require_relative '../../../helpers/elasticsearch_helper.rb' + +class ElasticsearchHelperTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + include ElasticsearchHelper + + attr_accessor :params + + def indexed_models + [Person,TextArticle,UploadedFile,Community,Event] + end + + def create_instances + create_user "Jose Abreu" + create_user "Joana Abreu" + create_user "Joao Abreu" + create_user "Ana Abreu" + end + + should 'return default_per_page when nil is passed' do + assert_not_nil default_per_page nil + assert_equal 10, default_per_page(nil) + end + + should 'return default_per_page when per_page is passed' do + assert_equal 15, default_per_page(15) + end + + should 'have indexed_models in searchable_models' do + assert_equivalent indexed_models, searchable_models + end + + should 'return query_string if expression is valid' do + + query= "my_query" + fields = ['name','login'] + result = query_method(query,fields) + + assert_includes result[:query][:query_string][:query], query + assert_equivalent result[:query][:query_string][:fields], fields + end + + + should 'return fields from models using weight' do + class StubClass + SEARCHABLE_FIELDS = {:name => {:weight => 10}, + :login => {:weight => 20}, + :description => {:weight => 2}} + end + + expected = ["name^10", "login^20", "description^2"] + assert_equivalent expected, fields_from_models([StubClass]) + end + + should 'search from model Person sorted by Alphabetic' do + self.params= {:selected_type => 'person', + :filter => 'lexical', + :query => "Abreu", + :per_page => 4} + + result = process_results + assert_equal ["Ana Abreu","Joana Abreu","Joao Abreu","Jose Abreu"], result.map(&:name) + end + + should 'search from model Person sorted by More Recent' do + self.params= {:selected_type => 'person', + :filter => 'more_recent', + :query => 'ABREU', + :per_page => 4} + + result = process_results + assert_equal ["Ana Abreu","Joao Abreu","Joana Abreu","Jose Abreu"], result.map(&:name) + end + + should 'search from model Person sorted by Relevance' do + self.params= {:selected_type => 'person', + :query => 'JOA BREU', + :per_page => 4} + + result = process_results + assert_equal ["Joana Abreu", "Joao Abreu"], result.map(&:name) + end + +end diff --git a/plugins/elasticsearch/test/unit/models/community_test.rb b/plugins/elasticsearch/test/unit/models/community_test.rb index 74cac82..3d3036d 100644 --- a/plugins/elasticsearch/test/unit/models/community_test.rb +++ b/plugins/elasticsearch/test/unit/models/community_test.rb @@ -8,10 +8,6 @@ class CommunityTest < ActionController::TestCase [Community] end - def setup - super - end - should 'index searchable fields for Community model' do Community::SEARCHABLE_FIELDS.each do |key, value| assert_includes indexed_fields(Community), key diff --git a/plugins/elasticsearch/test/unit/models/event_test.rb b/plugins/elasticsearch/test/unit/models/event_test.rb index b857896..8b044f5 100644 --- a/plugins/elasticsearch/test/unit/models/event_test.rb +++ b/plugins/elasticsearch/test/unit/models/event_test.rb @@ -8,10 +8,6 @@ class EventTest < ActionController::TestCase [Event] end - def setup - super - end - should 'index searchable fields for Event model' do Event::SEARCHABLE_FIELDS.each do |key, value| assert_includes indexed_fields(Event), key diff --git a/plugins/elasticsearch/test/unit/models/person_test.rb b/plugins/elasticsearch/test/unit/models/person_test.rb index a8cafc5..0012343 100644 --- a/plugins/elasticsearch/test/unit/models/person_test.rb +++ b/plugins/elasticsearch/test/unit/models/person_test.rb @@ -8,10 +8,6 @@ class PersonTest < ActionController::TestCase [Person] end - def setup - super - end - should 'index searchable fields for Person model' do Person::SEARCHABLE_FIELDS.each do |key, value| assert_includes indexed_fields(Person), key @@ -24,5 +20,4 @@ class PersonTest < ActionController::TestCase assert_includes indexed_fields(Person)[key][:type], value[:type] || 'string' end end - end diff --git a/plugins/elasticsearch/test/unit/models/text_article_test.rb b/plugins/elasticsearch/test/unit/models/text_article_test.rb index 937b77f..1455d8f 100644 --- a/plugins/elasticsearch/test/unit/models/text_article_test.rb +++ b/plugins/elasticsearch/test/unit/models/text_article_test.rb @@ -8,10 +8,6 @@ class TextArticleTest < ActionController::TestCase [TextArticle] end - def setup - super - end - should 'index searchable fields for TextArticle model' do TextArticle::SEARCHABLE_FIELDS.each do |key, value| assert_includes indexed_fields(TextArticle), key diff --git a/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb b/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb index 04bd842..0146047 100644 --- a/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb +++ b/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb @@ -8,10 +8,6 @@ class UploadedFileTest < ActionController::TestCase [UploadedFile] end - def setup - super - end - should 'index searchable fields for UploadedFile model' do UploadedFile::SEARCHABLE_FIELDS.each do |key, value| assert_includes indexed_fields(UploadedFile), key diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb index 42d48e0..08ac688 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb @@ -3,7 +3,7 @@ <%= profile_image person %>
<%= person.description %>
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb index 23fa3b7..7d345bf 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb @@ -1,5 +1,5 @@- <%= @results.total %><%= _(" results for ") %><%= @query %> +
+ <%= @hits %> + <% if not @query.blank? %> + <%= _(" results for ") %><%= @query %> + <% else %> + <%= _(" total results") %> + <% end %>
- <% else %> -- <%= @results.total %><%= _(" total results") %> -
- <% end %>