Widget filter_mode

I’m working on widgets for results for a profile search and have already looked at these pages:

https://support.livewhale.com/live/blurbs/search#Setting-up-search

https://support.livewhale.com/docs/widget-and-api-settings/#filtering-and-sorting

With respect to the filter_mode argument it looks like it is only one or the other for all the widget filters, but I need more complex boolean logic. I want to be able to have a filter that checks a variable for a specific value like:

<arg id="filter" name="profiles_160" action="matches">something</arg>

which would be required for all matches, but then have several filters matching against the search term, and one of which would allow a successful match as long as that first filter was matched:

<arg id="filter" name="profiles_156" action="matches"><xphp var="q" type="get"/></arg>

so first filter AND (second filter OR third filter OR fourth filter…)

if I use ‘any’ for filter_mode, I get results that might not satisfy the first filter.

Hope that makes sense.

If this is not currently possible then this is a feature request…!

Thanks,

-= G =-Preformatted text

Hi G,

I know what you mean – the short answer is, we don’t currently support mixing-and-matching of AND and OR logic in those widget filters out of the box, but there is a workaround we’ve used helpfully in this type of situation.

The workaround is, using the fallback setting to override with new filters sequentially until results are found. We’ve often set up search widgets with that kind of approach:


<!-- One or more very precise filters -->
<arg id="filter" name="..." action="equals">...</arg>
<arg id="filter" name="..." action="equals">...</arg>
<arg id="fallback">
    <!-- If no results, zero out and try again less precisely -->
    <arg id="filter"></arg>
    <arg id="filter" name="..." action="matches">...</arg>
    <arg id="filter" name="..." action="matches">...</arg>
</arg>
<arg id="fallback">
    <!-- If no results, zero out and try again with generic search -->
    <arg id="filter"></arg>
    <arg id="search">...</arg>
</arg>

The advantage of this is it lets you privilege certain types of results in search results pages (i.e. where the title is, or contains, an exact match). The disadvantage is the fallback code will only show whichever block has results—in the above example, if my “equals” code has results, then the “matches” version won’t get triggered. A custom module could be used to do that, to use $_LW->read() to pull results matching criteria 1, and then filter them with PHP to return results matching criteria 2 OR 3 OR 4. Hope this helps!

Thanks - that confirms what I thought. Those alternate ways would be good for some things, but unfortunately, not in my case. I may try the module approach when time permits…

-= G =-