Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-01-15 08:45:50

pin
New Member
Registered: 2013-01-15
Posts: 4

etc_search and rss_unlimited_categories

hello everybody,
Two questions about etc_search because I’m not good with query syntax
1) what code I have to write in order to sort the etc_search results by sections?
2) In order to let it search also among the native categories of textpattern I wrote this code: <txp:etc_search query=”{Title,Body,category1,category2}” />
and it works. But now I’ve added new categories via rss_unlimited_categories plug in.
What code I have to write in order to search also among categories created with rss_unlimited_categories?

As an absolute beginner I wrote this:

<txp:etc_search query=”|||*SELECT category_id FROM textpattern_category |||{Title,Body,category1,category2}” />

and of course it doesn’t work! Any suggestion?
I Need an help, thank you in any case!

Offline

#2 2013-01-15 12:07:16

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

Re: etc_search and rss_unlimited_categories

Hi pin,

for advanced searches like this, you need to write a complete MySQL query. Try

<txp:etc_search query="{Title,Body,category1,category2}|||*SELECT txp.* FROM textpattern txp JOIN textpattern_category rss ON txp.ID=rss.article_id JOIN txp_category cat ON rss.category_id=cat.id WHERE cat.type='article' AND {cat.name,cat.title}" />

Offline

#3 2013-01-15 19:54:52

pin
New Member
Registered: 2013-01-15
Posts: 4

Re: etc_search and rss_unlimited_categories

thank you very very much Oleg! I did copy and past and seems to work correctly!!
I’ve tried to read the code you wrote but it’s like “mars” language for me, I’m not a developer.
Could you suggest me also some idea to sort the results? There’s a general query to do it? In particular I would like to sort the etc_results by “sections” but there’s nothing in the optional attributes for that.
I think your plug is absolutely great but very difficult for a non-professional like me!

Offline

#4 2013-01-15 21:17:35

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

Re: etc_search and rss_unlimited_categories

pin wrote:

I’ve tried to read the code you wrote but it’s like “mars” language for me

If you mean plugins code, that’s what I feel too, looking at it two months after the release. :) Actually etc_search is a very simple plugin, it just displays the results of your MySQL search queries. Advanced searches require some knowledge of MySQL, but learning it will not be a waste of time, anyway.

Could you suggest me also some idea to sort the results? There’s a general query to do it? In particular I would like to sort the etc_results by “sections” but there’s nothing in the optional attributes for that.

There is no sort attribute, but you can add ORDER BY clause to your MySQL query. Something like this might work (though that’s a heavy query):

<txp:etc_search query="*SELECT DISTINCT txp.* FROM textpattern txp LEFT JOIN textpattern_category rss ON txp.ID=rss.article_id LEFT JOIN txp_category cat ON rss.category_id=cat.id WHERE {txp.Title,txp.Body,txp.category1,txp.category2,cat.name,cat.title} ORDER BY txp.Section, txp.Title" />

Someone with a good MySQL knowledge could certainly find a better way, all suggestions are welcome.

Edit: this should be a little faster:

<txp:etc_search query="*SELECT * FROM textpattern WHERE ID IN (SELECT DISTINCT txp.ID FROM textpattern txp LEFT JOIN textpattern_category rss ON txp.ID=rss.article_id LEFT JOIN txp_category cat ON rss.category_id=cat.id WHERE {txp.Title,txp.Body,txp.category1,txp.category2,cat.name,cat.title}) ORDER BY Section, Title" />

Last edited by etc (2013-01-15 22:17:50)

Offline

#5 2013-01-17 07:35:03

pin
New Member
Registered: 2013-01-15
Posts: 4

Re: etc_search and rss_unlimited_categories

I’m testing the last you wrote, and it works properly, and what’s more the last part ORDER BY seems customizable! Many thanks again.

Another question of different kind is about the use of <txp:etc_search_results > tag.
Suppose you have a page called “archive” where in the header of the web page you have:

<txp:etc_search live=“0”/>

then, somewhere in the page you have:

<txp:if_search> <txp:etc_search_results form=“etc_search_results” /> </txp:if_search>

when you make a search,
the etc_search seems to work correctly but at the beginning of the page appears this message:

Tag error: -> Textpattern Notice: Page template archive does not contain a txp:article tag while parsing form “None” on page “archive”

despite this, the etc_search find correctly the results I’ve asked.
To avoid this error message I have inserted a <txp:article/> like this:

<txp:if_search> <txp:etc_search_results form=“etc_search_results” /> <txp:article pgonly=“1” /> </txp:if_search>

this way everything works without producing the error message,
but it not seems very smart to me and now I wonder if I’m wrong with the use of <txp:etc_search_results> tag: why I need <txp:article pgonly=“1” /> to avoid the error?

Sorry for annoying you with all these questions…

Offline

#6 2013-01-17 08:58:32

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

Re: etc_search and rss_unlimited_categories

Oops! seems like I have never tested it in debug mode since the introduction of etc_search_results, thank you for the report. Spotted a silly typo ($false instead of false), please redownload or fix it yourself in the code. You will also get in this version a <txp:etc_search_result_excerpt /> tag, which can replace <txp:search_result_excerpt /> in search_results form.

why I need <txp:article pgonly=“1” /> to avoid the error?

You don’t, even the devs agree that you should ignore this obsolete warning. The problem is that txp search is integrated into <txp:article />, so if you keep it, you will get search results twice. Adding <txp:article pgonly="1" /> will increase the runtime, up to you to decide.

Sorry for annoying you with all these questions…

You don’t. :)

Offline

#7 2013-01-17 21:51:47

pin
New Member
Registered: 2013-01-15
Posts: 4

Re: etc_search and rss_unlimited_categories

I’m new to textpattern and I like it a lot despite the fact I’m not very smart with it. Thank you Oleg for your precious help and for the time you waste for me. By the way, I don’t see any “donate” button on your website…

Offline

#8 2013-01-17 22:16:16

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

Re: etc_search and rss_unlimited_categories

pin wrote:

I’m new to textpattern and I like it a lot despite the fact I’m not very smart with it. Thank you Oleg for your precious help and for the time you waste for me. By the way, I don’t see any “donate” button on your website…

Welcome to the club, and beware the addiction! My time is not wasted, I enjoy coding and like to share, so your feedback fully rewards me. Should you still feel indebted, here is the most appropriate donate button…

Offline

Board footer

Powered by FluxBB