Coroico / AdvSearch

Dynamic content search add-on for MODx Revolution that supports results highlighting, faceted search and search in custom packages
21 stars 14 forks source link

&parents property #53

Closed goldsky closed 10 years ago

goldsky commented 10 years ago

Are we missing &parents property as the condition?

Coroico commented 10 years ago

Not a missing. Use GetIds addon to specify complex list of ids.

GetIds : http://modx.com/extras/package/getids

goldsky commented 10 years ago

I knew you would say that, yeah, I've used that. But it's not efficient. Why would you need to use additional snippet to collect containers' children, if you can directly use their parent's ID to condition? We have a choice to minimize overhead.

Imagine you have thousands of products, under several categories, and AdvSearch can be used for the search engine.

This is the comparison.

The example has 3 categories, which have 1000 resources each of them.

<?php

define('MODX_API_MODE', true);
// this goes to the www.domain.name/index.php
require_once dirname(dirname(__FILE__)) . '/index.php';

$numberOfResource = 1000;
for ($i = 0; $i < $numberOfResource; $i++) {
    $resource = $modx->newObject('modResource');
    $resource->set('pagetitle', 'Products ' . $i);
    $resource->set('parent', 8);
    $resource->set('published', 1);
    $resource->set('template', 1);
    $resource->set('content', '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla adipiscing velit sit amet ante luctus, nec euismod dolor gravida. Mauris a eleifend quam. Praesent sit amet mi vitae justo placerat auctor. Vestibulum iaculis interdum molestie. Phasellus euismod arcu sit amet ligula adipiscing euismod. Integer tristique vehicula metus eget tempor. Vivamus at lacus augue. Duis cursus porta tellus quis dictum. Cras non odio dolor. Cras et lorem purus. Nunc ut placerat arcu.</p>'
            . '<p>Integer porttitor ac felis at imperdiet. Suspendisse tempor pellentesque enim aliquet condimentum. Integer nibh leo, tempor quis mollis quis, varius ut sem. Duis semper, purus sed placerat vehicula, ante dolor luctus erat, at facilisis eros odio id eros. Aenean at dui viverra, tincidunt nisl at, pharetra leo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean placerat neque eget dui porttitor, eu eleifend massa consequat. In consequat metus at lacus luctus, quis tempor elit tempus. Nunc libero odio, cursus at elit fringilla, malesuada porttitor orci. Suspendisse non gravida ante. Integer vitae dapibus odio. Curabitur a justo lacus. Praesent libero diam, sollicitudin in tempor vitae, hendrerit ac nisi. Maecenas sit amet neque vitae sapien venenatis vulputate. Cras porttitor volutpat neque, a interdum nisi sodales nec.</p>');

    $resource->save();
}

echo 'Done!';

I added Executioner snippet to log the speed, and searched random text of the content. The call:

[[!Executioner?
    &tElement=`AdvSearch` 
    &_ids=`[[!GetIds? &ids=`c6,c7,c8`]]`
    &parents=`6,7,8`
    &withAjax=`1`
    &minChars=`3`
]]

1st attempt:

Using GetIds :

Your log: 3000 results found for "gravida" - Server elapsed time: 0.3263s
Executioner: modSnippet: AdvSearch executed in 0.3517 s

Using &parents:

Your log: 3000 results found for "gravida" - Server elapsed time: 0.2872s
Executioner: modSnippet: AdvSearch executed in 0.3122 s

2nd attempt:

Using GetIds :

Your log: 3000 results found for "phasellus" - Server elapsed time: 0.3630s
Executioner: modSnippet: AdvSearch executed in 0.3886 s

Using &parents:

Your log: 3000 results found for "phasellus" - Server elapsed time: 0.3053s
Executioner: modSnippet: AdvSearch executed in 0.3306 s

3rd attempt:

Using GetIds :

Your log: 3000 results found for "interdum" - Server elapsed time: 0.3543s
Executioner: modSnippet: AdvSearch executed in 0.3806 s

Using &parents:

Your log: 3000 results found for "interdum" - Server elapsed time: 0.3168s
Executioner: modSnippet: AdvSearch executed in 0.3433 s

Ran on my WinXP box, 2GB RAM, Apache/2.4.3 (Win32) OpenSSL/0.9.8x PHP/5.4.10

You can see the difference. The numbers might not significant, as the search text was only 1 word, against 3000 resources. But for a newspaper website, or whatever search driven website, which might has more than tens of visitors each second, especially if the site is using Babel which duplicates all the resources for each of languages, this becomes crucial.

What do you think?

Coroico commented 10 years ago

You are right. I have merged your proposal.

Now the documentation should be updated with the &parents property.

goldsky commented 10 years ago

Thx, mate. I'll update it.