class Udongo::Search::ResultObjects::Base
Attributes
index[R]
search_context[R]
Public Class Methods
new(index, search_context: nil)
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 12 def initialize(index, search_context: nil) @index = index @search_context = search_context end
Public Instance Methods
build_html()
click to toggle source
Typically, an autocomplete requires 3 things:
-
A title indicating a resource name. Examples: Page#title, Product#name,…
-
A truncated summary providing a glimpse of the resource's contents. Examples: Page#subtitle, Product#description,…
-
A link to the resource. Examples: edit_backend_page_path(37), product_path(37),…
However, this seems very restrictive to me. If I narrow down the data a dev can use in an autocomplete, it severely reduces options he/she has in how the autocomplete results look like. Think of autocompletes in a shop that require images or prices to be included in their result bodies.
This is why I chose to let ApplicationController.render work around the problem by letting the dev decide how the row should look.
# File lib/udongo/search/result_objects/base.rb, line 34 def build_html ApplicationController.render(partial: partial, locals: locals) end
label()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 42 def label if index.name.include?('flexible_content') id = index.name.split(':')[1].to_i return ContentText.find(id).content end searchable.send(index.name) end
locals()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 51 def locals { "#{partial_target}": index.searchable, index: index } end
partial()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 55 def partial "#{partial_path}/#{partial_target}" end
partial_path()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 59 def partial_path "#{search_context.namespace.to_s.underscore}/search" end
partial_target()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 63 def partial_target index.searchable_type.underscore end
unpublished?()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 67 def unpublished? searchable.respond_to?(:published?) && searchable.unpublished? end
url()
click to toggle source
# File lib/udongo/search/result_objects/base.rb, line 71 def url end