Using the Search API Java Client

The Search API client allows easy usage of the commands directly from a Java application. For a description of the commands, see Search API Command Summary.

See Also
Using the HTTP Search Command
The API Client Factory

The base class to use is com.exalead.searchapi.client.SearchAPIClientFactory. You can create a SearchAPIClientFactory by specifying the root path of your Search API (for example, http://<HOSTNAME>:<BASEPORT+10>/search-api), and obtain specialized clients for each command.

For example, to perform queries on the search-api command:

SearchAPIClient client = SearchAPIClientFactory.build("http://localhost:10010");
SearchClient searchClient = client.searchClient("search-api");
SearchQuery sq = new SearchQuery("my test query");
SearchAnswer sa = searchClient.getResults(sq);

The SearchQuery class allows you to add all search parameters. The SearchQuery class provides several helpers to handle these parameters. There are four SearchAPI JAVA interfaces targeting Exalead CloudView V6, from which inherit 1 builder class per supported Exalead CloudView version:

  • CloudViewV6FacetingQueryBuilder interface

  • CloudViewV6HitsQueryBuilder interface

  • CloudViewV6RelevanceQueryBuilder interface

  • CloudViewV6DynamicSearchTargetQueryBuilder interface

For more information, see the Exalead CloudView Public APIs Java SDK documentation.

Note: The SearchClient object is thread safe. Use only one instance of the SearchClient for your whole program. It ensures that the HTTP connections are alive, to maintain request queueing without establishing useless connections to the service. To release the connections, call the close() method on the SearchClient instance.