Class: SiteSearch::ResultItem
- Inherits:
-
Data
- Object
- Data
- SiteSearch::ResultItem
- Defined in:
- app/services/site_search/result_item.rb
Overview
One row in a site-search result set, whatever engine produced it.
The adapters (SwiftypeAdapter, PublicationsAdapter)
each map their own payload into this shape, so Query can rank and
interleave them without knowing where they came from — and so replacing an
engine never changes what the browser receives.
highlight holds engine-supplied snippets with <em>-style emphasis, keyed
title/body. The client sanitizes those narrowly, so adapters must not put
arbitrary HTML there.
Constant Summary collapse
- TYPE_ALIASES =
Canonical type labels the UI filters on. Engines report these inconsistently
(faqs,faq,Blog,post, …), so normalization happens here — once —
rather than in every browser. { 'faq' => 'FAQ', 'faqs' => 'FAQ', 'product' => 'Product', 'products' => 'Product', 'blog' => 'Blog', 'post' => 'Blog', 'video' => 'Video', 'videos' => 'Video', 'support' => 'Support', 'publication' => 'Publication', 'publications' => 'Publication' }.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#highlight ⇒ Object
readonly
Returns the value of attribute highlight.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json ⇒ Hash
One result row as the browser consumes it.
-
#initialize(id: nil, url: nil, image: nil, title: nil, body: nil, highlight: {}, type: nil) ⇒ ResultItem
constructor
A new instance of ResultItem.
Constructor Details
#initialize(id: nil, url: nil, image: nil, title: nil, body: nil, highlight: {}, type: nil) ⇒ ResultItem
Returns a new instance of ResultItem.
38 39 40 |
# File 'app/services/site_search/result_item.rb', line 38 def initialize(id: nil, url: nil, image: nil, title: nil, body: nil, highlight: {}, type: nil) super end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def body @body end |
#highlight ⇒ Object (readonly)
Returns the value of attribute highlight
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def highlight @highlight end |
#id ⇒ Object (readonly)
Returns the value of attribute id
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def image @image end |
#title ⇒ Object (readonly)
Returns the value of attribute title
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url
13 14 15 |
# File 'app/services/site_search/result_item.rb', line 13 def url @url end |
Class Method Details
.normalize_type(raw, fallback: nil) ⇒ String?
45 46 47 48 49 50 |
# File 'app/services/site_search/result_item.rb', line 45 def self.normalize_type(raw, fallback: nil) value = raw.to_s.strip return fallback if value.blank? TYPE_ALIASES[value.downcase] || value.upcase_first end |
Instance Method Details
#as_json ⇒ Hash
Returns one result row as the browser consumes it.
53 54 55 |
# File 'app/services/site_search/result_item.rb', line 53 def as_json(*) { id:, url:, image:, title:, body:, highlight:, type: } end |