eZ Community » Forums » eZ Platform » "Extended filter attribute" like feature
expandshrink

"Extended filter attribute" like feature

"Extended filter attribute" like feature

Saturday 02 April 2016 1:23:31 am - 1 reply

Hi all

One of the features that I used a lot in eZ Publish legacy was the extended filter attribute (EFA). I didn't actually used it to filter content. My usage of EFA enabled me to retrieve content and it's related objects in a single query. It really sped up my data retrieval processes.

Is there any thing like it available for the new stack?

Here's a use case:

Consider having a class book which, among other fields, holds an object relations' author and an object relations' publisher. When you're listing the books within a folder (bookshelf), you have to go through all the books, one by one, and fetch the authors and publisher's names. I've tested doing so with simple ez_render_field (in twig) but that always crashed my apache when I ran in dev mode and attempted to pull lists of 100 books.
I've created my own controller, fetching the books with LocationQuery and then I go through the searchHits loadingContent for getFieldValue results. That works, but is a bit slow and spams the database server with an awful amount of queries.

So my question is very simple. Is there a way that I can execute a single query that fetches all content under a specific ParentLocationId, which will also pull objectRelation's fields values?

To be honest, my use case is a bit more complex, to be honest...

I have authors, publishers, literary_works and books:

  • A publisher is very simple. It only has a single field (Name)
  • An author is also simple. One field (Name)
  • A literary work has a Title and Authors (object relations)
  • A Book has several fields, a translated title, a collection, the Publisher (object relations) and the a literary_work (also object relations)

Now, when I wish to list the books in a location, I wish to show the publisher, literary_work title and author(s)

Each book line will translate into several queries due to the one by one logic I was forced to adopt

Here's the simplified code:

    $children = [];
 
    foreach ($repository->getSearchService()->findLocations($query)->searchHits as $searchHit) {
      $location = $searchHit->valueObject;
      $content = $contentService->loadContent($location->contentInfo->id);
      $literaryWorkFieldValue = $content->getFieldValue('literary_work');
      $literaryWorkContent = $contentService->loadContent($literaryWorkFieldValue->destinationContentIds[0]);
      $authorsFieldValue = $literaryWorkContent->getFieldValue('authors');
      if(count($authorsFieldValue->destinationContentIds) > 0) {
        $authorContent = $contentService->loadContent($authorsFieldValue->destinationContentIds[0]);
        $authorName = $authorContent->getFieldValue('name');
      } else 
        $authorName = "";
      $children[] = ["location" => $searchHit->valueObject, "content" => $content, "literaryWorkAuthor" => $authorName];
    }

I wished this could be simplified so that the $query passed to findLocations would return the whole content that is to be rendered. That not being possible, I would like that my first loadContent(..) would be the only loadContent needed for a book (loading the book fields, and any level of related objects that I setup as needed.

Does anyone has any suggestion on how to simplify the above in order to reduce the amount of queries executed against the database

Thank your for your input
Io

Wednesday 27 April 2016 5:16:37 pm

Hi again

I've postponed my development in this project until now. Does anyone have information regarding support for extended attribute filters in new stack criteria?

Thanks, in advance,
Io

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from