Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-06-25 19:31:44

visualpeople
Member
From: Corvallis, Oregon - USA
Registered: 2005-11-16
Posts: 73
Website

Can I search custom fields?

I’ve searched high and low for this answer and can’t come up with anything definitive.

An old blog post — mostly in german — suggests a hack, which I sort of tried, but maybe didn’t understand completely.

I added ,custom_1,custom_2,custom_3,custom_4,custom_5 and or custom_1 rlike '$q' or custom_2 rlike '$q' or custom_3 rlike '$q' or custom_4 rlike '$q' or custom_5 rlike '$q' to function on lines 33 and 35 respectively of /textpattern/publish/search.php but that doesn’t seem to work and it makes me a little queazy to hack the default install.

I’ve experimented a little with ob1_advanced_search but I just can’t get it configured correctly.

When I first started this project, I thought it’d be a no-brainer — actually I thought the default Textpattern search looked through custom fields — but now I’m stumped.

Thanks in advance for any help/advice.

-Ryan

Offline

#2 2008-06-25 23:35:14

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Can I search custom fields?

Hi Ryan,

some lines above the spot you’ve inserted the custom fields stuff there is one line (582) that perplexes me: if($q && !$iscustom && !$issticky). I don’t claim to really understand this, but just try to remove !$iscustom && from that part and see if it works now :)

Edit: Nice try, but too easy. Comment on $iscustom (line 558): // if an article ID is specified, treat it as a custom list :/

Last edited by uli (2008-06-25 23:55:59)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2008-06-26 17:25:22

visualpeople
Member
From: Corvallis, Oregon - USA
Registered: 2005-11-16
Posts: 73
Website

Re: Can I search custom fields?

Blast! I thought maybe you had it… thanks for your input anyway!

Offline

#4 2008-06-26 17:56:09

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

Re: Can I search custom fields?

Although it’s perhaps not pretty to code and might be a bit slow you could experiment with a technique like this. Essentially, it performs a fake “search” by calling article_custom with a form attribute. That passes every article (from your chosen section) to the form so you can then use smd_if to look at the custom field info for matches. If the tests are positive, you print a chunk of the body content (rvm_substr? rss_auto_excerpt?) and a link to the article.

Like I say, if you’re trying to match all custom fields with all data in all articles it could take a long time. Pre-filtering your results or giving people the option to only search certain sections/custom fields will drastically reduce the entropy.

Failing that — if you can wait for me to get my head above water again — I might be able to find time to enhance smd_query to allow you to pass URL variables into it safely. Then you could perform the query yourself if you fancied writing a bit of SQL.


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 2008-06-26 23:10:47

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Can I search custom fields?

As long as Stef/Bloke is with his head under code, I have some time to solve another riddle ;)

I’ve tried to duplicate the changes proposed on the German site … and got it working. Was a no-brainer, in deed ;) … ‘coz I’ve made two mistakes on the way, both resulted in error messages:

  1. I had no form by the name “search_results”
  2. In phpMyAdmin the “Save” button is placed on a number two position, left hand side of the “OK”, so I forgot to press it, and hit OK for a second time instead.

I tip the latter. Check for the “searching” entries in the “textpattern” DB table.
If not, a) what are the error messages you get displayed (in debugging mode), if any? b) Please post the changed code lines completely.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2008-06-26 23:22:56

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Can I search custom fields?

Even easier! You’ve changed the wrong file! You posted you’ve changed textpattern/publish/search.php, but textpattern/publish.php needs to be altered, somewhere around line 590 :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB