The website will have holiday properties that need to be categorised according to things like: region, property type, size, pet-friendly, etc. and so I need to create a search function with a corresponding set of drop-down lists for the visitor to select the categories. Not a word search, as I believe SimpleSearch uses.
Saw a paragraph by Bob, who said that template variables were not necessarily our friend in cases like this (I think because all the data is not in one table that can be easily queried?).
So any tips on how to achieve this if not using template variables for the categories and then using TV filters on a getResources call?
I went the TV + getResources route in the past and if the number of criteria is greater than 3 it starts to have the effect that the stroboscope has on migraine sufferers (and the client tells me he wants to use 7 criteria). Below from a simpler search with getResources, which seemed to work okay with 3 criteria in 2011:
Using an extra like ExtraFields or ClassExtender could be an option.
Creating a custom database table (instead of using modResource) could be an option.
Maybe even using Tagger instead of TVs might work better.
Thank you very much yet again. Tagger looks interesting, but I need to work with a very limited set of categories, with drop-down lists on the resource for the editor, but Tagger seems to want a more fluid, open-ended system of tags.
ClassExtender is beaming with Bob’s unique aura, so I will look into that first. PHP is where I am weakest, so this is going to take a while. Thanks again.
P.S. In the old days, perhaps between 2010 and 2015 there seemed to be a flurry of folks writing how-to pieces online about MODX. Am I missing something, or has that dried up now? I expected someone would have written a nice tutorial on how to put together a category-based search function in MODX (without using TV filters, if indeed that is too slow and not the way to go), but I haven’t found one.
I just posted a link in another thread about a CMP tutorial I wrote in 2018 that uses vanilla JS for a search function. It might give you some ideas. I think it would supplement ClassExtender but I’m not sure.
Hej @cottagestuff,
I also use TV for filtering in a project. Each resource has multiple TVs. The values from the TVs (mostly select fields) are retrieved from the values of the parent resources, and the children are the options. This makes it easy for the client to maintain.
Filtering is done via the pdoResources extra and the &where=`{"kitchenworld": "[[!#GET.kitchenworld]]"}` attribute. I use Fenom to check which fields are sent to build the JSON content. You may also wish to check out the filterWhere extra: GitHub - Jako/FilterWhere: Filter resources with request parameters · GitHub
It’s not the fastest because you have to join some tables to perform the filtering. However, it depends on how many resources you have. If you have a good server and good MODX caching settings, it works well.
If you want to filter resources by multiple categories with multiple options, please use Tagger. It is fast and easy to work with. If you have one category with one selectable value a TV is suitable too. But only then.
The decline in MODX’s popularity hasn’t helped.
Also for some common use cases, the russian-speaking MODX community has good solutions (for example mFilter/mSearch in this case), but with the language barrier, it’s harder to find usable information. (mFilter/mSearch are also not open-source, so I can’t test them out myself without paying.)
For an introduction to ExtraFields and ClassExtender I created this Youtube video.
I think it’s hard to give a general answer how best to implement such a search, as it depends on many parameters. If the amount of resources (“holiday properties” in your case) is quite small, you might get away with just using TVs. If you already have a tool for users to manage the “holiday properties” on the front-end, a custom database table might be the way to go. If the “holiday properties” are managed in the MODX manager on the other hand, using modResource will be easier. The skills of the developer also have to be taken into account, as this is more of an advanced topic.
With Tagger, you decide if the editor on the resource can add new tags to a field, or has to choose from a predefined set of options.
If you decide to stick with TVs, use pdoResources (from the pdoTools) and notgetResources, as I believe the resulting SQL query will be less convoluted.
Don’t use TVs of type “Listbox (Multi-Select)” if you have to query them. In such a case, use Tagger instead.
A solution I use for complex searches is jQuery QueryBuilder by mystic100. It’s a JS plugin that creates a UI to get the search criteria and returns a JSON object with the user’s selections. I have PHP code that converts the JSON to SQL that is then used to query custom database tables.
Using it does involve knowledge of Javascript and PHP but I was able to find examples online that I copied. It does require jQuery to run but you can use standard JavaScript to interface to it. An example of it in use is at my site My Online Plant Database.
I would say it’s a solution that is low on limitations and high on success while allowing very complex searches.