[pmwiki-users] Search for several words with OR operator

Petko Yotov 5ko at 5ko.fr
Sun Oct 8 07:53:31 PDT 2023


With PmWiki 2.3.26, it should now be possible to enable search of at 
least one item from the search box. Add to config.php:

   $EnableSearchAtLeastOneTerm = 1;

See the documentation. In such a case, to require some terms, precede 
them with "+" such as +term1 +term2.

With this variable enabled, if you're using the snippet I suggested 
earlier, you could replace it with this, it should be about 3 times 
faster:

    $list = [];
    $opt = [''=>['word1', 'word2', 'word3'] ];
    FPLTemplatePageList($pagename, $list, $opt);
    # now $list has all pages that contain word1 OR word2 OR word3

(To require terms, you'd have something like:

    $opt = [''=>['at', 'least', 'one'], '+'=>['required1', 'required2'] 
];
)

Petko


On 29/06/2023 10:49, Petko Yotov wrote:
> On 29/06/2023 10:02, Gregor Klarič wrote:
>> I am trying to find all pages which contain word1 OR word2 OR word3
>> 
>> Is this possible?
> 
> Not exactly out of the box, but in a custom function you can do this:
> 
>   $list = [];
> 
>   $opt = [''=>['word1'] ];
>   FPLTemplatePageList($pagename, $list, $opt);
> 
>   $opt = [''=>['word2'] ];
>   FPLTemplatePageList($pagename, $list, $opt);
> 
>   $opt = [''=>['word3'] ];
>   FPLTemplatePageList($pagename, $list, $opt);
> 
>   # now $list has all pages that contain word1 OR word2 OR word3
> 
> 
> Out of the box something similar can be achieved with categories:
> 
>   https://www.pmwiki.org/wiki/PmWiki/Categories
> 
> Pages can belong to multiple categories and can be shown with
> Pagelists in very flexible ways, for example:
> 
>   !! All pages from Cat1 OR Cat2 (at least one)
>   (:pagelist category=Cat1,Cat2:)
> 
>   !! All pages from Cat1 AND Cat2 (both)
>   (:pagelist category=+Cat1,+Cat2:)
> 
> See https://www.pmwiki.org/wiki/PmWiki/PageLists#wildcards
> 
> And you can format the list with a custom pagelist template if you 
> want.
> 
> Petko



More information about the pmwiki-users mailing list