Searching in MODX-extras

I would just like to mention - I really love MODX and I am using it for many years now. I love the open-system and the opportunity to do everything you want to do - as it seems to me. But you have to have the knowledge and skills in order to achieve what you want with a lot of scripting and individual solutions. MODX is my preferred CMS, which I always recommend when someone wants to know my two cents. I think I learned a lot in these past years, whether from the forum or via stackoverflow. But I am still highly limited, as I am now experiencing again while doing these current projects.

Additionally I love the MODX-community and the ongoing will of many to help others on here and back in the old forum. Especially some forum-members, that never gave up helping someone, no matter how hard or easy the task has been. I guess you know the many ones I am talking about…
So I did not want to offend anyone with my statement “kind of useless”! I really appreciate the effort everyone has done by creating an extra. I only can imagine how much work this might be. Or anyone who has even giving a hint or a thought on an issue in the forum. Many thanks for that!

So back to my task…

Inbetween I tried a lot of other things i read in this forum and the old one…tried again several SimpleSearch-ways with the extractSource and customPackages-options, but basically the same as described in my other post on here…

By using this SimpleSearch-call:

[[!SimpleSearch? 
    &tpl=`mySearchResult` 
    &extractSource=`faqMan`
    &includeTVs=`1`
    &processTVs=`1`
    &customPackages=`faqManItem:id,question,answer,set:faqman:{core_path}/components/faqman/model/:faqManItem.id = modResource.id` ]]

and this chunk:

<div class="simplesearch-result">
    <h3>[[+idx]]. <a href="[[+link]]" title="[[+longtitle]]">[[+pagetitle]]</a></h3>
    <div class="extract">
        <p>[[+extract]]</p>  [[+tags:tagsTest]]
    </div>
</div>

i am able to find something with the given search-term “test”. But the last part

:faqManItem.id = modResource.id

is wrong, because the faqManItem.id is not the resource-id, where the FAQ-Manager is held on. So i thought I might be able to predefine the resource ID, where the FAQ-Manager-call is used, and “build” a hash, that contains the FAQ-Manager-entry ID - so that I could be able to click on the result-list-link, get redirected to the FAQ-Manager-page with the correct hash, then scroll to an anchor with that hash. But I wasn’t able to create the hash-part.

But additionally, I am getting all other resources listed which have the same search-term “test” somewhere in the content or pagetitle. The usual [[+extract]] just shows the content of the FAQ-Manager entry, and not an extract of the content like usually…bummer :frowning: Even when I am entering a search-term “welcome”, which is not available in the FAQ-Manager-entry (I only created one for testing purposes), the search-result-entry still contains the content of the FAQ-Manager-entry, not the extract of the content from the resource.

Additionally I just found out, that SimpleSearch does even find inputs, which have the search-term included somewhere.

I used these simple calls:

[[!SimpleSearchForm]]

[[!SimpleSearch]]

with the search-term “test”, and I am getting listed a page, that does contain this input field:

<input type="hidden" name="test" value="Customer News">

Shouldn’t be listed in the results-list, or should it? Sure, the search-term “test” is given, but as the name of a hidden input-field…this shouldn’t be listed in the search results in my opinion?

I also found different posts about the Advsearch-extra, like this one AdvSearch + Tagger and using fieldPotency | MODX Community Forums and this one Filter Results using AdvSearch and Tagger with Queryhooks | MODX Community Forums, which provided snippet-codes are quite nearly the same…

These looked promising, as the script checks for both needed tables for the Tagger-DB-entries - modx_tagger_tag_resources and modx_tagger_tags. But those solutions didn’t work for me either.

Additionally i tried to enhance the snippet-part to search in the FAQ-Manager-entries and/or the Glossary-entries like this:

<?php

$modxTablePrefix = 'modx_';

$taggerModelPath = '{core_path}components/tagger/model/';
$faqManModelPath = '{core_path}components/faqman/model/';
$glossaryModelPath = '{core_path}components/glossary/model/';

$hook->setQueryHook(array(
    'qhVersion' => '1.2',
    'joined' => array(
        array(
            'package' => 'tagger',
            'class' => 'TaggerTagResource',
            'packagePath' => $taggerModelPath,
            'withFields' => 'resource',
            'tablePrefix' => $modxTablePrefix,
            'joinCriteria' => 'TaggerTagResource.resource = modResource.id'
        ),
        array(
            'package' => 'tagger',
            'class' => 'TaggerTag',
            'packagePath' => $taggerModelPath,
            'withFields' => 'tag',
            'tablePrefix' => $modxTablePrefix,
            'joinCriteria' => 'TaggerTag.id = TaggerTagResource.tag'
        ),
        
        array(
            'package' => 'glossary',
            'class' => 'Term',
            'packagePath' => $glossaryModelPath,
            'withFields' => 'term',
            'tablePrefix' => $modxTablePrefix,
            'joinCriteria' => 'Term.id = modResource.id'
        )               
        
    )
));

return true;

but - quelle surprise…no luck…I was too optimistic.

I also tried to only use the glossary-array, and to only use another faqman-array…

    array(
        'package' => 'faqman',
        'class' => 'faqManItem',
        'packagePath' => $faqManModelPath,
        'withFields' => 'quesion',
        'tablePrefix' => $modxTablePrefix,
        'joinCriteria' => 'faqManItem.id = modResource.id'
    ),

…but no luck again.

At this point important for me is to have a tagging-option for the content-editor to add tags to resources and make them searchable through - preferably - SimpleSearch.

After some more research I tried the Auto-Tag-TV and Tag-TV, which I never used before. On first sight it looked promising as well, although the output-options like “delimiter” or “HTML-Tag” did make no difference. I could manage/style the output with a custom-snippet, but tbh I thought the output-options would help on this.

And woohay - with SimpleSeach and &includeTVs and &processTVs I could even search for those test-tags i enterred via the Auto-TV-Tag. But again, using SimpleSearch does show results with inputs, that have the search-term in their name-property (as described above) - and/or maybe somewhere else as well. And I still cannot search in FAQ-Manager or Glossary…hm…

I also found this thread Performance issue with Auto-Tag TV type | MODX Community Forums where (the famous) Bruno mentioned:

I think you could create a extra table, which holds all used tags and a plugin, which actualises its entries by onDocFormSave and some other System-Events

To get the tags into a multiple-listbox-TV you could use a @SELECT or @EVAL-binding
To create new tags, use a extra TV, which you can read by the onDocFormSave - plugin

at frontend you could use rowboat, for example, to get the tags into the tagcloud.

This should generate the tags in frontend and backend much faster.

So the Auto-Tag-TV or Tag-TV do not seem to be the best choice for the use of many different tags…So I am back to point zero and don’t know where to start or tweak or whatever to do…

1 Like