Inherits from NSObject
Conforms to NSURLConnectionDataDelegate
NSURLConnectionDelegate
Declared in STAPIClient.h
STAPIClient.m

Overview

The STAPIClient is used to communicate with the Swiftype search servers. In order to work correctly it must have a delegate that defines the search parameters as well as an engine key. Details on the search parameters can be found here: http://swiftype.com/documentation/searching. An search engine’s key can be found within the account’s dashboard: http://swiftype.com/home.

The STAPIClient client is meant to run exactly 1 query at a time. If a query is pending (waiting for the server to respond) when another query is issued then that first query is canceled. A query will start and then finish or be canceled or fail. A query cannot for example fail and be canceled for the same request.

The client offers two types of queries: search and suggest. More detailed information on suggest queries can be found here http://swiftype.com/documentation/autocomplete.

It is not common to use STAPIClient directly. Instead it is recommended to use STSearchResultsObject or one of its subclasses.

Tasks

Properties

delegate

The delegate which will provide parameter data and receive messages related to the query

@property (nonatomic, weak) id<STAPIClientDelegate> delegate

Discussion

The delegate which will provide parameter data and receive messages related to the query

Declared In

STAPIClient.h

engineKey

Key to the engine that queries will run against

@property (nonatomic, copy) NSString *engineKey

Discussion

Key to the engine that queries will run against

Declared In

STAPIClient.h

Class Methods

clearAPICache

Clear the cache that is used by all instance of STAPIClient

+ (void)clearAPICache

Discussion

Clear the cache that is used by all instance of STAPIClient

Declared In

STAPIClient.h

Instance Methods

cancelQuery

Cancel any pending requests with the search server

- (void)cancelQuery

Discussion

Cancel any pending requests with the search server

Declared In

STAPIClient.h

initWithApiKey:

Initializes a new STAPIClient

- (id)initWithApiKey:(NSString *)engineKey

Parameters

engineKey

The key of the engine that queries will be run against

Discussion

Initializes a new STAPIClient

Declared In

STAPIClient.h

postClickAnalyticsForQuery:withType:documentId:

Used to log user interaction with the search results. This is typically called by the STSearchResultObjects postClickAnalyticsWithDocumentId method.

- (void)postClickAnalyticsForQuery:(NSString *)query withType:(STSearchType)type documentId:(NSString *)documentId

Parameters

query

The query the that was run against the server that found a particular result

type

The search type. Whether it was a suggest or a search query.

documentId

The id of the document that was selected.

Discussion

Used to log user interaction with the search results. This is typically called by the STSearchResultObjects postClickAnalyticsWithDocumentId method.

It is the responsibility of custom UI to call this once a user has selected a search result.

Declared In

STAPIClient.h

searchQuery:

Starts a new search query with the server. By default the query will request only the first 20 results for each document type.

- (void)searchQuery:(NSString *)query

Parameters

query

The query to be used in the search

If an existing suggest or search query is already waiting for a server response then it will be canceled in order for the new query to begin. The delegates query cancel method will be called for the canceled query.

Discussion

Starts a new search query with the server. By default the query will request only the first 20 results for each document type.

Declared In

STAPIClient.h

searchQuery:page:perPage:

Starts a new search query with the server for a specific page and certain number of results.

- (void)searchQuery:(NSString *)query page:(NSUInteger)page perPage:(NSUInteger)perPage

Parameters

query

The query to be used in the search

page

The page to request

perPage

Maximum number of items per page

If an existing suggest or search query is already waiting for a server response then it will be canceled in order for the new query to begin. The delegates query cancel method will be called for the canceled query.

Discussion

Starts a new search query with the server for a specific page and certain number of results.

Declared In

STAPIClient.h

suggestQuery:

Starts a new suggest query with the server. By default the query will request only the first 20 results for each document type.

- (void)suggestQuery:(NSString *)query

Parameters

query

The query to send to the server

If an existing suggest or search query is already waiting for a server response then it will be canceled in order for the new query to begin. The delegates query cancel method will be called for the canceled query.

Discussion

Starts a new suggest query with the server. By default the query will request only the first 20 results for each document type.

Declared In

STAPIClient.h