Class: DocsKit::SearchHit

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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

#hrefObject (readonly)

Returns the value of attribute href

Returns:

  • (Object)

    the current value of href



12
13
14
# File 'lib/docs_kit/search_hit.rb', line 12

def href
  @href
end

#page_titleObject (readonly)

Returns the value of attribute page_title

Returns:

  • (Object)

    the current value of page_title



12
13
14
# File 'lib/docs_kit/search_hit.rb', line 12

def page_title
  @page_title
end

#scoreObject (readonly)

Returns the value of attribute score

Returns:

  • (Object)

    the current value of score



12
13
14
# File 'lib/docs_kit/search_hit.rb', line 12

def score
  @score
end

#section_titleObject (readonly)

Returns the value of attribute section_title

Returns:

  • (Object)

    the current value of section_title



12
13
14
# File 'lib/docs_kit/search_hit.rb', line 12

def section_title
  @section_title
end

#snippetObject (readonly)

Returns the value of attribute snippet

Returns:

  • (Object)

    the current value of snippet



12
13
14
# File 'lib/docs_kit/search_hit.rb', line 12

def snippet
  @snippet
end

Instance Method Details

#as_jsonObject

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

#labelObject

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