Class: DocsKit::SearchIndex::Entry

Inherits:
Struct
  • Object
show all
Defined in:
lib/docs_kit/search_index.rb

Overview

An indexed section (or page intro). haystacks holds the lowercased text of each weighted field so scoring is a simple include? per token.

The page title is searchable ONLY on the page-intro entry (section_title nil), not on every section: a title token matches all sections of a page equally, so weighting each section by the title would flood the results with near-identical rows from one page. A pure title match therefore surfaces once (the intro), while a section still ranks on its own heading/body.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



43
44
45
# File 'lib/docs_kit/search_index.rb', line 43

def body
  @body
end

#hrefObject

Returns the value of attribute href

Returns:

  • (Object)

    the current value of href



43
44
45
# File 'lib/docs_kit/search_index.rb', line 43

def href
  @href
end

#page_titleObject

Returns the value of attribute page_title

Returns:

  • (Object)

    the current value of page_title



43
44
45
# File 'lib/docs_kit/search_index.rb', line 43

def page_title
  @page_title
end

#section_titleObject

Returns the value of attribute section_title

Returns:

  • (Object)

    the current value of section_title



43
44
45
# File 'lib/docs_kit/search_index.rb', line 43

def section_title
  @section_title
end

Instance Method Details

#haystacksObject

{ weight => lowercased searchable text } for this entry.



45
46
47
48
49
50
51
52
53
54
# File 'lib/docs_kit/search_index.rb', line 45

def haystacks
  @haystacks ||= begin
    fields = {
      HEADING_WEIGHT => section_title.to_s.downcase,
      BODY_WEIGHT => body.to_s.downcase
    }
    fields[TITLE_WEIGHT] = page_title.to_s.downcase if section_title.nil?
    fields
  end
end