Skip to content

Added raw search (fixes #17) #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions src/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ public function search(
array $requestOptions = []
): array;

/**
* Get the raw search result.
*
* @see https://docs.meilisearch.com/reference/api/search.html#response
*
* @param string $className
* @param string $query
* @param array $searchParams
*
* @return array
*/
public function rawSearch(
string $className,
string $query = '',
array $searchParams = []
): array;

/**
* @param string $className
* @param string $query
Expand Down
13 changes: 13 additions & 0 deletions src/Services/MeiliSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ public function search(
return $results;
}

/**
* {@inheritdoc}
*/
public function rawSearch(
string $className,
string $query = '',
array $searchParams = []
): array {
$this->assertIsSearchable($className);

return $this->engine->search($query, $this->searchableAs($className), $searchParams);
}

/**
* {@inheritdoc}
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Services/NullSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ public function search(
return [new stdClass()];
}

/**
* {@inheritdoc}
*/
public function rawSearch(
string $className,
string $query = '',
array $searchParams = []
): array {
return [];
}

/**
* {@inheritdoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public function testSearchImportAggregator()
$results = $this->searchService->search($this->objectManager, Post::class, $searchTerm);
$this->assertCount($nbEntityIndexed , $results);

$results = $this->searchService->rawSearch(Post::class, $searchTerm);
$this->assertCount($nbEntityIndexed , $results['hits']);

// clearup table
$this->connection->executeUpdate($this->platform->getTruncateTableSQL($this->indexName, true));
$this->cleanUp();
Expand Down