Class: MusicBrainz::Model::ScoredCollection

Inherits:
Collection
  • Object
show all
Defined in:
lib/rbrainz/model/scored_collection.rb

Overview

A ScoredCollection is a list of entities with scores.

A ScoredCollection is returned as the result of an entity search (e.g. search for an Artist). It contains an ordered list of Entry objects which wrap the entities and a corresponding search score, which indicates how good the entity matches the search criteria used for the search. The entities in a scored collection are sorted by score (in descending order).

A collection object may only store an extract of the complete data available on the server. This is especially the case if the limit or offset filter was used in the query. The collection object makes the total number of elements on the server and the current offset available with the count respective the offset parameter.

See lucene.apache.org/java/docs/scoring.html for more information about the scoring system used by MusicBrainz.

Defined Under Namespace

Classes: Entry

Instance Attribute Summary

Attributes inherited from Collection

#count, #offset

Instance Method Summary collapse

Methods inherited from Collection

#+, #[], #delete, #dup, #each, #empty?, #initialize, #size, #to_a

Constructor Details

This class inherits a constructor from MusicBrainz::Model::Collection

Instance Method Details

#<<(entry) ⇒ Object

Add a new entry to the collection. . Returns self.

You may either add a ScoredCollection::Entry, just an Model::Entity or an object responding to first and last where first must return the entity and last the score.

Examples:

include MusicBrainz
artist = Model::Artist.new

collection << Model::ScoredCollection::Entry.new(artist, 100)
collection << [artist, 100]
collection << artist

# Add several entities in one line
collection << artist_one << artist_two


75
76
77
# File 'lib/rbrainz/model/scored_collection.rb', line 75

def <<(entry)
  super wrap(entry)
end

#[]=(index, entry) ⇒ Object

Set the entry at the given position.

You may either add a ScoredCollection::Entry, just an Model::Entity or an object responding to first and last where first must return the entity and last the score.



84
85
86
# File 'lib/rbrainz/model/scored_collection.rb', line 84

def []=(index, entry)
  super wrap(entry)
end

#entitiesObject

Return an array of all entities.



55
56
57
# File 'lib/rbrainz/model/scored_collection.rb', line 55

def entities
  return map {|entry| entry.entity}
end

#to_collectionObject

Convert this ScoredCollection into a Collection without the scores.



89
90
91
# File 'lib/rbrainz/model/scored_collection.rb', line 89

def to_collection
  Collection.new(count, offset, entities)
end