Class: Spotlight::FieldMetadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/spotlight/field_metadata.rb

Overview

Expose Solr index metadata about fields

Constant Summary collapse

FACET_LIMIT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exhibit, repository, blacklight_config) ⇒ FieldMetadata

Returns a new instance of FieldMetadata.



9
10
11
12
13
# File 'app/models/spotlight/field_metadata.rb', line 9

def initialize(exhibit, repository, blacklight_config)
  @exhibit = exhibit
  @repository = repository
  @blacklight_config = blacklight_config
end

Instance Attribute Details

#blacklight_configObject (readonly)

Returns the value of attribute blacklight_config.



7
8
9
# File 'app/models/spotlight/field_metadata.rb', line 7

def blacklight_config
  @blacklight_config
end

#exhibitObject (readonly) Also known as: current_exhibit

Returns the value of attribute exhibit.



7
8
9
# File 'app/models/spotlight/field_metadata.rb', line 7

def exhibit
  @exhibit
end

#repositoryObject (readonly)

Returns the value of attribute repository.



7
8
9
# File 'app/models/spotlight/field_metadata.rb', line 7

def repository
  @repository
end

Instance Method Details

#field(field_name) ⇒ Object



15
16
17
18
19
20
21
# File 'app/models/spotlight/field_metadata.rb', line 15

def field(field_name)
  {
    document_count: document_counts.fetch(field_name, 0),
    value_count: terms.fetch(field_name, []).length,
    terms: terms.fetch(field_name, [])
  }
end

#search_paramsObject



23
24
25
# File 'app/models/spotlight/field_metadata.rb', line 23

def search_params
  search_builder.merge(rows: 0, 'facet.limit' => FACET_LIMIT + 1)
end