Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-05-21 05:20:37

ibadullah
Member
From: Kabul, Afghanistan
Registered: 2017-09-16
Posts: 49

Advance Search plugin for textpattern

hi
i am looking for advance Search plugin for public side where it have two or three fields, and a person can search the article by category, and keywords.

Offline

#2 2021-05-21 07:55:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

<txp:article_custom> can filter by category and section and keywords. All you need to do is send the values from your input boxes to the URL (e.g. ?c=marvel&key=iron-man,thor then you can use <txp:page_url /> to capture those and construct article tags with appropriate options based on the content passed to the page via URL.

But first I’d check out etc_search and see how well you can bend that to your needs. It’s possible to customize the queries quite heavily, iirc.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-05-21 08:18:42

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Advance Search plugin for textpattern

Why not use <txp:article /> itself? You will get the category filter for free, sending ?c=cat from your search input form to the search page URL. To filter by keywords, call

<txp:article keywords='<txp:page_url type="key" />' />

and send

?c=cat&key=some,keywords,list or ?c=cat&key[]=some&key[]=keywords&key[]=list

etc_search looks a bit overkill here.

Offline

#4 2021-05-21 10:51:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

Good point. Forgot that <txp:article> now also had those superpowers. Nice solution!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2021-05-21 12:41:41

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Advance Search plugin for textpattern

This should be even easier in 4.8.6: just send ?c=cat&keywords=some,keywords,list to

<txp:article match="category, keywords" />

Or, if you need to fine-tune, ?c1=cat&key[]=some&key[]=keywords&key[]=list to

<txp:article match="category1=c1, keywords=key" />

Offline

#6 2021-05-21 13:32:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

Sweet!

For documentation/genealogy purposes, btw, was match introduced to the article tag at the same time as it was for <txp:article_custom> (i.e. 4.6.0ish)? And also, what options are available to match? Is it any field, or just specific ones?

I’m just updating the article(_custom) tag docs now to capture this example and figured I might as well update the entire tag attribute set while I’m at it.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2021-05-21 19:50:18

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Advance Search plugin for textpattern

Bloke wrote #330238:

was match introduced to the article tag at the same time as it was for <txp:article_custom> (i.e. 4.6.0ish)? And also, what options are available to match? Is it any field, or just specific ones?

Yes, article_custom has inherited match from related_articles when absorbing the latter (which was its near clone). Since article and article_custom share their code (up to few attributes), they both accept match now.

IIRC, match in this context can be a list of

'category', 'category1', 'category2', 'keywords' + custom fields

or field=alias items. The latter form is roughly equivalent to field='<txp:page_url type="alias" />' attribute if alias URL variable is set.

Offline

#8 2021-05-21 21:28:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

Cool, thanks. That’s kinda what I figured. I’ve updated the tag doc and hopefully it’s up-to-date now, but if I’ve missed any attributes, feel free to fix the page or let me know and I’ll do it. Ta!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2021-05-28 10:42:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

Any idea what am I doing wrong with this, Oleg? Probably something obvious…

I have a bunch of articles and have used the keywords field to list various characters like batman, tron, iron man, green lantern, …

On a fresh install in my archive Page template if I change the if_article_list article tag to:

<txp:article keywords='<txp:page_url type="keywords" />' class="article-list" form="article_listing" limit="10" wraptag="ul" />

It’s all good. If I manually add ?keywords=iron man, batman to the URL then I only see the articles that match any of the keywords (not all, but we can have that discussion about how to let people choose any/all another time when we turbocharge keywords to act more like tags).

However, if I alter the tag to this:

<txp:article match="keywords" class="article-list" form="article_listing" limit="10" wraptag="ul" />

and then pass in ?keywords=iron man, batman on the URL, I always get all articles, regardless of what URL filters I add. The query isn’t adding the keyparts:

First query:

SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 AND `Posted` <= from_unixtime(2147483647) AND (Expires IS NULL OR from_unixtime(2147483647) <= Expires) AND Section  IN ('articles') AND Status IN (4) AND (FIND_IN_SET('batman', Keywords) or FIND_IN_SET('iron man', Keywords)) ORDER BY Posted DESC LIMIT 0, 10

Second query:

SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 AND `Posted` <= from_unixtime(2147483647) AND (Expires IS NULL OR from_unixtime(2147483647) <= Expires) AND Section  IN ('articles') AND Status IN (4) ORDER BY Posted DESC LIMIT 0, 10

Do I need to do anything else to wire it up?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2021-05-28 10:55:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

P.S. If you sprinkle your site with rah_repeat, the following works wonderfully well in your default article form to simulate hashtag searches in the keywords field that will then find articles that match the clicked tag in the current section:

TAGS: <rah::repeat value='<txp:keywords />'>
    <a href="<txp:site_url /><txp:section />/?keywords=<rah::repeat_value />">#<rah::repeat_value /></a>
</rah::repeat>

It only currently works with <txp:article keywords='<txp:page_url type="keywords" />' /> as mentioned above, but it’s ace!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2021-05-28 13:15:10

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Advance Search plugin for textpattern

Doh! Fixed in dev, please merge into 4.8.6 if it’s yet time. Thank you!

Offline

#12 2021-05-28 13:19:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,415
Website GitHub

Re: Advance Search plugin for textpattern

Still time… that’s what this final testing phase is for :) I’ll get on it now.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB