I have a document (document type A) which has multiple (any number of) children documents of the same type (document type B). The following link from vespa documentation talks about the parent-child relationship.
http://docs.vespa.ai/documentation/search-definitions.html#document-references
For this, we have to define a reference type field and then import any field from the referred document. What if I want multiple document references from the parent document. Can't I define something like,
field child_ref type array<reference<doc_type_child>> {
indexing: attribute
}
certainly, I would have the difficulty of importing a certain field as all the child references have the same field.
Let's say the child document type is model and parent document type is car, basically, I want to have a nested document in which I need the capability of querying based on parent and child fields also. Let's say if I search for Mercedes cars with spokes of wheels in range (3,5), the search for Mercedes brand (parent doc field) in parent documents and further I would like to choose models of Mercedes car results (car1, car2, ...) which have wheel spokes (child doc field) from 3 to 5, (car1[model 1, model 4, model 6], car2[model 2, model 3, model 5]). Basically, hits should be of Mercedes brand and in all those hits, internally hits of models which have 3-5 wheel spokes.
The relationship goes from the child document to the parent so no you cannot store child document references in the parent document.
But the example you provide is fully doable with car being the parent (global) document type and model the child, each child document references the parent (car) and can import any field from the parent document type while matching/searching is performed against the child (model) document type and you can search both model document fields and the imported parent car fields. /search/?query=car_brand:mercedes+AND+model_spokes:[3;5]&restrict=model
Where car_brand is an imported field from the parent car in the model document type.
Related
I'm using an content node type (let's say "A") with file attachments.
For search functionality the attachments are being indexed by "Search API" and "Search API Attachments".
At the search result view I want to view fields of the parent of a found file. How to achieve this?
For example:
If a search results in a file, the result page should view fields from the containing parent node (type "A"), for instance the title of the parent node.
You can add relationships down in your index, but not up, so you
probably want to index the parent content, and then add fields to your index which have a relationship to the file > filename. That way the filename is indexed (other other file entity fields), but the result you're return is the parent node.
You could then use a search result view mode to select which parent node fields you want to feature in the result.
Docs - https://www.drupal.org/docs/8/modules/search-api/getting-started/adding-an-index
I have to 2 object having master-detail relationship.
I want to update a Status picklist field in Parent object if any update is happening on either of the object (Parent or child).
What will be the best approach?
Hope this helps give you some idea of the various solutions available. I've ordered them by simplest workflow updates to more complex process builders and lastly apex triggers, which resonates the best practice of clicks over code when implementing solutions on salesforce.
You can use a number of strategies here, I'll outline them below from simplest to complex (overkill):
Workflow: You can use two workflow field updates to do this:
- one on the parent object when a record is edited,
then update the status picklist field on the record .
- and another on the child object when a record is edited,
then upon selecting `field to update` as option, you will
be given the parent object and child object as options to
filter fields on, select parent object to filter fields on
then select the status picklist field from parent object.
Process Builder:
You can use process builder to update parent record from child.
Create a process builder flow on child object and update parent
object along with either of the two:
- create a workflow on the parent object to update the status
picklist field when a record is edited only.
- or alternatively to the workflow on the parent object, create
a process builder flow on parent object and update parent object.
Apex Trigger:
Equally you can go to the lengths of writing an apex trigger
upon the parent object `onupdate` trigger and verify if a valid
change was made(meaning the change made to parent was not a
change on the status picklist field), update the the status
picklist field too.
I have 2 content types:
One content type is named: "Offer". This content type includes a reference field to choose one hotel, form the other content type: "Hotel". The content type "Hotel" has a term reference field called "sports".
Now I want to build a view filter, which uses the content type "Offer", and uses the sport terms which i get over the hotel relationship.
I already tried to create a relationship on my own:
Reference to the hotel
Added taxonomy field sport with the relationship to the hotel, which i created before
Then i added the taxonomy field to my filter, and selected the Relationship in the drop down menu.
But this doesn't work at all.
Anyone can help me?
Regards M.
The view should initially return the hotel content type.
Add a optional relationship to the offer reference field, this will give you access to the fields in the offer content type. Once you've done that you should be able to add whatever field you want as an exposed filter.
To get the sports working you may have to add the relationship Has taxonomy term in order to get what you want and then add the term as an exposed filter.
Use the patch over at https://www.drupal.org/node/1492260 for autocomplete.
A select list should work the same way as with this patch, but it's built-in. In either case, you have to enable it by checking the checkbox in the content type field config.
I have a complex taxonomy hierarchy for product categories.
Every main taxonomy term has at least one child term. Some of those child terms have child terms. So in some places the taxonomy tree is one level deep and in other places it is two levels deep.
I need to create two separate Drupal templates for the taxonomy terms depending on the level.
I have already created a custom template for the top level using a view.
I am trying to figure out how to dynamically render the taxonomy term using a custom template depending on whether it is in level 1 down or level 2 down.
I am guessing I will need to use a template pre-processing function?
Is that the best way to approach this?
You can try adding a relationship to the parent term (in the display's advanced settings)
Then add a filter (filter by by term name or termID) and set it to use the parent relationship.
Limit the displayed terms to:
terms where the parent term is null (to get the base term)
terms where the parent term is not null (to get terms with at least one
parent)
I have 2 models:
class Parent (db.Model) :
data = db.StringProperty()
class Child1 (db.Model) :
parent = db.ReferenceProperty(Parent)
childData = db.StringProperty()
class Child2 (db.Model) :
parent = db.ReferenceProperty(Parent)
childData2 = db.StringProperty()
class Child3 (db.Model) :
parent = db.ReferenceProperty(Parent)
childData3 = db.StringProperty()
....
I want a query which can give me a list of all parents which do not have a child yet. How do i do it?
I do not want to maintain an identifier in the Parent model for each of the children as I want to add new child models very often.
The correct way to handle this is to keep a count in your Parent entity of the number of children. Then, you can simply query for Parents that have child count equal to 0.
You don't need to have the child id in the Parent entity; you want to keep a count of the number of children. It is not necessarily important whether the child is of one Model type or another. The purpose of keeping this running count is that it enables you to solve your problem, which is querying for childless Parents. There is no native capability of the datastore or of AppEngine query objects that provides this functionality.
So since this is not supported natively, you have the choice of doing it one of two ways:
1) keep a running count of the number of children, incrementing or decrementing whenever you add or remove a child;
2a) query EVERY child of every type and record unique values of parent.
2b) query all Parent entities and match them up with the unique parent ids from 2a
I'll leave it to you to decide which approach is the correct one.