-
Notifications
You must be signed in to change notification settings - Fork 18
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
DataObjects can declare their own indexing behaviour #6
Comments
I think we should allow for selecting fields on subclasses, but not a Page:
fields:
Content
MyCustomFieldOnSubclass |
It would be nice if you could index any object regardless of if it is from the ORM, for example by making them comply with an The default behaviour could be supplied as a trait that is easily added to Should be fairly simple by implementing a |
Yes, this is the intention: https://github.com/silverstripe/silverstripe-search-service/blob/master/src/Interfaces/DocumentInterface.php And the DataObject implementation: https://github.com/silverstripe/silverstripe-search-service/blob/master/src/DataObject/DataObjectDocument.php |
Removing "index all fields on subclasses" as Ingo and I have discussed the potential security hazards of implicit exposure of fields. |
This doesn't work with subclasses at the moment: SilverStripe\SearchService\Service\IndexConfiguration:
indexes:
my_index:
includeClasses:
Page:
fields:
title:
property: Title
relation_only_on_subclass:
property: MyRelation.Title
diff --git a/src/DataObject/DataObjectDocument.php b/src/DataObject/DataObjectDocument.php
index 38090d8..e3dd790 100644
--- a/src/DataObject/DataObjectDocument.php
+++ b/src/DataObject/DataObjectDocument.php
@@ -343,8 +343,15 @@ class DataObjectDocument implements
*/
public function toDBField(Field $field)
{
+ $obj = $this->getDataObject();
if ($field->getProperty()) {
- return $this->getDataObject()->relObject($field->getProperty());
+ $firstField = explode('.', $field->getProperty())[0];
+ if ($obj->hasField($firstField) || $obj->hasMethod($firstField) || $obj->getRelationClass($firstField)) {
+ return $obj->relObject($field->getProperty());
+ } else {
+ // Guard against missing fields which only exist in some subclasses
+ return null;
+ }
}
return $this->resolveField($field->getSearchFieldName()); |
As a Silverstripe CMS developer, I want to leverage the power of the ORM to create a highly inclusive set of index fields on my dataobjects so that searches return more accurate results.
Acceptance Criteria
Include all fields on subclassesNote: Decided not to do this to avoid inferring field namesThe text was updated successfully, but these errors were encountered: