Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Penny committed Aug 2, 2022
1 parent 883497b commit c6520d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ composer require "silverstripe/silverstripe-search-service"

## Requirements

* silverstripe/framework 4.4+
* silverstripe/versioned
* symbiote/silverstripe-queuedjobs
* php: ^8.0
* guzzlehttp/guzzle: ^7
* symbiote/silverstripe-queuedjobs: ^4
* elastic/enterprise-search: ^8.3
* silverstripe/versioned: ^1

## Documentation

Expand Down
38 changes: 30 additions & 8 deletions docs/en/customising_add_search_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@ This method is responsible for adding a single document to the indexes. Keep in
`DocumentInterface` object that is passed to this function is self-aware of the indexes
it is assigned to. Be sure to check each item's `shouldIndex()` method, as well.

Return value should be the unique ID of the document.

```php
public function addDocument(DocumentInterface $item): self
public function addDocument(DocumentInterface $item): ?string
{
if (!$item->shouldIndex()) {
return $this;
}
$fields = DocumentBuilder::singleton()->toArray($item);
$indexes = IndexConfiguration::singleton()->getIndexesForDocument($item);
foreach (array_keys($indexes) as $indexName) {
// your custom API call here
$mySearchClient->addDocuementToIndex(
static::environmentizeIndex($indexName),
$fields
);
}
return $item->getIdentifier();
}
```
Expand All @@ -77,11 +82,13 @@ that the `addDocument()` method works as a proxy for `addDocuments()`, e.g.
]
```

### removeDocument(DocumentInterface $doc): self
### removeDocument(DocumentInterface $doc): ?string

Removes a document from its indexes.

```php
Return value should be the unique ID of the document.

```php
public function removeDocument(DocumentInterface $doc): ?string
{
$indexes = IndexConfiguration::singleton()->getIndexesForDocument($doc);
Expand All @@ -98,12 +105,14 @@ public function removeDocument(DocumentInterface $doc): ?string
}
```

### removeDocuments(array $items): self
### removeDocuments(array $items): array

Same as `removeDocument()`, but accepts an array of `DocumentInterface` objects. It is recommended
that the `removeDocument()` method works as a proxy for `removeDocuments()`, e.g.
`$this->removeDocuments([$item])`.

Return value should be an array of the Document IDs that were removed

**Tip**: Build a map of index names to documents to minimise calls to your API.

```php
Expand All @@ -113,7 +122,7 @@ that the `removeDocument()` method works as a proxy for `removeDocuments()`, e.g
]
```

### getDocument(string $id): ?array
### getDocument(string $id): ?DocumentInterface

Gets a single document from an index. Should check each index and get the first one to match it.

Expand All @@ -126,6 +135,7 @@ public function getDocument(string $id): ?array
static::environmentizeIndex($indexName),
$id
);
if ($result) {
return DocumentBuilder::singleton()->fromArray($result);
}
Expand All @@ -140,17 +150,21 @@ public function getDocument(string $id): ?array
to your indexing service. (See the `ConfigurationAware` trait).


### getDocuments(array $ids): self
### getDocuments(array $ids): array

Same as `getDocument()`, but accepts an array of identifiers. It is recommended
that the `getDocument()` method works as a proxy for `rgetDocuments()`, e.g.
`$this->getDocuments([$id])`.

return type should be an array of `DocumentInterface`.

### listDocuments(string $indexName, ?int $limit = null, int $offset = 0): array

This method is expected to list all documents in a given index, with some pagination
parameters.

return type should be an array of `DocumentInterface`.

```php
public function listDocuments(string $indexName, ?int $pageSize = null, int $currentPage = 0): array
{
Expand All @@ -159,8 +173,14 @@ public function listDocuments(string $indexName, ?int $pageSize = null, int $cur
$request->setPageSize($pageSize);
$request->setCurrentPage($currentPage);
return $this->getClient()->appSearch()
$response = $this->getClient()->appSearch()
->listDocuments($request)
->asArray();
// Convert your reponse body into DocumentInterface objects
$documents = [];
return $documents;
}
```

Expand Down Expand Up @@ -191,8 +211,10 @@ This method should rely heavily on the `IndexConfiguration` class to guide its o
with the `getOptions()` method of the `Field` objects, which can be used for adding arbitrary
configuration data to the index (e.g. data types).

Return value should be an array describing the current Schema for each index.

```php
public function configure(): void
public function configure(): array
{
foreach ($indexesToCreate as $index) {
$myAPI->createIndex(static::environmentizeIndex($index));
Expand Down

0 comments on commit c6520d1

Please sign in to comment.