Searching FAQs in MIGX TVs on a Single Resource

Hi all,

I have a resource which contains a list of categorised FAQs in MIGX TVs. In total there are 15 MIGX TVs, all identical apart from their names and contents:

faqsAboutUs
faqsConsumers
faqsRetailers
etc …

On the main FAQs page I call each in turn via a chunk / getImageList call to give a full categorised list of FAQs [in the form of accordions].

Fine.

On individual pages I call only the FAQ I require.

So, on the About Us page, for instance, I call on the faqsAboutUs chunk after the main content.

Fine

The client has now asked if we can make these FAQs searchable - and I’m struggling to come up with a solution.

Using SimpleSearch, we’d be restricting the search to just the FAQs page [and include the TVs] and all results would, I think, just point to that page. In fact there would only ever be one result. The FAQs page.

I’d be open to the idea of creating an individual page for each of the FAQs categories, but since the data lives in a TV for another resource, I don’t see how I can search it.

Since all the search extras seem to focus on the content of the database [as opposed to the rendered output of each page] - I’m not sure this is even possible without creating some custom search system to make it happen. Or pushing the FAQs content out into resources and binning the MIGX TVs altogether.

Am I missing something obvious?

Any thoughts much appreciated as always.

Chris

Can’t you just create a search form, and then filter your output with a where property in your call to getImageList if there is a search-value in the request?

Or implement a client-side filtering in Javascript?

That’s an interesting idea @halftrainedharry - slightly complicated by the fact that there are 15 separate categories / getImageList calls but I’m going to take a look at it.

Thanks as always.

Chris

My answer was probably a bit premature. I’m not sure that it really works with the &where property.

The problem is that when you want to search for a value in two different fields (here the fields “question” and “answer”) there seems to be no way to define a OR-condition.

[[!getImageList?
    ...
    &where=`{"question:contains":"whatever","answer:contains":"whatever"}`
]]

This example only returns the row if the search value (here “whatever”) is found in both the fields.

Therefore you probably have to code something yourself.


Are you familiar with MIGXdb?
With MIGXdb the data is saved in a custom database table and searching that is much easier.

Thanks for that - I was just about to start looking at how to add the OR

I’m not [yet] familiar with MIGXdb but I know I probably should be.

For the purposes of this site I’m thinking maybe I’ll just move the FAQs into resources. I think that will solve all my problems, despite being a more clumsy way of storing such info.

MIGXdb next on my list to get a grip of.

Thanks once more @halftrainedharry

It you want to make it work with the current structure and little effort, you could duplicate the snippet getImageList and replace these lines

with some custom filtering. Like:

$queryVar = $modx->getOption('queryVar', $scriptProperties, 'search'); //name of $_GET parameter
if (isset($_GET[$queryVar])) {
    $search_value = filter_var($_GET[$queryVar], FILTER_SANITIZE_STRING);
    
    $tempitems = array();
    //loop all the items
    foreach ($items as $item) {
        if ((stripos($item["question"], $search_value) !== false) || (stripos($item["answer"], $search_value) !== false)){
            //search value found in field "question" or "answer"
            $tempitems[] = $item;
        }
    }
    $items = $tempitems;
}

Also MIGXdb isn’t that hard. Especially if you already know MIGX.

1 Like