Search
Processor operations that search for and match given items with remote items.
Searches for matches on remote APIs, matches the item to the best matching result from the query, and assigns the ID of the matched object back to the item.
Classes:
|
Stores the results of the searching process. |
|
Key settings related to a search algorithm. |
|
Searches for remote matches for a list of item collections. |
- class musify.processors.search.ItemSearchResult(matched=(), unmatched=(), skipped=())
Bases:
Result,GenericStores the results of the searching process.
Attributes:
Sequence of Items for which matches were found from the search.
Sequence of Items for which matches were not found from the search.
Sequence of Items which were skipped during the search.
-
matched:
Sequence[TypeVar(T, bound=MusifyItemSettable)] = () Sequence of Items for which matches were found from the search.
-
unmatched:
Sequence[TypeVar(T, bound=MusifyItemSettable)] = () Sequence of Items for which matches were not found from the search.
-
skipped:
Sequence[TypeVar(T, bound=MusifyItemSettable)] = () Sequence of Items which were skipped during the search.
-
matched:
- class musify.processors.search.SearchConfig(match_fields, search_fields_1=(TagFields.NAME,), search_fields_2=(), search_fields_3=(), result_count=10, min_score=0.1, max_score=0.8, allow_karaoke=False)
Bases:
objectKey settings related to a search algorithm.
Attributes:
The fields to match results on.
A sequence of the tag names to use as search fields in the 1st pass.
If no results are found from the tag names in
search_fields_1on the 1st pass, an optional sequence of the tag names to use as search fields in the 2nd pass.If no results are found from the tag names in
search_fields_2on the 2nd pass, an optional sequence of the tag names to use as search fields in the 3rd pass.The number of the results to request when querying the API.
The minimum acceptable score for an item to be considered a match.
The maximum score for an item to be considered a perfect match.
When True, items determined to be karaoke are allowed when matching added items.
-
search_fields_1:
Sequence[TagField] = (TagFields.NAME,) A sequence of the tag names to use as search fields in the 1st pass.
-
search_fields_2:
Iterable[TagField] = () If no results are found from the tag names in
search_fields_1on the 1st pass, an optional sequence of the tag names to use as search fields in the 2nd pass.
-
search_fields_3:
Iterable[TagField] = () If no results are found from the tag names in
search_fields_2on the 2nd pass, an optional sequence of the tag names to use as search fields in the 3rd pass.
-
result_count:
int= 10 The number of the results to request when querying the API.
-
min_score:
float= 0.1 The minimum acceptable score for an item to be considered a match.
-
max_score:
float= 0.8 The maximum score for an item to be considered a perfect match. After this score is reached by an item, any other items are disregarded as potential matches.
-
allow_karaoke:
bool= False When True, items determined to be karaoke are allowed when matching added items. Skip karaoke results otherwise.
-
search_fields_1:
- class musify.processors.search.RemoteItemSearcher(matcher, object_factory)
Bases:
ProcessorSearches for remote matches for a list of item collections.
- Parameters:
matcher (
ItemMatcher) – TheItemMatcherto use when comparing any changes made by the user in remote playlists during the checking operationobject_factory (
RemoteObjectFactory) – TheRemoteObjectFactoryto use when creating new remote objects. This must have aRemoteAPIassigned for this processor to work as expected.
Attributes:
The
SearchSettingsfor eachRemoteObjectTypeThe
RemoteAPIto callThe
MusifyLoggerfor this objectThe
ItemMatcherto use when comparing any changes made by the user in remote playlists during the checking operationThe
RemoteObjectFactoryto use when creating new remote objects.Methods:
search(collections)Searches for remote matches for the given list of item collections.
as_dict()Return a dictionary representation of the key attributes of this object.
-
search_settings:
dict[RemoteObjectType,SearchConfig] = {RemoteObjectType.TRACK: SearchConfig(match_fields={<TagFields.ARTIST: 32>, <TagFields.TITLE: 65>, <TagFields.ALBUM: 30>, <TagFields.LENGTH: 16>}, search_fields_1=[<TagFields.NAME: 1000>, <TagFields.ARTIST: 32>], search_fields_2=[<TagFields.NAME: 1000>, <TagFields.ALBUM: 30>], search_fields_3=[<TagFields.NAME: 1000>], result_count=10, min_score=0.1, max_score=0.8, allow_karaoke=False), RemoteObjectType.ALBUM: SearchConfig(match_fields={<TagFields.ARTIST: 32>, <TagFields.LENGTH: 16>, <TagFields.ALBUM: 30>}, search_fields_1=[<TagFields.NAME: 1000>, <TagFields.ARTIST: 32>], search_fields_2=[<TagFields.NAME: 1000>], search_fields_3=(), result_count=5, min_score=0.1, max_score=0.7, allow_karaoke=False)} The
SearchSettingsfor eachRemoteObjectType
-
logger:
MusifyLogger The
MusifyLoggerfor this object
- matcher
The
ItemMatcherto use when comparing any changes made by the user in remote playlists during the checking operation
- factory
The
RemoteObjectFactoryto use when creating new remote objects.
- async search(collections)
Searches for remote matches for the given list of item collections.
- Returns:
dict[str,ItemSearchResult[TypeVar(T, bound=MusifyItemSettable)]] – Map of the collection’s name to itsItemSearchResultobject.
- as_dict()
Return a dictionary representation of the key attributes of this object.
- Return type:
dict[str,Any]
- The results of this function are used to produce the following:
A JSON representation of the object when calling
json()The string representation of the object when calling str() on the object
The representation of the object when calling repr() on the object