forked from ongr-io/ElasticsearchDSL
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elasticsearch version changed as 8.4.0 for github ci/cd
- Loading branch information
Showing
4 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @since Feb 2022 | ||
* @author Haydar KULEKCI <haydarkulekci@gmail.com> | ||
*/ | ||
|
||
namespace ONGR\ElasticsearchDSL\Tests\Functional\Knn; | ||
|
||
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation; | ||
use ONGR\ElasticsearchDSL\Knn\Knn; | ||
use ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery; | ||
use ONGR\ElasticsearchDSL\Search; | ||
use ONGR\ElasticsearchDSL\Tests\Functional\AbstractElasticsearchTestCase; | ||
|
||
class KnnTest extends AbstractElasticsearchTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getDataArray(): array | ||
{ | ||
return [ | ||
'knn_data' => [ | ||
'doc_1' => [ | ||
'label' => 1, | ||
'vector_field' => [1, 2, 3], | ||
], | ||
'doc_2' => [ | ||
'label' => 1, | ||
'vector_field' => [1, 2, 4], | ||
], | ||
'doc_3' => [ | ||
'label' => 2, | ||
'vector_field' => [1, 2, 30], | ||
], | ||
] | ||
]; | ||
} | ||
|
||
protected function getMapping(): array | ||
{ | ||
return [ | ||
'properties' => [ | ||
'label' => [ | ||
'type' => 'long' | ||
], | ||
'vector_field' => [ | ||
'type' => 'dense_vector', | ||
'similarity' => 'cosine', | ||
'index' => true, | ||
'dims' => 3 | ||
] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Match all test | ||
*/ | ||
public function testKnnSearch(): void | ||
{ | ||
$knn = new Knn('vector_field', [1, 2, 3], 1, 1); | ||
|
||
$search = new Search(); | ||
$search->addKnn($knn); | ||
$results = $this->executeSearch($search, true); | ||
$this->assertCount(1, $results['hits']['hits']); | ||
$this->assertEquals('doc_1', $results['hits']['hits'][0]['_id']); | ||
} | ||
|
||
/** | ||
* Match all test | ||
*/ | ||
public function testKnnSearchWithFilter(): void | ||
{ | ||
$knn = new Knn('vector_field', [1, 2, 3], 1, 1); | ||
$knn->setFilter(new TermQuery('label', 2)); | ||
|
||
$search = new Search(); | ||
$search->addKnn($knn); | ||
$results = $this->executeSearch($search, true); | ||
$this->assertCount(1, $results['hits']['hits']); | ||
$this->assertEquals('doc_3', $results['hits']['hits'][0]['_id']); | ||
} | ||
} |