Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
search_api_opensearch-3285438
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
search_api_opensearch-3285438
Commits
d6bfca93
Commit
d6bfca93
authored
1 year ago
by
Robert Phillips
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3285438
: Prevent index clear when field mapping hasn't changed.
parent
49da79d6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#90097
failed
1 year ago
Stage: build
Stage: lint
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SearchAPI/BackendClient.php
+50
-7
50 additions, 7 deletions
src/SearchAPI/BackendClient.php
with
50 additions
and
7 deletions
src/SearchAPI/BackendClient.php
+
50
−
7
View file @
d6bfca93
...
...
@@ -269,7 +269,6 @@ class BackendClient implements BackendClientInterface {
*/
public
function
updateIndex
(
IndexInterface
$index
):
void
{
if
(
$this
->
indexExists
(
$index
))
{
$index
->
clear
();
$this
->
updateSettings
(
$index
);
$this
->
updateFieldMapping
(
$index
);
}
...
...
@@ -288,14 +287,58 @@ class BackendClient implements BackendClientInterface {
* Thrown when an underlying OpenSearch error occurs.
*/
public
function
updateFieldMapping
(
IndexInterface
$index
):
void
{
$indexId
=
$this
->
getIndexId
(
$index
);
try
{
$params
=
$this
->
fieldParamsBuilder
->
mapFieldParams
(
$indexId
,
$index
);
$this
->
client
->
indices
()
->
putMapping
(
$params
);
if
(
$this
->
indexFieldsUpdated
(
$index
))
{
$indexId
=
$this
->
getIndexId
(
$index
);
try
{
$params
=
$this
->
fieldParamsBuilder
->
mapFieldParams
(
$indexId
,
$index
);
$this
->
client
->
indices
()
->
putMapping
(
$params
);
$index
->
reindex
();
}
catch
(
OpenSearchException
$e
)
{
throw
new
SearchApiException
(
sprintf
(
'An error occurred updating field mappings for index %s.'
,
$indexId
),
0
,
$e
);
}
}
catch
(
OpenSearchException
$e
)
{
throw
new
SearchApiException
(
sprintf
(
'An error occurred updating field mappings for index %s.'
,
$indexId
),
0
,
$e
);
}
/**
* Checks if the recently updated index had any fields changed.
*
* @param \Drupal\search_api\IndexInterface $index
* The index that was just updated.
*
* @return bool
* TRUE if any of the fields were updated, FALSE otherwise.
*/
protected
function
indexFieldsUpdated
(
IndexInterface
$index
):
bool
{
if
(
!
isset
(
$index
->
original
))
{
return
TRUE
;
}
/** @var \Drupal\search_api\IndexInterface $original */
$original
=
$index
->
original
;
$old_fields
=
$original
->
getFields
();
$new_fields
=
$index
->
getFields
();
if
(
!
$old_fields
&&
!
$new_fields
)
{
return
FALSE
;
}
if
(
array_diff_key
(
$old_fields
,
$new_fields
)
||
array_diff_key
(
$new_fields
,
$old_fields
))
{
return
TRUE
;
}
foreach
(
$new_fields
as
$field
)
{
if
(
!
isset
(
$old_fields
[
$field
->
getFieldIdentifier
()]))
{
continue
;
}
$old_field
=
$old_fields
[
$field
->
getFieldIdentifier
()];
if
(
$field
->
getSettings
()
!=
$old_field
->
getSettings
())
{
return
TRUE
;
}
if
(
$field
->
getConfiguration
()
!=
$old_field
->
getConfiguration
())
{
return
TRUE
;
}
}
return
FALSE
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment