Files
plexjava/src/main/java/dev/plexapi/sdk/AsyncSearch.java

221 lines
13 KiB
Java

/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
package dev.plexapi.sdk;
import static dev.plexapi.sdk.operations.Operations.AsyncRequestOperation;
import dev.plexapi.sdk.models.operations.GetSearchResultsRequest;
import dev.plexapi.sdk.models.operations.PerformSearchRequest;
import dev.plexapi.sdk.models.operations.PerformVoiceSearchRequest;
import dev.plexapi.sdk.models.operations.async.GetSearchResultsRequestBuilder;
import dev.plexapi.sdk.models.operations.async.GetSearchResultsResponse;
import dev.plexapi.sdk.models.operations.async.PerformSearchRequestBuilder;
import dev.plexapi.sdk.models.operations.async.PerformSearchResponse;
import dev.plexapi.sdk.models.operations.async.PerformVoiceSearchRequestBuilder;
import dev.plexapi.sdk.models.operations.async.PerformVoiceSearchResponse;
import dev.plexapi.sdk.operations.GetSearchResults;
import dev.plexapi.sdk.operations.PerformSearch;
import dev.plexapi.sdk.operations.PerformVoiceSearch;
import java.lang.Double;
import java.lang.String;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
* API Calls that perform search operations with Plex Media Server
*/
public class AsyncSearch {
private final SDKConfiguration sdkConfiguration;
private final Search syncSDK;
AsyncSearch(Search syncSDK, SDKConfiguration sdkConfiguration) {
this.sdkConfiguration = sdkConfiguration;
this.syncSDK = syncSDK;
}
/**
* Switches to the sync SDK.
*
* @return The sync SDK
*/
public Search sync() {
return syncSDK;
}
/**
* Perform a search
*
* <p>This endpoint performs a search across all library sections, or a single section, and returns matches as hubs, split up by type. It performs spell checking, looks for partial matches, and orders the hubs based on quality of results. In addition, based on matches, it will return other related matches (e.g. for a genre match, it may return movies in that genre, or for an actor match, movies with that actor).
*
* <p>In the response's items, the following extra attributes are returned to further describe or disambiguate the result:
*
* <p>- `reason`: The reason for the result, if not because of a direct search term match; can be either:
* - `section`: There are multiple identical results from different sections.
* - `originalTitle`: There was a search term match from the original title field (sometimes those can be very different or in a foreign language).
* - `&lt;hub identifier&gt;`: If the reason for the result is due to a result in another hub, the source hub identifier is returned. For example, if the search is for "dylan" then Bob Dylan may be returned as an artist result, an a few of his albums returned as album results with a reason code of `artist` (the identifier of that particular hub). Or if the search is for "arnold", there might be movie results returned with a reason of `actor`
* - `reasonTitle`: The string associated with the reason code. For a section reason, it'll be the section name; For a hub identifier, it'll be a string associated with the match (e.g. `Arnold Schwarzenegger` for movies which were returned because the search was for "arnold").
* - `reasonID`: The ID of the item associated with the reason for the result. This might be a section ID, a tag ID, an artist ID, or a show ID.
*
* <p>This request is intended to be very fast, and called as the user types.
*
* @return The async call builder
*/
public PerformSearchRequestBuilder performSearch() {
return new PerformSearchRequestBuilder(sdkConfiguration);
}
/**
* Perform a search
*
* <p>This endpoint performs a search across all library sections, or a single section, and returns matches as hubs, split up by type. It performs spell checking, looks for partial matches, and orders the hubs based on quality of results. In addition, based on matches, it will return other related matches (e.g. for a genre match, it may return movies in that genre, or for an actor match, movies with that actor).
*
* <p>In the response's items, the following extra attributes are returned to further describe or disambiguate the result:
*
* <p>- `reason`: The reason for the result, if not because of a direct search term match; can be either:
* - `section`: There are multiple identical results from different sections.
* - `originalTitle`: There was a search term match from the original title field (sometimes those can be very different or in a foreign language).
* - `&lt;hub identifier&gt;`: If the reason for the result is due to a result in another hub, the source hub identifier is returned. For example, if the search is for "dylan" then Bob Dylan may be returned as an artist result, an a few of his albums returned as album results with a reason code of `artist` (the identifier of that particular hub). Or if the search is for "arnold", there might be movie results returned with a reason of `actor`
* - `reasonTitle`: The string associated with the reason code. For a section reason, it'll be the section name; For a hub identifier, it'll be a string associated with the match (e.g. `Arnold Schwarzenegger` for movies which were returned because the search was for "arnold").
* - `reasonID`: The ID of the item associated with the reason for the result. This might be a section ID, a tag ID, an artist ID, or a show ID.
*
* <p>This request is intended to be very fast, and called as the user types.
*
* @param query The query term
* @return CompletableFuture&lt;PerformSearchResponse&gt; - The async response
*/
public CompletableFuture<PerformSearchResponse> performSearch(String query) {
return performSearch(query, Optional.empty(), Optional.empty());
}
/**
* Perform a search
*
* <p>This endpoint performs a search across all library sections, or a single section, and returns matches as hubs, split up by type. It performs spell checking, looks for partial matches, and orders the hubs based on quality of results. In addition, based on matches, it will return other related matches (e.g. for a genre match, it may return movies in that genre, or for an actor match, movies with that actor).
*
* <p>In the response's items, the following extra attributes are returned to further describe or disambiguate the result:
*
* <p>- `reason`: The reason for the result, if not because of a direct search term match; can be either:
* - `section`: There are multiple identical results from different sections.
* - `originalTitle`: There was a search term match from the original title field (sometimes those can be very different or in a foreign language).
* - `&lt;hub identifier&gt;`: If the reason for the result is due to a result in another hub, the source hub identifier is returned. For example, if the search is for "dylan" then Bob Dylan may be returned as an artist result, an a few of his albums returned as album results with a reason code of `artist` (the identifier of that particular hub). Or if the search is for "arnold", there might be movie results returned with a reason of `actor`
* - `reasonTitle`: The string associated with the reason code. For a section reason, it'll be the section name; For a hub identifier, it'll be a string associated with the match (e.g. `Arnold Schwarzenegger` for movies which were returned because the search was for "arnold").
* - `reasonID`: The ID of the item associated with the reason for the result. This might be a section ID, a tag ID, an artist ID, or a show ID.
*
* <p>This request is intended to be very fast, and called as the user types.
*
* @param query The query term
* @param sectionId This gives context to the search, and can result in re-ordering of search result hubs
* @param limit The number of items to return per hub
* @return CompletableFuture&lt;PerformSearchResponse&gt; - The async response
*/
public CompletableFuture<PerformSearchResponse> performSearch(
String query, Optional<Double> sectionId,
Optional<Double> limit) {
PerformSearchRequest request =
PerformSearchRequest
.builder()
.query(query)
.sectionId(sectionId)
.limit(limit)
.build();
AsyncRequestOperation<PerformSearchRequest, PerformSearchResponse> operation
= new PerformSearch.Async(sdkConfiguration);
return operation.doRequest(request)
.thenCompose(operation::handleResponse);
}
/**
* Perform a voice search
*
* <p>This endpoint performs a search specifically tailored towards voice or other imprecise input which may work badly with the substring and spell-checking heuristics used by the `/hubs/search` endpoint.
* It uses a [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) heuristic to search titles, and as such is much slower than the other search endpoint.
* Whenever possible, clients should limit the search to the appropriate type.
* Results, as well as their containing per-type hubs, contain a `distance` attribute which can be used to judge result quality.
*
* @return The async call builder
*/
public PerformVoiceSearchRequestBuilder performVoiceSearch() {
return new PerformVoiceSearchRequestBuilder(sdkConfiguration);
}
/**
* Perform a voice search
*
* <p>This endpoint performs a search specifically tailored towards voice or other imprecise input which may work badly with the substring and spell-checking heuristics used by the `/hubs/search` endpoint.
* It uses a [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) heuristic to search titles, and as such is much slower than the other search endpoint.
* Whenever possible, clients should limit the search to the appropriate type.
* Results, as well as their containing per-type hubs, contain a `distance` attribute which can be used to judge result quality.
*
* @param query The query term
* @return CompletableFuture&lt;PerformVoiceSearchResponse&gt; - The async response
*/
public CompletableFuture<PerformVoiceSearchResponse> performVoiceSearch(String query) {
return performVoiceSearch(query, Optional.empty(), Optional.empty());
}
/**
* Perform a voice search
*
* <p>This endpoint performs a search specifically tailored towards voice or other imprecise input which may work badly with the substring and spell-checking heuristics used by the `/hubs/search` endpoint.
* It uses a [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) heuristic to search titles, and as such is much slower than the other search endpoint.
* Whenever possible, clients should limit the search to the appropriate type.
* Results, as well as their containing per-type hubs, contain a `distance` attribute which can be used to judge result quality.
*
* @param query The query term
* @param sectionId This gives context to the search, and can result in re-ordering of search result hubs
* @param limit The number of items to return per hub
* @return CompletableFuture&lt;PerformVoiceSearchResponse&gt; - The async response
*/
public CompletableFuture<PerformVoiceSearchResponse> performVoiceSearch(
String query, Optional<Double> sectionId,
Optional<Double> limit) {
PerformVoiceSearchRequest request =
PerformVoiceSearchRequest
.builder()
.query(query)
.sectionId(sectionId)
.limit(limit)
.build();
AsyncRequestOperation<PerformVoiceSearchRequest, PerformVoiceSearchResponse> operation
= new PerformVoiceSearch.Async(sdkConfiguration);
return operation.doRequest(request)
.thenCompose(operation::handleResponse);
}
/**
* Get Search Results
*
* <p>This will search the database for the string provided.
*
* @return The async call builder
*/
public GetSearchResultsRequestBuilder getSearchResults() {
return new GetSearchResultsRequestBuilder(sdkConfiguration);
}
/**
* Get Search Results
*
* <p>This will search the database for the string provided.
*
* @param query The search query string to use
* @return CompletableFuture&lt;GetSearchResultsResponse&gt; - The async response
*/
public CompletableFuture<GetSearchResultsResponse> getSearchResults(String query) {
GetSearchResultsRequest request =
GetSearchResultsRequest
.builder()
.query(query)
.build();
AsyncRequestOperation<GetSearchResultsRequest, GetSearchResultsResponse> operation
= new GetSearchResults.Async(sdkConfiguration);
return operation.doRequest(request)
.thenCompose(operation::handleResponse);
}
}