com.seanjstory.workplace.search:workplace-search-sdk

A Java SDK for building Workplace Search Custom API Sources

License

License

Categories

Categories

Search Business Logic Libraries
GroupId

GroupId

com.seanjstory.workplace.search
ArtifactId

ArtifactId

workplace-search-sdk
Last Version

Last Version

7.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

A Java SDK for building Workplace Search Custom API Sources

Download workplace-search-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/com.seanjstory.workplace.search/workplace-search-sdk/ -->
<dependency>
    <groupId>com.seanjstory.workplace.search</groupId>
    <artifactId>workplace-search-sdk</artifactId>
    <version>7.8.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.seanjstory.workplace.search/workplace-search-sdk/
implementation 'com.seanjstory.workplace.search:workplace-search-sdk:7.8.0'
// https://jarcasting.com/artifacts/com.seanjstory.workplace.search/workplace-search-sdk/
implementation ("com.seanjstory.workplace.search:workplace-search-sdk:7.8.0")
'com.seanjstory.workplace.search:workplace-search-sdk:jar:7.8.0'
<dependency org="com.seanjstory.workplace.search" name="workplace-search-sdk" rev="7.8.0">
  <artifact name="workplace-search-sdk" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.seanjstory.workplace.search', module='workplace-search-sdk', version='7.8.0')
)
libraryDependencies += "com.seanjstory.workplace.search" % "workplace-search-sdk" % "7.8.0"
[com.seanjstory.workplace.search/workplace-search-sdk "7.8.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.seanjstory.workplace.search : workplace-search-client jar 7.8.0
org.yaml : snakeyaml jar 1.21

test (3)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.0-groovy-2.4
cglib : cglib-nodep jar 3.2.4
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Workplace Search - Java APIs

A JVM client and SDK for Elastic Workplace Search

Building

To build, run:

mvn clean install

As a Dependency

To use the JVM client for Workplace Search, add:

            <dependency>
                <groupId>com.seanjstory.workplace.search</groupId>
                <artifactId>workplace-search-client</artifactId>
                <version>7.9.0-SNAPSHOT</version>
            </dependency>

To use the JVM SDK for Custom API Sources for Workplace Search, add:

            <dependency>
                <groupId>com.seanjstory.workplace.search</groupId>
                <artifactId>workplace-search-sdk</artifactId>
                <version>7.9.0-SNAPSHOT</version>
            </dependency>

Usage

Client

The client requires an accessToken, and most of the APIs also require a contentSourceKey. Both can be found in the Workplace Search UI after creating a Custom API source. Using the client is as easy as:

import com.seanjstory.workplace.search.client.Client;
//...
String accessToken = "3a423c597442eddb09baad64793ff342fc0aa6da357f5227888d44b3386cf722";
String contentSourceKey = "5e8f5266f74c321dae6e5548";

Client client = new Client(accessToken);

Map<String,String> document = Collections.singletonMap("id", "someId")
List<Map<String, Object>> documents = Collections.singletonList(document)

client.indexDocuments(contentSourceKey, documents)

SDK

For experiential learners, the best way to see the SDK in action might be to look at a simple example.

The Workplace Search Java SDK is intended to help develop Custom API sources. To leverage it, it's worth understanding what is in the module.

.
└── com.seanjstory.workplace.search.sdk
    ├── api
    │   ├── DocumentBase.java     # Abstract Class
    │   ├── Source.java           # Interface
    │   ├── SourcesUtils.java     # Concrete Utility
    │   ├── YamlConfig.java       # Concrete Utility
    │   └── Yielder.java          # Abstract Utility
    └── run
        └── Sync.java             # Concrete Utility
  • The DocumentBase class provides the base API for "documents". Every document should have an id and a body. Most documents will have other metadata as well (URL, Title, Last Modified Date, etc).
  • The Source interface is merely defined as a class that provides an Iterator<? extends DocumentBase>.
  • The SourcesUtils class is a lightweight approach to dependency injection. It will look for a sources resource in your classloader's resources, expecting to find a line-separated list of Source implementation cannonical names. The SourceUtils can then be used to instantiate a source, given its name, and optionally a list of String arguments.
  • The YamlConfig class is a lightweight adapter for a YAML config file that can be used store your Access Token, Content Source Key, and any arguments necessary to instantiate your Sources (in conjunction with SourcesUtils).
  • The Yielder is the recommended mechanism through which your Source implementations might provide an Iterator. Many sources may contain so many documents (and such large documents), that it becomes difficult to handle them all in a single collection. This lazy evaluator is easy to leverage, and can help you to keep only a small number of documents in memory at a given time.
  • Finally, the Sync class provides a main function that drive your source. It expects two arguments, a path to a YAML configuration file (see YamlConfig) and a source name (see SourcesUtils). From these, it will instantiate a Source, connect to Workplace Search with a Java Client, and iterate over your documents, indexing them in batches of 100.

Versions

Version
7.8.0