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
EZP-26368: As a developer I want to index custom data with Solr Search Engine #67
Conversation
6bab612
to
6fcdbdf
Compare
Ready for review, ping @andrerom @alongosz @bdunogier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
(I would remove @version //autogentag//
from all new files, beside that it looks good)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, however do you also have updated PR with the followup changes where inline logic is removed in favor of using this plugin system?
/** | ||
* Base compiler pass for aggregate document field mappers. | ||
*/ | ||
abstract class BaseDocumentFieldMapperPass implements CompilerPassInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a real review (I don't request the change), but we have similar compiler passes over the place. Shouldn't we try to have a common one that we can re-use in all of our packages ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could do that, it should probably be in ezpublish-kernel
repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go. I hope the review ain't too far off :)
/** | ||
* Base class for document field mappers. | ||
*/ | ||
abstract class FieldMapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not an interface rather than an abstract class ? i'd actually really suggest an interface. An abstract class would have a particular behaviour, while FieldMapper
hints at a "role" (e.g. what it does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think I'll just remove this, as it serves not purpose ATM. We can introduce it later on if need be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in a433031
* | ||
* Content document field mapper maps Content to the search fields for Content document. | ||
*/ | ||
abstract class Content extends FieldMapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above (interface vs. abstract class).
Also, I tend to avoid naming things "Content" or similar. We end up with an s'load of those. ContentFieldMapper
is still short enough, is it not ?
(I won't be fanatic about it, just an improvement imho).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the benefit of the interface here, it's perfectly fine for abstract class not to have it's own implementation. Role would be more like FieldMapping
.
Will rename when moving up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed (and moved up) in 30ffce1.
/** | ||
* Aggregate implementation of Location document field mapper. | ||
*/ | ||
class Aggregate extends LocationMapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it me or all of your Aggregate mappers have the same code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's you :) They are mostly the same, but accept different mapper type.
{ | ||
$fields = []; | ||
|
||
if ($this->locationTranslationFieldMapper->accept($location, $languageCode)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be shorter with a return early:
if ($this->locationTranslationFieldMapper->accept($location, $languageCode)) {
return [];
}
return $this->locationTranslationFieldMapper->mapFields($location, $languageCode);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but I would not be able to process it at a glance :)
It's really a matter of style.
@@ -83,6 +117,12 @@ class NativeDocumentMapper implements DocumentMapper | |||
/** | |||
* Creates a new document mapper. | |||
* | |||
* @param \EzSystems\EzPlatformSolrSearchEngine\DocumentMapper\FieldMapper\Content $blockFieldMapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only possibility I see is to move it up, on the same level as DocumentMapper
.
I actually like that idea, it's the same approach I took in pspanja#4 with a number of other services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved up in 30ffce1
Edited: Not updated yet, I wanted to do it in a followup. |
I think I addressed all remarks. |
What do you think @bdunogier? From extensibility perspective do we hit a good spot here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, but this implies master should be bumped to 1.2.x, so when this is merged, commit before should be branched of to 1.1 in case we need to do another 1.1 release.
There were no significant commits to |
Is there an example that I can look at somewhere ? It would help a lot :) |
The one linked in the description, should be virtually identical, aside from placement, removal of |
"lol" ;) Thank you for the link, I'll look into it. |
You're welcome. This is the code with consolidated field names and visitors, so basically removing unnecessary duplication even further: Also do check the container configuration: |
Looks okay from an extensibility pov. It would be much easier to review this aspect with documentation about the said extensibility (I've found out that writing this doc together with the feature really helps). |
*/ | ||
class ContentFieldMapperPass extends BaseFieldMapperPass | ||
{ | ||
const AGGREGATE_MAPPER_SERVICE_ID = 'ezpublish.search.solr.field_mapper.content'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit late, so take that as an FYI, but you could have use one concrete class (FieldMapperPass
), with the service id / service tag as arguments, and instantiate the Pass N times from the bundle, with the respective arguments. Less files, same result, easier to test.
92c2f38
to
6bb041f
Compare
@@ -0,0 +1,100 @@ | |||
# Document Field Mappers | |||
|
|||
As a website developer you will often find the need to index some additional data in the search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
website developer => developer
|
||
As a website developer you will often find the need to index some additional data in the search | ||
engine. The use cases for this are wide, for example the data could come from the external source | ||
(for example from recommendation system), or from the internal source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be italic: (for example from recommendation system)
6bb041f
to
09a1927
Compare
09a1927
to
6834483
Compare
Excellent, thanks @pspanja . |
This PR resolves https://jira.ez.no/browse/EZP-26368
This is #42 continued.
As was discussed previously
LocationTranslation
mapper is here removed, to be proposed in a separate PR.This implements document field mappers, aka indexing plugins feature.
Three types of base plugins are implemented:
Content::mapFields(Content $content)
ContentTranslation::mapFields(Content $content, $languageCode)
Location::mapFields(Location $location)
For each of these an
Aggregate
plugin is implemented and used (6 places total):Content::mapFields(Content $content)
ContentTranslation::mapFields(Content $content, $languageCode)
Location::mapFields(Location $location)
The same, but starting from extension points (service tags):
ezpublish.search.solr.document_field_mapper.block
Content::mapFields(Content $content)
ezpublish.search.solr.document_field_mapper.block_translation
ContentTranslation::mapFields(Content $content, $languageCode)
ezpublish.search.solr.document_field_mapper.content
Content::mapFields(Content $content)
ezpublish.search.solr.document_field_mapper.content_translation
ContentTranslation::mapFields(Content $content, $languageCode)
ezpublish.search.solr.document_field_mapper.location
Location::mapFields(Location $location)
Concrete plugins are registered to
Aggregate
plugin in a container compiler pass, using service tags.At the moment no concrete plugins are implemented, followup to this would be refactoring
DocumentMapper
to use only plugins to map fields. How that would look like can be seen here: pspanja#1This is
DocumentMapper
fully refactored to use plugins: https://github.com/pspanja/ezplatform-solr-search-engine/blob/3a439bcf098b7e5a6c397204fc5849737cb1a60b/lib/DocumentMapper/NativeDocumentMapper.php