Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#25 2005-07-12 02:18:58
- Ray
- Member
- Registered: 2004-03-02
- Posts: 154
Re: search only one section?
Searching one section only as per your instructions works fine. What I’m trying to accomplish is a one section only search that has it’s own search results page.
At first I thought it would be as simple as using a <span style=“color:#cc0000;”>search_input</span> form with a <span style=“color:#cc0000;”>section=“news”</span> in the tag. Like so.
<code><txp:output_form form=“search_input” section=“news” /></code>
Then my search_input form would have the following
<code>
<div id=“searchbox”>
<form action=”/search” method=“get”>
<label for=“searchbox”>Search News Archives</label>
<input type=“text” name=“q” class=“searchfield” size=“15” />
<input type=“submit” class=“button” value=“Find” />
</form>
</div>
</code>
But that didn’t do the trick. Instead of bringing up the search results for the news section only <b>it grabs results from the entire site.</b> The only way I can get a one section only search working is without a custom search results page and just using the tags you suggested. As soon as I build my own search_input form it shows results from the whole site.
Last edited by Ray (2005-07-12 02:19:53)
Offline
#26 2005-07-12 03:07:10
- Ray
- Member
- Registered: 2004-03-02
- Posts: 154
Re: search only one section?
Maybe there’s another way to take care of the things I’m trying to accomplish with a custom search page.
Your solution as mentioned at the top of this thread works fine… however there are two primary issues I’d like to find a solution for.
1) My news page has an article limit of five. If I use the method you suggested then my search results (on that page) are also limited to five hits. If there are more than 5 hits then the Previous/Next page links simply go to the Previous/Next page of the NEWS section. NOT the search results. So, if I search my NEWS section for apples then I will get a list of five hits for apples from my NEWS section but the Previous/Next links don’t go to the next five hits… it goes to the Previous/Next Page of the news section…. pg2 of NEWS.
2) If I can’t have a custom search page AND search by section only then a custom label for the search form would do. There are three primary sections on the site that have articles. NEWS section, PRODUCTS section and EVENTS section. Being able to search each section only would be a bonus. Being able to have a custom search label for each search function would be double bonus.
Being able to have a search by section only AND have a custom search results page for each section PLUS have custom labels for each search form would be simply dreamy. Ice cream and kittens and warm fuzzy mittens kinda dreamy.
Last edited by Ray (2005-07-12 03:13:40)
Offline
#27 2005-07-12 23:39:46
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: search only one section?
This might help, on your news page template:
<pre><code>
<txp:if_search>
<h3>Search results:</h3>
<txp:article searchall=0 limit=50 />
<txp:else />
<txp:article limit=5 />
</txp:if_search>
</code></pre>
Alex
Offline
#28 2005-07-13 01:57:09
- Ray
- Member
- Registered: 2004-03-02
- Posts: 154
Re: search only one section?
I love you. That worked like a charm and will do just fine.
Offline
#29 2005-07-13 03:29:01
- Ray
- Member
- Registered: 2004-03-02
- Posts: 154
Re: search only one section?
Zem… I’m sure I know the answer to this but I want to check anyway. Can I safely remove the wraptag from the search function in publish/taghandlers.php. Line 483. I’d rather control the form and it’s wrap tag with another method.
<code>
function search_input($atts) // input form for search queries
{
global $q, $permlink_mode;
extract(lAtts(array(
‘form’ => ‘search_input’,
/*
‘wraptag’ => ‘p’,
*/
‘size’ => ‘15’,
‘label’ => ‘Search Archives’,
‘button’ => ‘’,
‘section’ => ‘’,
),$atts));
</code>
Offline
#30 2005-07-13 04:27:27
- Ray
- Member
- Registered: 2004-03-02
- Posts: 154
Re: search only one section?
Also… is it possible to include a search of multiple sections at once?… but not all sections. If so, how do I include those section in the txp tag
<code><txp:search_input section=“recentnews” /></code>
Offline
#31 2005-09-02 14:46:48
- june
- Member
- Registered: 2005-06-02
- Posts: 47
Re: search only one section?
What about using the “include in site search” option under the section tab in the admin interface? Wouldn’t that allow you to be selective about what sections you want to search and don’t want to search?
-june
Offline
#32 2005-09-02 20:00:17
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: search only one section?
june: the idea here is having searches separate from each other. Useful if your sections are different kinds of content.
Offline
Re: search only one section?
It’s late … but I bump this thread to note that <code><txp:search_input section=“my_section” /></code> work only in clean url : isn’t it? I can’t get it work with messy url, so if you have an experience …
(TXP 4.0.3)
françois
Offline
#34 2006-02-20 01:41:43
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: search only one section?
No, it works for messy urls too. Don’t forget to put if_search and a call to your search results form on that page.
Offline
#35 2006-03-21 21:35:57
- Andrew
- Plugin Author
- Registered: 2004-02-23
- Posts: 730
Re: search only one section?
Ok, I’ve read through this thread and have tried numerous things, but from what I can tell what I want to do (which is really quite simple) isn’t possible. Here’s what I want (using the whole “search” section w/ search_page template setup):
<pre><form action=”/search/” method=“get”>
<input name=“q” id=“query” type=“text” style=“width:250px;” value=“Search this site…” /><select name=“section”><option value=”“>All Sections</option><option value=“foo”>Foo</option><option value=“bar”>Bar</option><option value=“etc”>Etc…</option></select><input type=“submit” value=“GO” />
</form>
</pre>
<form action="/search/" method="get">
<input name="q" id="query" type="text" value="" />
<select name="section">
<option value="">All Sections</option>
<option value="foo">Foo</option>
<option value="bar">Bar</option>
<option value="etc">Etc...</option>
</select>
<input type="submit" value="Search" />
</form>
I’m using custom php to output the select menu. The filterSearch()
function in search.php (the only thing used in that entire file?) only is called if the “searchall” attribute has been set to “1” in your txp:article tag. So basically, if you haven’t specified searchall=‘0’ or if you’re not using an article tag in which to specify the attribute, then all searchable sections will always be searched. Since I am not using a txp tag I cannot set this attribute and even if I modify filterSearch()
to listen for $_['section']
, it will never get to this point because of searchall not being set.
If there were a way for me to output this form and specify a “searchonly” type of attribute, it’d be much easier (search only that which is selected, if searchable). But what I need is inverted from what is available. Perhaps I’m just not seeing it, but I’m totally disoriented when trying to figure out what the heck is going on with search_input, txp:article with relation to search, and anything that falls outside the scope of the basic functionality these offer.
I’m actually surprised no one has mentioned this before. Section-specific search is critical in large-scale sites; perhaps this is an indication of the scale of sites for which Textpattern is typically used. But regardless, I’d like to come up with a solution to this problem.
Last edited by Andrew (2006-03-21 21:38:19)
Offline
Re: search only one section?
You might want to look at the recent version of chh_article_custom. Takshaka has added boolean and weighted search function. But he probably help you out with your dilema here.
Refresh Dallas and other Refreshing Cities.
Offline