Hi, Following problem: We have a tree structure with children and a root element (recursivly) stored in one table (imagine a threaded forum). Each of the children has a title which should be indexed by ferret. Now we want to make a search that returns only the root and searches all items. So if one node has "expensive" and nother node has "car" I want to enter "expensive car" in search and still find the root of all children (and only once!) Also paging should work as well. Any clues how to achieve that? Regards Till -- Posted via http://www.ruby-forum.com/.
On Tue, Nov 20, 2007 at 01:17:30PM +0100, Till Vollmer wrote:> Hi, > > Following problem: > > We have a tree structure with children and a root element (recursivly) > stored in one table (imagine a threaded forum). > > Each of the children has a title which should be indexed by ferret. > > Now we want to make a search that returns only the root and searches all > items. > > > So if one node has "expensive" and nother node has "car" I want to enter > "expensive car" in search and still find the root of all children (and > only once!) > > Also paging should work as well. > > Any clues how to achieve that?An instance method in the root class to the effect of children_titles_with_spaces would get you this. That method would return "expensive car" given your simple, two-node example, which would be indexable with the normal analyzer. -Chris
Hi, Thank you for the clue. Ok, like a virtual attribute. Works technically but: Downside: How often is that called ? Our tree has e.g. 200 children. This means that the children are collected on every change of one of the children (index) or? Any other ideas? Regards Till Am 20.11.2007 um 13:52 schrieb Chris Strom:> On Tue, Nov 20, 2007 at 01:17:30PM +0100, Till Vollmer wrote: >> Hi, >> >> Following problem: >> >> We have a tree structure with children and a root element >> (recursivly) >> stored in one table (imagine a threaded forum). >> >> Each of the children has a title which should be indexed by ferret. >> >> Now we want to make a search that returns only the root and >> searches all >> items. >> >> >> So if one node has "expensive" and nother node has "car" I want to >> enter >> "expensive car" in search and still find the root of all children >> (and >> only once!) >> >> Also paging should work as well. >> >> Any clues how to achieve that? > > An instance method in the root class to the effect of > children_titles_with_spaces would get you this. That method would > return > "expensive car" given your simple, two-node example, which would be > indexable with the normal analyzer. > > -Chris > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talkCodemart GmbH Till Vollmer Managing Director Tel: +49 (0)89 1213 5359 Mob: + 49 (0)160 718 7403 Fax: +49 (0)89 1892 1347 Yahoo ID: till_vollmer Skype: till_vollmer www.codemart.de till.vollmer at codemart.de -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20071120/936d5394/attachment-0001.html
If you are using acts_as_ferret, it will never get called. The acts_as_ferret declaration would go on the root class. Updates to the child classes would not trigger an aaf index update in the root class. If you want to real-time index updates, you would have to add an after_save callback to the child class that forces an aaf update in the root class. If real-time updates are not too important, then you could dump the child updates into a queue that performs bulk updates. This would minimize the number of times this method gets called. If you''re worried about 200+ SQL calls, don''t perform the join in ruby, do it via SQL using CONCAT and "Advanced Attribute" as described in AWDWR, 19.3. -Chris On Tue, Nov 20, 2007 at 02:01:39PM +0100, Till Vollmer wrote:> Hi, > Thank you for the clue. > Ok, like a virtual attribute. Works technically but: > Downside: How often is that called ? Our tree has e.g. 200 children. This > means that the children are collected on every change of one of the > children (index) or? > Any other ideas? > Regards > Till > > > Am 20.11.2007 um 13:52 schrieb Chris Strom: > >> On Tue, Nov 20, 2007 at 01:17:30PM +0100, Till Vollmer wrote: >>> Hi, >>> >>> Following problem: >>> >>> We have a tree structure with children and a root element (recursivly) >>> stored in one table (imagine a threaded forum). >>> >>> Each of the children has a title which should be indexed by ferret. >>> >>> Now we want to make a search that returns only the root and searches all >>> items. >>> >>> >>> So if one node has "expensive" and nother node has "car" I want to enter >>> "expensive car" in search and still find the root of all children (and >>> only once!) >>> >>> Also paging should work as well. >>> >>> Any clues how to achieve that? >> >> An instance method in the root class to the effect of >> children_titles_with_spaces would get you this. That method would return >> "expensive car" given your simple, two-node example, which would be >> indexable with the normal analyzer. >> >> -Chris >> _______________________________________________ >> Ferret-talk mailing list >> Ferret-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ferret-talk > > Codemart GmbH > Till Vollmer > Managing Director > Tel: +49 (0)89 1213 5359 > Mob: + 49 (0)160 718 7403 > Fax: +49 (0)89 1892 1347 > Yahoo ID: till_vollmer > Skype: till_vollmer > www.codemart.de > till.vollmer at codemart.de > > > > >> _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk
Hi, Thank you for your answer. The root and the nodes are in the same table for us. Is there no "group_by" or something for ferret? That would probably make the deal. Regards Till Am 20.11.2007 um 14:36 schrieb Chris Strom:> If you are using acts_as_ferret, it will never get called. The > acts_as_ferret declaration would go on the root class. Updates to the > child classes would not trigger an aaf index update in the root class. > > If you want to real-time index updates, you would have to add an > after_save callback to the child class that forces an aaf update in > the > root class. > > If real-time updates are not too important, then you could dump the > child > updates into a queue that performs bulk updates. This would > minimize the > number of times this method gets called. > > If you''re worried about 200+ SQL calls, don''t perform the join in > ruby, do > it via SQL using CONCAT and "Advanced Attribute" as described in > AWDWR, > 19.3. > > -Chris > > On Tue, Nov 20, 2007 at 02:01:39PM +0100, Till Vollmer wrote: >> Hi, >> Thank you for the clue. >> Ok, like a virtual attribute. Works technically but: >> Downside: How often is that called ? Our tree has e.g. 200 >> children. This >> means that the children are collected on every change of one of the >> children (index) or? >> Any other ideas? >> Regards >> Till >> >> >> Am 20.11.2007 um 13:52 schrieb Chris Strom: >> >>> On Tue, Nov 20, 2007 at 01:17:30PM +0100, Till Vollmer wrote: >>>> Hi, >>>> >>>> Following problem: >>>> >>>> We have a tree structure with children and a root element >>>> (recursivly) >>>> stored in one table (imagine a threaded forum). >>>> >>>> Each of the children has a title which should be indexed by ferret. >>>> >>>> Now we want to make a search that returns only the root and >>>> searches all >>>> items. >>>> >>>> >>>> So if one node has "expensive" and nother node has "car" I want >>>> to enter >>>> "expensive car" in search and still find the root of all children >>>> (and >>>> only once!) >>>> >>>> Also paging should work as well. >>>> >>>> Any clues how to achieve that? >>> >>> An instance method in the root class to the effect of >>> children_titles_with_spaces would get you this. That method would >>> return >>> "expensive car" given your simple, two-node example, which would be >>> indexable with the normal analyzer. >>> >>> -Chris >>> _______________________________________________ >>> Ferret-talk mailing list >>> Ferret-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ferret-talk >> >> Codemart GmbH >> Till Vollmer >> Managing Director >> Tel: +49 (0)89 1213 5359 >> Mob: + 49 (0)160 718 7403 >> Fax: +49 (0)89 1892 1347 >> Yahoo ID: till_vollmer >> Skype: till_vollmer >> www.codemart.de >> till.vollmer at codemart.de >> >> >> >> >> > >> _______________________________________________ >> Ferret-talk mailing list >> Ferret-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ferret-talk > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talkCodemart GmbH Till Vollmer Managing Director Tel: +49 (0)89 1213 5359 Mob: + 49 (0)160 718 7403 Fax: +49 (0)89 1892 1347 Yahoo ID: till_vollmer Skype: till_vollmer www.codemart.de till.vollmer at codemart.de -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20071120/1fd65759/attachment.html
If it''s all the same class, then don''t index children: def ferret_enabled?(is_rebuild = false) @ferret_disabled.nil? && self.root? end Only root nodes would get indexed with the above method (and an appropriate root? definition) in place. AFAIK, there is no group_by concept in aaf. At the same time, I don''t think it''s really necessary. The above, combined with a single method definition for children_titles_with_spaces should get you exactly what you''re looking to do. -Chris On Tue, Nov 20, 2007 at 03:08:52PM +0100, Till Vollmer wrote:> Hi, > Thank you for your answer. > > The root and the nodes are in the same table for us. > Is there no "group_by" or something for ferret? That would probably make > the deal. > > Regards > Till > > Am 20.11.2007 um 14:36 schrieb Chris Strom: > >> If you are using acts_as_ferret, it will never get called. The >> acts_as_ferret declaration would go on the root class. Updates to the >> child classes would not trigger an aaf index update in the root class. >> >> If you want to real-time index updates, you would have to add an >> after_save callback to the child class that forces an aaf update in the >> root class. >> >> If real-time updates are not too important, then you could dump the child >> updates into a queue that performs bulk updates. This would minimize the >> number of times this method gets called. >> >> If you''re worried about 200+ SQL calls, don''t perform the join in ruby, do >> it via SQL using CONCAT and "Advanced Attribute" as described in AWDWR, >> 19.3. >> >> -Chris >> >> On Tue, Nov 20, 2007 at 02:01:39PM +0100, Till Vollmer wrote: >>> Hi, >>> Thank you for the clue. >>> Ok, like a virtual attribute. Works technically but: >>> Downside: How often is that called ? Our tree has e.g. 200 children. This >>> means that the children are collected on every change of one of the >>> children (index) or? >>> Any other ideas? >>> Regards >>> Till >>> >>> >>> Am 20.11.2007 um 13:52 schrieb Chris Strom: >>> >>>> On Tue, Nov 20, 2007 at 01:17:30PM +0100, Till Vollmer wrote: >>>>> Hi, >>>>> >>>>> Following problem: >>>>> >>>>> We have a tree structure with children and a root element (recursivly) >>>>> stored in one table (imagine a threaded forum). >>>>> >>>>> Each of the children has a title which should be indexed by ferret. >>>>> >>>>> Now we want to make a search that returns only the root and searches >>>>> all >>>>> items. >>>>> >>>>> >>>>> So if one node has "expensive" and nother node has "car" I want to >>>>> enter >>>>> "expensive car" in search and still find the root of all children (and >>>>> only once!) >>>>> >>>>> Also paging should work as well. >>>>> >>>>> Any clues how to achieve that? >>>> >>>> An instance method in the root class to the effect of >>>> children_titles_with_spaces would get you this. That method would >>>> return >>>> "expensive car" given your simple, two-node example, which would be >>>> indexable with the normal analyzer. >>>> >>>> -Chris >>>> _______________________________________________ >>>> Ferret-talk mailing list >>>> Ferret-talk at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/ferret-talk >>> >>> Codemart GmbH >>> Till Vollmer >>> Managing Director >>> Tel: +49 (0)89 1213 5359 >>> Mob: + 49 (0)160 718 7403 >>> Fax: +49 (0)89 1892 1347 >>> Yahoo ID: till_vollmer >>> Skype: till_vollmer >>> www.codemart.de >>> till.vollmer at codemart.de >>> >>> >>> >>> >>> >> >>> _______________________________________________ >>> Ferret-talk mailing list >>> Ferret-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ferret-talk >> _______________________________________________ >> Ferret-talk mailing list >> Ferret-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ferret-talk > > Codemart GmbH > Till Vollmer > Managing Director > Tel: +49 (0)89 1213 5359 > Mob: + 49 (0)160 718 7403 > Fax: +49 (0)89 1892 1347 > Yahoo ID: till_vollmer > Skype: till_vollmer > www.codemart.de > till.vollmer at codemart.de > > > > >> _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk