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

Refactoring mapping field building and merging with config files. #1055

Merged

Conversation

romainruaud
Copy link
Collaborator

Several things here :

  • Mapping class refactored to allow only an array of fields in constructor.

  • Fields are built by the Indices Config prior to creating the mapping.

  • Fields that exist both in a "dynamic provider" and from the elasticsuite_indices.xml file are now properly merged.

I made the choice to give precedence to the file : only some fieldConfig is written to the file, meaning it will only overwrite some values of the dynamically computed Field.

For SKU, this allow to have the "defaultSearchAnalyzer" defined in the file, and to rely on the Back-Office for Search Weight of the attribute.

Fix #920

@romainruaud
Copy link
Collaborator Author

I also refactored the Unit tests for Mapping since it does not rely anymore on Dynamic Fields Provider : easier to test now. But the Indices Config part remains untested about DynamicFieldProviders.

let me know

@afoucret afoucret changed the base branch from 2.6.x to master September 4, 2018 08:28
Copy link
Contributor

@afoucret afoucret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See both comments.

/**
* {@inheritDoc}
*/
public function getConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it is a mistake to create a new getter for the config.
I would prefer a method mergeConfig(array $config) that would return a new instance of the field with updated config.

It is also possible to add a test on the mergeConfig method in FieldTest.

}

foreach ($typeConfigData['mapping']['staticFields'] as $fieldName => $fieldConfig) {
if (isset($fields[$fieldName])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mergeConfig method instead of this one :

$field = $this->mappingFieldFactory->create(['name' => $fieldName] + $fieldConfig);

if (isset($fields[$fieldName]) {
    $field = $fields[$fieldName]->mergeConfig($fieldConfig);
}

$fields[$fieldName] = $field;

@romainruaud romainruaud force-pushed the feature_mapping-fields-refactoring branch 2 times, most recently from 7c5192e to 33994f7 Compare September 4, 2018 10:26
@romainruaud romainruaud force-pushed the feature_mapping-fields-refactoring branch from d421ed5 to 68d2029 Compare September 4, 2018 10:45
@romainruaud
Copy link
Collaborator Author

PR updated and rebased

@afoucret afoucret merged commit 6a42657 into Smile-SA:master Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants