Skip to content
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

Add index for all filterable, sortable and searchable fields #68

Open
wants to merge 3 commits into
base: 0.7
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Update not searchable field test to fail on elastic and opensearch co…
…rrectly
alexander-schranz committed Jan 13, 2023
commit c4789061a9de584f244f6b5ac43e9d7511801605
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ public function testSimpleElasticsearchMapping(): void
$this->assertSame([
'id' => [
'type' => 'keyword',
'index' => false,
],
'title' => [
'type' => 'text',
@@ -94,7 +93,6 @@ public function testComplexElasticsearchMapping(): void
],
'categoryIds' => [
'type' => 'integer',
'index' => false,
],
'comments' => [
'properties' => [
@@ -109,7 +107,6 @@ public function testComplexElasticsearchMapping(): void
],
'commentsCount' => [
'type' => 'integer',
'index' => false,
],
'created' => [
'type' => 'date',
@@ -142,9 +139,16 @@ public function testComplexElasticsearchMapping(): void
],
],
],
'internalTags' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
'rating' => [
'type' => 'float',
'index' => false,
],
'tags' => [
'type' => 'text',
@@ -159,7 +163,6 @@ public function testComplexElasticsearchMapping(): void
],
'uuid' => [
'type' => 'keyword',
'index' => false,
],
], $mapping[$index->name]['mappings']['properties']);
}
15 changes: 8 additions & 7 deletions packages/seal-opensearch-adapter/OpensearchSchemaManager.php
Original file line number Diff line number Diff line change
@@ -68,12 +68,13 @@ private function createPropertiesMapping(array $fields): array
foreach ($fields as $name => $field) {
// TODO recheck doc_values https://github.com/schranz-search/schranz-search/issues/65
$index = $field->searchable || $field->filterable || $field->sortable;
$doc_values = $field->filterable || $field->sortable;

match (true) {
$field instanceof Field\IdentifierField => $properties[$name] = [
'type' => 'keyword',
'index' => $index,
'doc_values' => $field->filterable,
'doc_values' => $doc_values,
],
$field instanceof Field\TextField => $properties[$name] = \array_replace([
'type' => 'text',
@@ -82,30 +83,30 @@ private function createPropertiesMapping(array $fields): array
'fields' => [
'raw' => [
'type' => 'keyword',
'index' => $field->searchable || $field->filterable,
'doc_values' => $field->filterable,
'index' => true,
'doc_values' => true,
],
],
] : []),
$field instanceof Field\BooleanField => $properties[$name] = [
'type' => 'boolean',
'index' => $index,
'doc_values' => $field->filterable,
'doc_values' => $doc_values,
],
$field instanceof Field\DateTimeField => $properties[$name] = [
'type' => 'date',
'index' => $index,
'doc_values' => $field->filterable,
'doc_values' => $doc_values,
],
$field instanceof Field\IntegerField => $properties[$name] = [
'type' => 'integer',
'index' => $index,
'doc_values' => $field->filterable,
'doc_values' => $doc_values,
],
$field instanceof Field\FloatField => $properties[$name] = [
'type' => 'float',
'index' => $index,
'doc_values' => $field->filterable,
'doc_values' => $doc_values,
],
$field instanceof Field\ObjectField => $properties[$name] = [
'type' => 'object',
Original file line number Diff line number Diff line change
@@ -139,6 +139,14 @@ public function testComplexOpensearchMapping(): void
],
],
],
'internalTags' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
'rating' => [
'type' => 'float',
],
2 changes: 1 addition & 1 deletion packages/seal/Testing/AbstractConnectionTestCase.php
Original file line number Diff line number Diff line change
@@ -215,7 +215,7 @@ public function testNoneSearchableFields(): void

$search = new SearchBuilder($schema, self::$connection);
$search->addIndex(TestingHelper::INDEX_COMPLEX);
$search->addFilter(new Condition\SearchCondition('admin.nonesearchablefield@localhost'));
$search->addFilter(new Condition\SearchCondition('Nonesearchable'));

$this->assertCount(0, [...$search->getResult()]);
}
2 changes: 2 additions & 0 deletions packages/seal/Testing/TestingHelper.php
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ public static function createSchema(): Schema
'text' => new Field\TextField('text'),
], multiple: true),
'tags' => new Field\TextField('tags', multiple: true, filterable: true),
'internalTags' => new Field\TextField('internalTags', multiple: true, searchable: false, filterable: true),
'categoryIds' => new Field\IntegerField('categoryIds', multiple: true, searchable: false, filterable: true),
];

@@ -138,6 +139,7 @@ public static function createComplexFixtures(): array
],
],
'tags' => ['Tech', 'UI'],
'internalTags' => ['Internal', 'Nonesearchable'],
'categoryIds' => [1, 2],
],
[
1 change: 1 addition & 0 deletions packages/seal/Tests/Marshaller/MarshallerTest.php
Original file line number Diff line number Diff line change
@@ -88,6 +88,7 @@ private function getRawDocument(): array
],
],
'tags' => ['Tech', 'UI'],
'internalTags' => ['Internal', 'Nonesearchable'],
'categoryIds' => [1, 2],
];
}