Class: DocsKit::SearchHit
- Inherits:
-
Data
- Object
- Data
- DocsKit::SearchHit
- Defined in:
- lib/docs_kit/search_hit.rb
Overview
One ranked search result. Built by DocsKit::SearchIndex#search and rendered by DocsUI::SearchResults (html) / serialized to JSON for the docs-nav palette.
page_title — the page the hit lives on (results group by this)
section_title — the `## ` section, or nil for a page-intro hit
href — the page href + "#anchor" (nil section → bare page href)
snippet — an HTML-safe excerpt around the match, the term in <mark>
score — the rank weight (title > heading > body); higher wins
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#page_title ⇒ Object
readonly
Returns the value of attribute page_title.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#section_title ⇒ Object
readonly
Returns the value of attribute section_title.
-
#snippet ⇒ Object
readonly
Returns the value of attribute snippet.
Instance Method Summary collapse
-
#as_json ⇒ Object
JSON shape the palette fetches (matches #label / #href / #snippet).
-
#initialize(page_title:, href:, snippet:, score:, section_title: nil) ⇒ SearchHit
constructor
A new instance of SearchHit.
-
#label ⇒ Object
The label a result row shows: "Page → Section", or just the page title for a page-intro hit.
Constructor Details
#initialize(page_title:, href:, snippet:, score:, section_title: nil) ⇒ SearchHit
Returns a new instance of SearchHit.
13 14 15 |
# File 'lib/docs_kit/search_hit.rb', line 13 def initialize(page_title:, href:, snippet:, score:, section_title: nil) super end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href
12 13 14 |
# File 'lib/docs_kit/search_hit.rb', line 12 def href @href end |
#page_title ⇒ Object (readonly)
Returns the value of attribute page_title
12 13 14 |
# File 'lib/docs_kit/search_hit.rb', line 12 def page_title @page_title end |
#score ⇒ Object (readonly)
Returns the value of attribute score
12 13 14 |
# File 'lib/docs_kit/search_hit.rb', line 12 def score @score end |
#section_title ⇒ Object (readonly)
Returns the value of attribute section_title
12 13 14 |
# File 'lib/docs_kit/search_hit.rb', line 12 def section_title @section_title end |
#snippet ⇒ Object (readonly)
Returns the value of attribute snippet
12 13 14 |
# File 'lib/docs_kit/search_hit.rb', line 12 def snippet @snippet end |
Instance Method Details
#as_json ⇒ Object
JSON shape the palette fetches (matches #label / #href / #snippet).
24 25 26 |
# File 'lib/docs_kit/search_hit.rb', line 24 def as_json(*) { "label" => label, "href" => href, "snippet" => snippet } end |
#label ⇒ Object
The label a result row shows: "Page → Section", or just the page title for a page-intro hit.
19 20 21 |
# File 'lib/docs_kit/search_hit.rb', line 19 def label section_title ? "#{page_title} → #{section_title}" : page_title end |