diff --git a/app/Http/Controllers/Api/V1/ItemController.php b/app/Http/Controllers/Api/V1/ItemController.php index c264fc52d..304c072f0 100644 --- a/app/Http/Controllers/Api/V1/ItemController.php +++ b/app/Http/Controllers/Api/V1/ItemController.php @@ -303,7 +303,7 @@ protected function createQueryBuilder($q, $filter) if ($q) { $query = Query::multiMatch() - ->fields(['title.*', 'description.*']) + ->fields(['title.*', 'description.*', 'identifier', 'id']) ->query($q); $builder->must($query); } diff --git a/tests/Feature/Api/V1/ItemsTest.php b/tests/Feature/Api/V1/ItemsTest.php index 20f9e66eb..239e7da4b 100644 --- a/tests/Feature/Api/V1/ItemsTest.php +++ b/tests/Feature/Api/V1/ItemsTest.php @@ -326,4 +326,45 @@ public function test_show() ], ]); } + + public function test_search_by_id() + { + $item = Item::factory()->create(); + app(ItemRepository::class)->refreshIndex(); + + $url = route('api.v1.items.index', [ + 'q' => $item->id, + ]); + + $this->getJson($url)->assertJson([ + 'total' => 1, + 'data' => [ + [ + 'id' => $item->id, + ], + ], + ]); + } + + public function test_search_by_identifier() + { + $item = Item::factory()->create(['identifier' => 'G 3415']); + app(ItemRepository::class)->refreshIndex(); + + $url = route('api.v1.items.index', [ + 'q' => 'G 3415', + ]); + + $this->getJson($url)->assertJson([ + 'total' => 1, + 'data' => [ + [ + 'id' => $item->id, + 'content' => [ + 'identifier' => 'G 3415', + ], + ], + ], + ]); + } }