Skip to content

Commit

Permalink
增加 wildcard 测试
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Jul 9, 2024
1 parent 48011de commit 78cd327
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function buildQuery(string $key, mixed $value): array
],
self::WILDCARD, self::LIKE => [
'wildcard' => [
$key => $value,
$key => [
'value' => $value
],
],
],
self::GT_SYMBOL, self::GT => [
Expand Down
15 changes: 12 additions & 3 deletions tests/Cases/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public function testGetArrayAccess()
$this->assertSame(json_encode(['_id' => '1', 'id' => 1, 'name' => 'foo', 'summary' => 'foo']), json_encode($res));
}

public function testLikeChinese()
{
$res = Foo::query()->where('summary', 'like', '*中*')->get()->first();
$this->assertSame(8, $res['id']);

$res = Foo::query()->where('name', 'like', '*中文*')->get()->first();
$this->assertSame(8, $res['id']);
}

public function testOrWhere()
{
$res = Foo::query()->orWhere('id', 1)->orWhere('id', 2)->orderBy('id', 'asc')->get();
Expand All @@ -94,9 +103,9 @@ public function testOrWhere()

public function testLike()
{
$res = Foo::query()->where('summary', 'like', '*o*')->get();
$res = Foo::query()->where('summary', 'like', '*fo*')->get();

$this->assertSame(3, $res->count());
$this->assertSame(2, $res->count());
}

public function testPaginate()
Expand Down Expand Up @@ -125,7 +134,7 @@ public function testUpdateAndGet()
public function testLTAndGT()
{
$res = Foo::query()->where('id', '>', 4)->get();
$this->assertSame(3, $res->count());
$this->assertSame(5, $res->count());

$res = Foo::query()->where('id', '>=', 4)->get();
$this->assertSame(4, $res->count());
Expand Down
7 changes: 5 additions & 2 deletions tests/put_documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public function getMapping(): array
$indices = $client->indices();
$indices = Foo::indices();

if (! $indices->exists()) {
$indices->create(['number_of_shards' => 4]);
if ($indices->exists()) {
$indices->delete();
}
$indices->create(['number_of_shards' => 4]);

$indices->putMapping();

Expand All @@ -62,6 +63,8 @@ public function getMapping(): array
$res = Foo::query()->bulk([
['id' => 6, 'name' => 'elastic', 'summary' => uniqid()],
['id' => 7, 'name' => 'elastic2', 'summary' => uniqid()],
['id' => 8, 'name' => '我是中文', 'summary' => '我是中文'],
['id' => 9, 'name' => '我是中文啊', 'summary' => '我是中文啊'],
]);

var_dump($res);

0 comments on commit 78cd327

Please sign in to comment.