Java SDK
The SearchUnify SDK for Java enables developers to build scalable solutions based on SearchUnify search, analytics, and crawlers. You can start in minutes using Maven or by downloading the JAR file.
Prerequisite
Ensure that your profile is in the right scope. Refer to Change User Scope (API and SDK).
How it works
The SearchUnify SDK for Java simplifies use of SearchUnify Services by providing a set of libraries that are consistent and familiar to Java developers. It provides support for the entire API life-cycle, including credential management, data marshaling, and serialization. The SDK supports higher level abstractions for simplified development.
Key Features
-
HTTP/2 Support and pluggable HTTP layer. New programming interfaces that take advantage of HTTP/2 features and provide new ways to build applications.
-
Nonblocking I/O. A new, nonblocking SDK architecture supports a true nonblocking I/O and asynchronous clients that implement high concurrency across a few threads.
Getting Started
Sign up with SearchUnify, check your system to ensure that it meets the minimum technical requirements, install the SDK, and initialize it before consuming the SearchUnify SDK for Java.
Sign up for SearchUnify
Get a SearchUnify account. Refer to the oAuth section of the developer guide for information about how to retrieve your SearchUnify credentials. Place the link to the section here.
Minimum Requirements
-
JDK 1.8+
-
Maven 3.0
Install Java SDK
The recommended way to use the SearchUnify SDK for Java in your project is to consume it from Maven. Import the JAR and specify the SDK Maven modules that your project needs in <dependencies>.
Maven <dependencies>
<dependencies>
<dependency>
<groupId>com.searchunify</groupId>
<artifactId>sdk</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Initialize Java SDK Client
Before using the SDK, initialize your client. You can access SearchUnify analytics, content and search from the client after initialization. The access token expires in 4 hours and needs to be refreshed.
Initialize Java SDK
import com.searchunify.sdk.SearchUnifyClient;
/**
* @author Fyodor Dostoevsky
* @created 30-Mar-2022
*/
public class App {
private SearchUnifyClient client;
public App() {
String key = "key";
String secret = "secret";
String baseContext = "https://yourcompany.searchunify.com";
String username = "changeme";
String password = "changeme";
this.client = new SearchUnifyClient(key, secret, baseContext, username, password, "password");
}
}
Analytics
To access analytics data you can use the analytics methods provided by SearchUnify Java SDK. There are around 22 methods.
Returns data on visitors, search users, clicks, results, cases, and other essential search behavior. The data is fetched as long as from and to are less than 30 days apart.
Parameters
Parameter | Required / Optional | Data Type |
from | Required | String |
to | Required | String |
uid | Optional | String |
Example
getTiledata()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.TileDataRequest;
import com.searchunify.sdk.dtos.TileDataResponse;
/**
* @author Guy de Maupassant
* @created 30-Jan-2030
*/
public class App {
private SearchUnifyClient client;
private void getTileData() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "1111222e-69dc-11eb-94cc-0242ac120007";
TileDataRequest request = TileDataRequest.builder().from(from).to(to).uid(uid).build();
TileDataResponse response = client.getTileData(request);
}
}
Returns how All Searches, All Searches with Results, and All Searches with Clicks (conversions) have changed over the period between from and to.
Parameters
Parameter | Required / Optional | Data Type |
from | Required | String |
to | Required | String |
uid | Optional | String |
Example
getSummaryChartData()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.GetSearchSummaryChartRequest;
import com.searchunify.sdk.dtos.GetSearchSummaryChartResponse;
/**
* @author Henry David Thoreau
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSummaryChartData() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefgh-69dc-11eb-94cc-0242ac120007";
GetSearchSummaryChartRequest request = GetSearchSummaryChartRequest.builder().from(from).to(to).uid(uid).build();
GetSearchSummaryChartResponse response = client.getSearchSummaryChart(request);
}
}
Returns the most popular search queries.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchQueryAll()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getTileDataChartRequest;
import com.searchunify.sdk.dtos.getTileDataChartResponse;
/**
* @author Jack London
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getTileData() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefgh-69dc-11eb-94cc-0242ac120007";
GetSearchQueryAllRequest request = GetSearchQueryAllRequest.builder().startDate(from).endDate(to)
.searchClientId(uid).count(10).build();
GetSearchQueryAllResponse response = client.getSearchQueryAll(request);
}
}
Returns the most popular search queries for which results were found.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchQueryWithResults()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchQueryWithResultsChartRequest;
import com.searchunify.sdk.dtos.getSearchQueryWithResultsChartResponse;
/**
* @author Andreï Makine
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchQueryWithResults() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefgh-69dc-11eb-94cc-0242ac120007";
GetSearchQueryWithResultsRequest request = GetSearchQueryWithResultsRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).count(10).build();
GetSearchQueryWithResultsResponse response = client.getSearchQueryWithResults(request);
}
}
Returns the most popular search queries for which results were found but users didn't click on any of them.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchQueryWithNoClicks()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchQueryWithNoClicksChartRequest;
import com.searchunify.sdk.dtos.getSearchQueryWithNoClicksChartResponse;
/**
* @author Liu Cixin
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchQueryWithNoClicks() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
GetSearchQueryWithNoClicksRequest request = GetSearchQueryWithNoClicksRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).count(10).build();
GetSearchQueryWithNoClicksResponse response = client.getSearchQueryWithNoClicks(request);
}
}
Returns the most popular search queries for which no results were found.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchQueryWithoutResults()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchQueryWithoutResultsChartRequest;
import com.searchunify.sdk.dtos.getSearchQueryWithoutResultsChartResponse;
/**
* @author Tsutsui Yasutaka
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchQueryWithoutResults() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcd1234-69dc-11eb-94cc-0242ac120007";
GetSearchQueryWithoutResultsRequest request = GetSearchQueryWithoutResultsRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).count(10).build();
GetSearchQueryWithoutResultsResponse response = client.getSearchQueryWithoutResults(request);
}
}
Returns search and conversion data over the period between startDate and endDate.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchQueryHistogramChartRequest;
import com.searchunify.sdk.dtos.searchQueryHistogramChartResponse;
/**
* @author Bhyrappa S.L.
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void searchQueryHistogram() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefgh1-69dc-11eb-94cc-0242ac120007";
SearchQueryHistogramRequest request = SearchQueryHistogramRequest.builder().startDate(from).endDate(to)
.searchClientId(uid).count(10).build();
SearchQueryHistogramResponse response = client.searchQueryHistogram(request);
}
}
Returns the total number of queries that didn't produce even one result. The data is for the period between startDate and endDate.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
searchQueryMissedHistogram()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchQueryMissedHistogramChartRequest;
import com.searchunify.sdk.dtos.searchQueryMissedHistogramChartResponse;
/**
* @author Zhuangzi
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void searchQueryMissedHistogram() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefghi-69dc-11eb-94cc-0242ac120007";
SearchQueryMissedHistogramRequest request = SearchQueryMissedHistogramRequest.builder().startDate(from).endDate(to)
.searchClientId(uid).count(10).build();
SearchQueryMissedHistogramResponse response = client
.searchQueryMissedHistogram(request);
}
}
Return the activity on a case.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
count | Required | Integer |
caseUID | Required | String |
Example
searchSessionByCaseUidAuth()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchSessionByCaseUidAuthChartRequest;
import com.searchunify.sdk.dtos.searchSessionByCaseUidAuthChartResponse;
/**
* @author Victor Pelevin
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void searchSessionByCaseUidAuth() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "abcdefgh-69dc-11eb-94cc-0242ac120007";
SearchSessionByCaseUidAuthRequest request = SearchSessionByCaseUidAuthRequest.builder().startDate(from)
.endDate(to).caseUID(uid).count(10).build();
SearchSessionByCaseUidAuthResponse response = client.searchSessionByCaseUidAuth(request);
}
}
Prints a list of the count most popular documents. For count=5, you get 5 results. The data is from between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchConverionAll()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchConverionAllChartRequest;
import com.searchunify.sdk.dtos.getSearchConverionAllChartResponse;
/**
* @author Valmiki
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchConverionAll() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
GetSearchConverionAllRequest request = GetSearchConverionAllRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).count(10).build();
GetSearchConverionAllResponse response = client.getSearchConverionAll(request);
}
}
Prints a list of the count documents that are not on the first page. These documents can be boosted to enhance search experience.. For count=5, you get 5 results. The data is from between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
getSearchConverionNotOnFirstPage()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchConverionNotOnFirstPageChartRequest;
import com.searchunify.sdk.dtos.getSearchConverionNotOnFirstPageChartResponse;
/**
* @author Omar Khayyam
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchConverionNotOnFirstPage() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
GetSearchConverionNotOnFirstPageRequest request = GetSearchConverionNotOnFirstPageRequest.builder().startDate(from).endDate(to).searchClientId(uid).count(10).build();
GetSearchConverionNotOnFirstPageResponse response = client.getSearchConverionNotOnFirstPage(request);
}
}
Prints a chart of the popularity (indexData) of all your content sources (indexName). The data is presented in an alphabetical order and includes: objectName, objectData, filterName, filterData, facetName, and facetName. An objectName is a content type and a filter is a high-level facet. The data is from between startDate and endDate.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
Example
getSearchConverionWithFilter()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchConverionWithFilterChartRequest;
import com.searchunify.sdk.dtos.getSearchConverionWithFilterChartResponse;
/**
* @author Gabriel García Márquez
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchConverionWithFilter() {
String from = "2021-05-25";
String to = "2021-06-01";
GetSearchConverionWithFilterRequest request = GetSearchConverionWithFilterRequest.builder().startDate(from)
.endDate(to).build();
GetSearchConverionWithFilterResponse response = client.getSearchConverionWithFilter(request);
}
}
Prints a list of the count most popular searches in a session. For count=5, you get 5 results. The data is from between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
sessionId | Required | String |
Example
getSearchConverionBySessionId()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchConverionBySessionIdChartRequest;
import com.searchunify.sdk.dtos.getSearchConverionBySessionIdChartResponse;
/**
* @author Jorge Luis Borges
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchConverionBySessionId() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String sessionId = "abcde71e11eb0242";
GetSearchConverionBySessionIdRequest request = GetSearchConverionBySessionIdRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).sessionId(sessionId).count(10).build();
GetSearchConverionBySessionIdResponse response = client.getSearchConverionBySessionId(request);
}
}
Prints count discussions that have been accessed the most and can be converted into articles. The data is from between startDate and endDate.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
count | Required | Integer |
Example
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.discussionsReadyToBecomeArticlesChartRequest;
import com.searchunify.sdk.dtos.discussionsReadyToBecomeArticlesChartResponse;
/**
* @author Saadat Hassan Manto
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void discussionsReadyToBecomeArticles() {
String from = "2021-05-25";
String to = "2021-06-01";
DiscussionsReadyToBecomeArticlesRequest request = DiscussionsReadyToBecomeArticlesRequest.builder()
.startDate(from).endDate(to).count(10).build();
DiscussionsReadyToBecomeArticlesResponse response = client.discussionsReadyToBecomeArticles(request);
}
}
View the list of articles that were consulted before a user created a case.
Parameters
Parameter | Required / Optional | Data Type |
uid | Required | String |
startDate | Required | String |
endDate | Required | String |
internalUser | Required | True, False, or All |
searchType | Required | all, global, or support |
limit | Optional | Integer |
offset | Optional | Integer |
Example
articlesCreatedCases()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.articlesCreatedCasesChartRequest;
import com.searchunify.sdk.dtos.articlesCreatedCasesChartResponse;
/**
* @author José Saramago
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void articlesCreatedCases() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String searchType = "global";
String internalUser = "false";
ArticlesCreatedCasesRequest request = ArticlesCreatedCasesRequest request = ArticlesCreatedCasesRequest.builder().from(from).to(to).uid(uid)
.internalUser(internalUser).searchType(searchType).offset(0).limit(10).build();
ArticlesCreatedCasesResponse response = client.articlesCreatedCases(request);
}
}
Returns the articles that were consulted by users who didn't create a case.
Parameters
Parameter | Required / Optional | Data Type |
uid | Required | String |
startDate | Required | String |
endDate | Required | String |
internalUser | Required | True, False, or All |
searchType | Required | all, global, or support |
limit | Optional | Integer |
offset | Optional | Integer |
Example
articlesDeflectedCase()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.articlesDeflectedCaseChartRequest;
import com.searchunify.sdk.dtos.articlesDeflectedCaseChartResponse;
/**
* @author Nikolai Gogol
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void articlesDeflectedCase() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String searchType = "global";
String internalUser = "false";
ArticlesDeflectedCaseRequest request = ArticlesDeflectedCaseRequest.builder().from(from).to(to).uid(uid) .internalUser(internalUser).searchType(searchType).offset(0).limit(10).build();
ArticlesDeflectedCaseResponse response = client.articlesDeflectedCase(request);
}
}
Find out how many articles have been attached to cases.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
caseUID | Required | String |
internalUser | Required | True, False, or All |
limit | Optional | Integer |
offset | Optional | Integer |
Example
articlesAttachedToCases()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.articlesAttachedToCasesChartRequest;
import com.searchunify.sdk.dtos.articlesAttachedToCasesChartResponse;
/**
* @author Osamu Dazai
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void articlesAttachedToCases() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String searchType = "global";
String internalUser = "false";
ArticlesAttachedToCasesRequest request = ArticlesAttachedToCasesRequest.builder().from(from).to(to).uid(uid)
.internalUser(internalUser).searchType(searchType).offset(0).limit(10).build();
ArticlesAttachedToCasesResponse response = client.articlesAttachedToCases(request);
}
}
Prints a list of the count search sessions and the searches conducted in each session. For count=5, you get 5 results. The data is from between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
count | Required | Integer |
Example
Prints the number of articles generated on your cases between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Optional | String |
Example
searchQueryKcsSupport()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchQueryKcsSupportChartRequest;
import com.searchunify.sdk.dtos.searchQueryKcsSupportChartResponse;
/**
* @author Lu Xun
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void searchQueryKcsSupport() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
SearchQueryKcsSupportRequest request = SearchQueryKcsSupportRequest.builder().startDate(from).endDate(to)
.searchClientId(uid).build();
SearchQueryKcsSupportResponse response = client.searchQueryKcsSupport(request);
}
}
Provides search, conversion, page views, case deflection, and case creation data for the argument caseUid.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
caseUID | Required | String |
Example
searchSessionByCaseUid()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchSessionByCaseUidChartRequest;
import com.searchunify.sdk.dtos.searchSessionByCaseUidChartResponse;
/**
* @author Kobo Abe
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void searchSessionByCaseUid() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "23456781-11eb-94cc-0242ac120007";
SearchSessionByCaseUidRequest request = SearchSessionByCaseUidRequest.builder().startDate(from).endDate(to)
.caseUID(uid).build();
SearchSessionByCaseUidResponse response = client.searchSessionByCaseUid(request);
}
}
Prints a list of the count queries in a search session and the documents accessed during that session. For count=5, you get 5 results. The data is from between startDate and endDate on a search client whose ID is searchClientID. If the searchClientID is not specified, then the call fetches data from all the search clients.
Parameters
Parameter | Required / Optional | Data Type |
startDate | Required | String |
endDate | Required | String |
searchClientId | Required | String |
count | Required | Integer |
sessionId | Optional | String |
Example
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getSearchSessionBySearchSessionIdChartRequest;
import com.searchunify.sdk.dtos.getSearchSessionBySearchSessionIdChartResponse;
/**
* @author Rabindernath Tagore
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getSearchSessionBySearchSessionId() {
String from = "2021-05-25";
String to = "2021-06-01";
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String sessionId = "5815771691194";
GetSearchSessionBySessionIdRequest request = GetSearchSessionBySessionIdRequest.builder().startDate(from)
.endDate(to).searchClientId(uid).sessionId(sessionId).count(10).build();
GetSearchSessionBySessionIdResponse response = client.getSearchSessionBySessionId(request);
}
}
Content
This section includes the methods for content source SDKs.
This function returns all the added content sources.
getAllContentSources()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getAllContentSourcesChartRequest;
import com.searchunify.sdk.dtos.getAllContentSourcesChartResponse;
/**
* @author Lev Tolstoy
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getAllContentSources() {
GetAllContentSourcesRequest request = new GetAllContentSourcesRequest();
GetAllContentSourcesResponse response = client.getAllContentSources(request);
}
}
Returns the id, label, name, url, and size of a content source, where size is the number of documents stored in the content source.
Parameters
Parameter | Required / Optional | Data Type |
id | Required | String |
Example
getContentSourcesById()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getContentSourcesByIdChartRequest;
import com.searchunify.sdk.dtos.getContentSourcesByIdChartResponse;
/**
* @author Gurdial Singh
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getContentSourcesById() {
String id = "12345678-69dc-11eb-94cc-0242ac120007";
GetContentSourceByIdRequest request = GetContentSourceByIdRequest.builder().id(id).build();
GetContentSourceByIdResponse response = client.getContentSourcesById(request);
}
}
Lists all the objects and fields of a content source in an array. Each element in the array is an object. Each object has four properties: id, label, name, and fields.
The fields element is also an object with six properties: id, name, label, type, isFilterable, and isSearchable. The type property can be an int, a boolean, or a string. isFilterable is a boolean object. If it is true, then the field is used as a facet. isSearchable is also a boolean object. If it is true, then the data stored in the field can be found through search.
Parameters
Parameter | Required / Optional | Data Type |
id | Required | String |
Example
getContentSourceObjectAndFields()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getContentSourceObjectAndFieldsChartRequest;
import com.searchunify.sdk.dtos.getContentSourceObjectAndFieldsChartResponse;
/**
* @author Fazil Iskander
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getContentSourceObjectAndFields() {
String id = "12345678-69dc-11eb-94cc-0242ac120007";
GetContentSourceObjectAndFieldsRequest request = GetContentSourceObjectAndFieldsRequest.builder().id(id)
.build();
GetContentSourceObjectAndFieldsResponse response = client.getContentSourceObjectAndFields(request);
}
}
Return data for document specified by its content source id, object id, and document id.
Parameters
Parameter | Required / Optional | Data Type |
contentSourceId | Required | String |
objectId | Required | String |
documentId | Required | String |
Example
getAllDocumentInContentSource()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getAllDocumentInContentSourceChartRequest;
import com.searchunify.sdk.dtos.getAllDocumentInContentSourceChartResponse;
/**
* @author Nikos Kazantzakis
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getAllDocumentInContentSource() {
String contentSourceId = "12345678-69dc-11eb-94cc-0242ac120007";
String objectId = "12345678-69dc-11eb-94cc-0242ac120007";
String documentId = "12345678-69dc-11eb-94cc-0242ac120007";
GetAllDocumentInContentSourceRequest request = GetAllDocumentInContentSourceRequest.builder()
.contentSourceId(contentSourceId).objectId(objectId).documentId(documentId).build();
GetAllDocumentInContentSourceResponse response = client.getAllDocumentInContentSource(request);
}
}
Update a content field or a document property in your index. The changes are reflected in your index. This call does not alter data on your content source. For instance, you can update a document title in the index without changing it in the content source.
Parameters
Parameter | Required / Optional | Data Type |
contentSourceId | Required | String |
objectId | Required | String |
documentId | Required | String |
body | Required | Map |
Example
updateDocument()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.getAllDocumentInContentSourceChartRequest;
import com.searchunify.sdk.dtos.getAllDocumentInContentSourceChartResponse;
/**
* @author Chinua Achebe
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void getAllDocumentInContentSource() {
Map<String, Object> body = new HashMap<>();
body.put("name", "chinua");
body.put("age", 31);
body.put("designation", "technical architect");
body.put("company", "SearchUnify");
String contentSourceId = "12345678-69dc-11eb-94cc-0242ac120007";
String objectId = "12345678-69dc-11eb-94cc-0242ac120007";
String documentId = "12345678-69dc-11eb-94cc-0242ac120007";
UpdateDocumentRequest request = UpdateDocumentRequest.builder().contentSourceId(contentSourceId) .objectId(objectId).documentId(documentId).body(body).build();
UpdateDocumentResponse response = client.updateDocument(request);
}
}
Add one or more documents to your search index. bulkUpload can be used instead of crawling from the Admin Console when:
-
You have only a few documents to add and you don't want to recrawl a large content source.
-
You want to insert new documents into the search index without first deleting it, which happens when an admin crawls from the Admin Console
Parameters
Parameter | Required / Optional | Data Type |
contentSourceId | Required | String |
objectId | Required | String |
body | Required | Map |
Example
bulkUploadDocuments()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.bulkUploadDocumentsChartRequest;
import com.searchunify.sdk.dtos.bulkUploadDocumentsChartResponse;
/**
* @author Ngũgĩ wa Thiong'o
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void bulkUploadDocuments() {
List<Map<String, Object>> bulkList = new ArrayList<>();
Map<String, Object> b1 = new HashMap<>();
b1.put("name", "liucixin");
b1.put("age", 31);
b1.put("designation", "technical architect");
b1.put("company", "SearchUnify");
Map<String, Object> b2 = new HashMap<>();
b2.put("name", "bhyrappa");
b2.put("age", 31);
b2.put("designation", "technical writer");
b2.put("company", "SearchUnify");
bulkList.add(b1);
bulkList.add(b2);
String contentSourceId = "12345678-69dc-11eb-94cc-0242ac120007";
String objectId = "12345678-69dc-11eb-94cc-0242ac120007";
BulkUploadDocumentRequest request = BulkUploadDocumentRequest.builder().contentSourceId(contentSourceId)
.objectId(objectId).bulkData(bulkList).build();
BulkUploadDocumentResponse response = client.bulkUploadDocuments(request);
}
}
Search
SDK has a search API to make content searchable. You just need to pass parameters as per requirement.
View search results on a platform of your choice.
Parameters
Parameter | Optional / Required | Description | Data Type |
---|---|---|---|
uid
|
Required | It is your search client ID. You can find it in Search Clients > UID (column). | string |
searchString
|
Required | It is the search query. | string |
email
|
Optional | This parameter is used establish the searcher's identity and tailor search results based on that identity. An admin email might fetch results different from a moderator email. | string |
orderBy
|
Optional | It has two values, asc and desc . If orderby=desc , then the order in which the results are presented is reversed. The last result will be ranked first, the penultimate result second, and so on. The default value of orderBy is asc . |
string |
sortby
|
Optional | It can have two values, _score or _post_time . When sortby=_score , then the documents with the highest score are presented first. When sortby=_post_time , then the lastest documents are on top. |
string |
exactPhrase
|
Optional | It treats all the words in the search query as one contiguous string. exactPhrase=salesforce console becomes "salesforce console". |
string |
withOneOrMore
|
Optional | When used, it inserts the Boolean operator OR between each pair of keywords. withOneOrMore=salesforce console becomes "salesforce OR console". |
string |
withoutTheWords
|
Optional | This parameter inserts the Boolean operator NOT before each keyword. withoutTheWords=salesforce console becomes "NOT salesforce NOT console" |
string |
from
|
Optional | It's an offset. If from="10" , then the call will ignore the top 10 results and fetch results starting from the document ranked 11. |
string |
resultsPerPage
|
Optional | If resultsPerPage=30 , then each search will produce 30 results on each page. |
string |
indexEnabled
|
Optional | The content sources tabs are hidden if indexEnabled is set to false . In the default state, indexEnabled=true . |
boolean |
aggregations
|
Optional | aggregations is used to refine your search with facets. For example: type: ${facet name}, filter: [ ${facet filter name1}, ${facet filter name2} ] . A common pattern for nested facets is [{type: ${facet name},children: [ childname: ${facet child name1}, level: ${facet level} ]}] |
object |
pagingAggregation
|
Optional | It is used if your goal is to display all your facets. {key: ${facet name},keyword: ${facet search keyword},offset: ${number of filters to shown}} |
object |
pageNo
|
Optional | Returns search results from the specified page number. If pageNo==5 , then the results from the fifth page will be returned. |
|
sid
|
Optional | Attaches session ID(s) to the returned data. | |
language
|
Optional | Returns results in the specified language. language=zh returns Chinese results. |
|
versionResults
|
Optional | Merge multiple versions of a doc into a result. | |
getAutoTunedResult
|
Optional | Returns auto tuned results. Works only if Auto Spell Corrector and Facet Interpretor are enabled in the instance. | |
getSimilarSearches
|
Optional | Returns results from the similar searches tab. Works only if Similar Searches is turned on in the instance. | |
mergeSources
|
Optional | Groups results by content sources. Works only if Customize Search Client View is turned on in the instance. |
Salesforce-Specific Parameters
Parameter | Optional / Required | Description | Data Type |
---|---|---|---|
UserId
|
Optional | Your user ID. | string |
UserType
|
Optional | Your user type. For example, Standard, Admin, and Developer. | string |
AccountId
|
Optional | Your Salesforce ID. | string |
ProfileId
|
Optional | Your profile ID in your org. | string |
ContactId
|
Optional | Your contact ID. | string |
Lithium-Specific Parameters
Parameter | Optional / Required | Description | Data Type |
---|---|---|---|
boardsArr
|
Required | It limits search to the boards specified in boardsArr . |
string |
Example
search()
import com.searchunify.sdk.SearchUnifyClient;
import com.searchunify.sdk.dtos.searchChartRequest;
import com.searchunify.sdk.dtos.searchChartResponse;
/**
* @author Arthur C Clarke
* @created 30-Mar-2021
*/
public class App {
private SearchUnifyClient client;
private void search() {
String uid = "12345678-69dc-11eb-94cc-0242ac120007";
String searchString = "search query here";
SearchRequest request = SearchRequest.builder().uid(uid).searchString(searchString).build();
SearchResponse response = client.search(request);
}
}