Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-01-16 20:13:15

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Too many search results [solved]

Edit: This topic once was posted in the Seeking Txp pros forum, could be solved there, but is too useful to go stale in that diaspora.

Original post:
I have a site that relies on the rah_link_search plugin to search for links. I am looking for a Textpattern Pro trying to make pagination work for the search results. In the new default theme, pagination is implemented for article searches. This solution should be adapted in order to work with link searches, but this seems to be difficult. This is because this pagination relies on Textpattern’s search tags and other tags like newer and older, and these tags work only for article searches.

{Edited to add the introduction and make a new title. -Uli}

Last edited by uli (2012-01-29 17:15:05)

Offline

#2 2012-01-29 07:28:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: Too many search results [solved]

can you not have a large number in your search results?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2012-01-29 07:40:09

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: Too many search results [solved]

No, the problem was, that when a user would enter “a” or “e”, then thousands of results would be retrieved.

Offline

#4 2012-01-29 08:20:02

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: Too many search results [solved]

What I did is simply to truncate the search after 200 results. The nice thing about textpattern search, and about link search, is that you can enter multiple terms, and they are linked with “and”. Therefore, I think that it is sufficient to truncate the search, and tell the user to enter more specific search terms.

Offline

#5 2012-01-29 09:29:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,597
Website

Re: Too many search results [solved]

You could also test how long the search term is and ask the user to try again if it’s too short. The following (untested) code should do that.

Put this at the top of your if_search area:

<txp:variable name="searchterm_minchars" value="4" />
<txp:variable name="searchterm_tooshort"><txp:php>
   global $variable, $q;
   echo ( strlen(trim($q)) < intval($variable['searchterm_minchars']) ) ? 'yes' : '';
</txp:php></txp:variable>

and then in your page template use an if_variable conditional to check if the search term is long enough, e.g.:

<txp:if_variable name="searchterm_tooshort" value="yes">
  <p>Sorry, your search term ‘<em><txp:search_term /></em>’ is too short. 
     Please try again with a word with at least <txp:variable name="searchterm_minchars" /> letters.</p>
<txp:else />
  <!-- your search results here as normal -->
</txp:if_variable>

The minimum length for a search term can be hard-coded into the php, but I put it in the variable searchterm_minchars variable so that you can re-use it later, and so that you can make it user-editable by setting it up in adi_variable. In the latter case, use adi_variable instead of the first line of the first code snippet to set the variable.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2012-01-29 10:09:30

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: Too many search results [solved]

The following (untested) code should do that.

Thanks! That works like a charm. Something for the core?

Last edited by ax (2012-01-29 10:30:17)

Offline

#7 2012-01-29 16:59:47

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

Re: Too many search results [solved]

That’s a cool solution, jakob!
ax, I’ll move this topic to the How-Do-I forum, stripping some of the now unnecessary sentences/posts, so it has a wider audience and can be found in restricted forum searches.


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

Offline

Board footer

Powered by FluxBB