Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Compat new NC16
  • Loading branch information
ArtificialOwl committed Mar 1, 2019
commit c719192323984cfa1e5604e373edda0594f4013f
22 changes: 11 additions & 11 deletions lib/Platform/ElasticSearchPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
use OCA\FullTextSearch_ElasticSearch\Service\MiscService;
use OCA\FullTextSearch_ElasticSearch\Service\SearchService;
use OCP\FullTextSearch\IFullTextSearchPlatform;
use OCP\FullTextSearch\Model\DocumentAccess;
use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\FullTextSearch\Model\IIndex;
use OCP\FullTextSearch\Model\IndexDocument;
use OCP\FullTextSearch\Model\IIndexDocument;
use OCP\FullTextSearch\Model\IRunner;
use OCP\FullTextSearch\Model\ISearchResult;

Expand Down Expand Up @@ -211,11 +211,11 @@ public function resetIndex(string $providerId) {


/**
* @param IndexDocument $document
* @param IIndexDocument $document
*
* @return IIndex
*/
public function indexDocument(IndexDocument $document): IIndex {
public function indexDocument(IIndexDocument $document): IIndex {

$document->initHash();

Expand Down Expand Up @@ -262,15 +262,15 @@ public function indexDocument(IndexDocument $document): IIndex {


/**
* @param IndexDocument $document
* @param IIndexDocument $document
* @param Exception $e
*
* @return array
* @throws AccessIsEmptyException
* @throws ConfigurationException
* @throws \Exception
*/
private function indexDocumentError(IndexDocument $document, Exception $e): array {
private function indexDocumentError(IIndexDocument $document, Exception $e): array {

$this->updateRunnerAction('indexDocumentWithoutContent', true);

Expand All @@ -285,10 +285,10 @@ private function indexDocumentError(IndexDocument $document, Exception $e): arra


/**
* @param IndexDocument $document
* @param IIndexDocument $document
* @param Exception $e
*/
private function manageIndexErrorException(IndexDocument $document, Exception $e) {
private function manageIndexErrorException(IIndexDocument $document, Exception $e) {

$message = $this->parseIndexErrorException($e);
$document->getIndex()
Expand Down Expand Up @@ -336,7 +336,7 @@ public function deleteIndexes(array $indexes) {
* {@inheritdoc}
* @throws Exception
*/
public function searchRequest(ISearchResult $result, DocumentAccess $access) {
public function searchRequest(ISearchResult $result, IDocumentAccess $access) {
$this->searchService->searchRequest($this->client, $result, $access);
}

Expand All @@ -345,10 +345,10 @@ public function searchRequest(ISearchResult $result, DocumentAccess $access) {
* @param string $providerId
* @param string $documentId
*
* @return IndexDocument
* @return IIndexDocument
* @throws ConfigurationException
*/
public function getDocument(string $providerId, string $documentId): IndexDocument {
public function getDocument(string $providerId, string $documentId): IIndexDocument {
return $this->searchService->getDocument($this->client, $providerId, $documentId);
}

Expand Down
21 changes: 10 additions & 11 deletions lib/Service/IndexMappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
use Elasticsearch\Common\Exceptions\Missing404Exception;
use OCA\FullTextSearch_ElasticSearch\Exceptions\AccessIsEmptyException;
use OCA\FullTextSearch_ElasticSearch\Exceptions\ConfigurationException;
use OCP\FullTextSearch\Model\IIndex;
use OCP\FullTextSearch\Model\IndexDocument;
use OCP\FullTextSearch\Model\IIndexDocument;


/**
Expand Down Expand Up @@ -68,13 +67,13 @@ public function __construct(ConfigService $configService, MiscService $miscServi

/**
* @param Client $client
* @param IndexDocument $document
* @param IIndexDocument $document
*
* @return array
* @throws ConfigurationException
* @throws AccessIsEmptyException
*/
public function indexDocumentNew(Client $client, IndexDocument $document): array {
public function indexDocumentNew(Client $client, IIndexDocument $document): array {
$index = [
'index' =>
[
Expand All @@ -93,13 +92,13 @@ public function indexDocumentNew(Client $client, IndexDocument $document): array

/**
* @param Client $client
* @param IndexDocument $document
* @param IIndexDocument $document
*
* @return array
* @throws ConfigurationException
* @throws AccessIsEmptyException
*/
public function indexDocumentUpdate(Client $client, IndexDocument $document): array {
public function indexDocumentUpdate(Client $client, IIndexDocument $document): array {
$index = [
'index' =>
[
Expand Down Expand Up @@ -144,24 +143,24 @@ public function indexDocumentRemove(Client $client, string $providerId, string $


/**
* @param IndexDocument $document
* @param IIndexDocument $document
* @param array $arr
*/
public function onIndexingDocument(IndexDocument $document, array &$arr) {
public function onIndexingDocument(IIndexDocument $document, array &$arr) {
if ($document->getContent() !== ''
&& $document->isContentEncoded() === IndexDocument::ENCODED_BASE64) {
&& $document->isContentEncoded() === IIndexDocument::ENCODED_BASE64) {
$arr['index']['pipeline'] = 'attachment';
}
}


/**
* @param IndexDocument $document
* @param IIndexDocument $document
*
* @return array
* @throws AccessIsEmptyException
*/
public function generateIndexBody(IndexDocument $document): array {
public function generateIndexBody(IIndexDocument $document): array {

$access = $document->getAccess();
if ($access === null) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
use OCA\FullTextSearch_ElasticSearch\Exceptions\AccessIsEmptyException;
use OCA\FullTextSearch_ElasticSearch\Exceptions\ConfigurationException;
use OCP\FullTextSearch\Model\IIndex;
use OCP\FullTextSearch\Model\IndexDocument;
use OCP\FullTextSearch\Model\IIndexDocument;


/**
Expand Down Expand Up @@ -177,13 +177,13 @@ public function deleteIndexes(Client $client, array $indexes) {

/**
* @param Client $client
* @param IndexDocument $document
* @param IIndexDocument $document
*
* @return array
* @throws ConfigurationException
* @throws AccessIsEmptyException
*/
public function indexDocument(Client $client, IndexDocument $document): array {
public function indexDocument(Client $client, IIndexDocument $document): array {
$result = [];
$index = $document->getIndex();
if ($index->isStatus(IIndex::INDEX_REMOVE)) {
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/SearchMappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use OCA\FullTextSearch_ElasticSearch\Exceptions\QueryContentGenerationException;
use OCA\FullTextSearch_ElasticSearch\Exceptions\SearchQueryGenerationException;
use OCA\FullTextSearch_ElasticSearch\Model\QueryContent;
use OCP\FullTextSearch\Model\DocumentAccess;
use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\FullTextSearch\Model\ISearchRequest;


Expand Down Expand Up @@ -67,15 +67,15 @@ public function __construct(ConfigService $configService, MiscService $miscServi

/**
* @param ISearchRequest $request
* @param DocumentAccess $access
* @param IDocumentAccess $access
* @param string $providerId
*
* @return array
* @throws ConfigurationException
* @throws SearchQueryGenerationException
*/
public function generateSearchQuery(
ISearchRequest $request, DocumentAccess $access, string $providerId
ISearchRequest $request, IDocumentAccess $access, string $providerId
): array {
$query['params'] = $this->generateSearchQueryParams($request, $access, $providerId);

Expand All @@ -85,15 +85,15 @@ public function generateSearchQuery(

/**
* @param ISearchRequest $request
* @param DocumentAccess $access
* @param IDocumentAccess $access
* @param string $providerId
*
* @return array
* @throws ConfigurationException
* @throws SearchQueryGenerationException
*/
public function generateSearchQueryParams(
ISearchRequest $request, DocumentAccess $access, string $providerId
ISearchRequest $request, IDocumentAccess $access, string $providerId
): array {
$params = [
'index' => $this->configService->getElasticIndex(),
Expand Down Expand Up @@ -303,11 +303,11 @@ private function generateQueryContentFields(ISearchRequest $request, QueryConten


/**
* @param DocumentAccess $access
* @param IDocumentAccess $access
*
* @return array
*/
private function generateSearchQueryAccess(DocumentAccess $access): array {
private function generateSearchQueryAccess(IDocumentAccess $access): array {

$query = [];
$query[] = ['term' => ['owner' => $access->getViewerId()]];
Expand Down
64 changes: 14 additions & 50 deletions lib/Service/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
use daita\MySmallPhpTools\Traits\TArrayTools;
use Elasticsearch\Client;
use Exception;
use OC\FullTextSearch\Model\DocumentAccess;
use OC\FullTextSearch\Model\IndexDocument;
use OCA\FullTextSearch_ElasticSearch\Exceptions\ConfigurationException;
use OCA\FullTextSearch_ElasticSearch\Exceptions\SearchQueryGenerationException;
use OCP\FullTextSearch\Model\DocumentAccess;
use OCP\FullTextSearch\Model\IndexDocument;
use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\FullTextSearch\Model\IIndexDocument;
use OCP\FullTextSearch\Model\ISearchResult;


Expand Down Expand Up @@ -75,12 +77,12 @@ public function __construct(
/**
* @param Client $client
* @param ISearchResult $searchResult
* @param DocumentAccess $access
* @param IDocumentAccess $access
*
* @throws Exception
*/
public function searchRequest(
Client $client, ISearchResult $searchResult, DocumentAccess $access
Client $client, ISearchResult $searchResult, IDocumentAccess $access
) {
try {
$query = $this->searchMappingService->generateSearchQuery(
Expand Down Expand Up @@ -109,57 +111,16 @@ public function searchRequest(
}


// /**
// * @param Client $client
// * @param IFullTextSearchProvider $provider
// * @param DocumentAccess $access
// * @param SearchResult $result
// *
// * @return SearchResult
// * @throws ConfigurationException
// */
// public function fillSearchResult(
// Client $client, IFullTextSearchProvider $provider, DocumentAccess $access,
// SearchResult $searchResult
// ) {
// try {
// $query = $this->searchMappingService->generateSearchQuery(
// $provider, $access, $searchResult->getRequest()
// );
// } catch (SearchQueryGenerationException $e) {
// return null;
// }
//
// try {
// $result = $client->search($query['params']);
// } catch (Exception $e) {
// $this->miscService->log(
// 'debug - request: ' . json_encode($searchResult->getRequest()) . ' - query: '
// . json_encode($query)
// );
// throw $e;
// }
//
// $this->updateSearchResult($searchResult, $result);
//
// foreach ($result['hits']['hits'] as $entry) {
// $searchResult->addDocument($this->parseSearchEntry($entry, $access->getViewerId()));
// }
//
// return $searchResult;
// }


/**
* @param Client $client
* @param string $providerId
* @param string $documentId
*
* @return IndexDocument
* @return IIndexDocument
* @throws ConfigurationException
*/
public function getDocument(Client $client, string $providerId, string $documentId
): IndexDocument {
): IIndexDocument {
$query = $this->searchMappingService->getDocumentQuery($providerId, $documentId);
$result = $client->get($query);

Expand Down Expand Up @@ -206,9 +167,9 @@ private function updateSearchResult(ISearchResult $searchResult, array $result)
* @param array $entry
* @param string $viewerId
*
* @return IndexDocument
* @return IIndexDocument
*/
private function parseSearchEntry(array $entry, string $viewerId): IndexDocument {
private function parseSearchEntry(array $entry, string $viewerId): IIndexDocument {
$access = new DocumentAccess();
$access->setViewerId($viewerId);

Expand All @@ -233,7 +194,10 @@ private function parseSearchEntry(array $entry, string $viewerId): IndexDocument
private function parseSearchEntryExcerpts(array $highlight): array {
$result = [];
foreach (array_keys($highlight) as $k) {
$result = array_merge($highlight[$k]);
$result[] = [
'source' => $k,
'excerpt' => $highlight[$k]
];
}

return $result;
Expand Down