Forums / Extensions / eZ Find / HELP Please: How to search parent nodes

HELP Please: How to search parent nodes

Author Message

Zion Tech

Tuesday 15 February 2011 10:43:46 pm

Dear all

I am sure somebody did the search feature as what I would say below, please give me some help in advancement.

If I have shopA(ClassShop) and shopB(ClassShop), both of them have some products, eg: carA(ClassCar), carB. ClassCar is the class of carA which has an attribute of relationobject(e,g brand). Now we relate BMW to carA, and Audi to carB. Note: both shops have carA and carB.

Now I try to search BMW, it is easy to get the result of carA! However, I want to display the shops which are the containers of carA and carB. not only the data but also the search number is for the shops.

Like: A :- ( B<->C ), I search C, but want to get A. Is it feasible?

Waiting for your reply.

All the best.

Marko Žmak

Wednesday 16 February 2011 12:21:05 am

AFAIK, there's no was to do this in one fetch.

But you could do it like this:

  • fetch all the products with brand BMW
  • iterate through this products and add their parents

You should also have an additional array of parent node IDs that you have already added so that you don't get duplicates.

For getting parent nodes of an object see "assigned_nodes" and "parent_nodes" under the docs for ezcontentobject.

Another way would be fetch all the shops, and for each of them do a count fetch for products with brand BMW. Then select only those that have this count >0.

I suggest you try both solutions and see what fits best your needs.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Mingxing Chen

Wednesday 16 February 2011 1:18:39 am

@Marko, how about the navigator if you try to search products first and then get the parents?

Just thinking...

Shinetech is the leader in next generation global application outsourcing. Shinetech combines world class technical skills, recognized expertise in advanced development methodologies and industry experience to deliver results for global enterprises. Shinetech utilizes distributed Agile methods for rapid and precise systems development.
------------------------------------------------------------------------------------------
Blog: http://www.mingxing.me
Email: chenmx@shinetechchina.com

Marko Žmak

Wednesday 16 February 2011 3:01:14 am

Chen, what navigator? Could you explain it a little bit?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Mingxing Chen

Thursday 17 February 2011 8:21:47 pm

Hi Marko, I meant how about the total search number, which is used for pages.

Of course, we can append they shops in an array and count it, but if there is too much data, it seems not a good solution.

Please let me know what you think.

Thanks

Shinetech is the leader in next generation global application outsourcing. Shinetech combines world class technical skills, recognized expertise in advanced development methodologies and industry experience to deliver results for global enterprises. Shinetech utilizes distributed Agile methods for rapid and precise systems development.
------------------------------------------------------------------------------------------
Blog: http://www.mingxing.me
Email: chenmx@shinetechchina.com

Marko Žmak

Friday 18 February 2011 2:50:07 am

Chen, the total number has sense only if you use limit and offset. And the solutions I suggested are not ment to be used with limit and offset. In my experience whenever you do some sort of manual filtering of fetched data, you will have a lot of headache in combining this with limit and offset.

The full proof solution that would allow paging would be to create an extended attribute filter that would fetch the shops which contain at least one product of brand BMW. But that might be a little bit of an overkill.

It all depends on what for Zion wants to use this. If this is about only a few shops, then there's no need for paging.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth