Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#33 2006-02-15 16:45:23

fpradignac
Plugin Author
From: France near Cognac
Registered: 2005-01-29
Posts: 359
Website

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

#36 2006-03-21 21:57:57

tinyfly
Member
From: Dallas, Texas
Registered: 2004-05-10
Posts: 462
Website

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.

Offline

#37 2006-03-21 22:52:56

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: search only one section?

Thanks, tinyfly. Hm… doesn’t seem to have what I need. Each angle I look at it, search needs to be reworked a bit in publish.php & search.php, but I’m not quite fluent enough in the subtlties to know what not to touch.

Offline

#38 2006-03-23 00:17:18

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: search only one section?

So no one’s got any ideas?

Offline

#39 2006-08-21 21:37:04

leith1
New Member
Registered: 2006-08-21
Posts: 6

Re: search only one section?

Anyone who has solved this – please post. I am running several sites and want to use a single textpattern install. Divide the content between sites using sections:

section1 – site 1 content only
section2 – site 2 content only
section3 – content for both site1 and site2

Then have a search on site1 that returns results from sections 1 and 3. And have a search on site2 that returns results from sections 2 and 3.

Any suggestions anyone?

Offline

#40 2006-08-21 21:45:41

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: search only one section?

<del>section1 -> the search tag has attribute section=“section1”, the article tag has searchall=0
section2 -> the search tag has attribute section=“section2”, the article tag has searchall=0
section3 -> the search tag has attribute section=“section3”, the article tag has searchall=1
This assumes that you just have site 1 and site 2 and that section 3 is just for searching both sites.</del>

Sorry, I misunderstood. What you seem to be looking for is the option to set which sections to search in the article tag by using section=“section1,section2” there (or something close to that), but that isn’t supported by the TXP article tag as far as I can tell.
Have you looked at the chh_article_custom plugin mentioned above?

Last edited by ruud (2006-08-21 23:49:23)

Offline

#41 2006-08-21 22:40:06

leith1
New Member
Registered: 2006-08-21
Posts: 6

Re: search only one section?

Ruud,

Thanks but I’m not sure it will work.

Your assumption that Section 3 is only there to classify content to be included in both site’s searches is correct. But I want the site 1 search to search sections 1 and 3, and site 2 search to search sections 2 and 3. Only a single search box on each of site 1 and site 2.

From what you wrote it seems (am I incorrect?) that I would need 2 search boxes on each site (1 that searched it’s section and one that searched section3 content).

Offline

#42 2006-08-22 18:22:35

leith1
New Member
Registered: 2006-08-21
Posts: 6

Re: search only one section?

Thanks. That plugin might work if I used the hierarchical category search feature. I would rather stick to using sections and categories as I understand TXP defines them. I made the following 2-line modifications to the /textpattern/textpattern/publish.php code:

warning: Since I am new to TXP (1st implementation) I doubt this is highly recommended. Upgrading to a newer version of TXP will wipe our your modifications. Other unpredictable behaviour may arise which I’ve not found yet.

================================================
TXP Version: 4.03
================================================

CONTEXT: based on comments #39-41 in the discussion above. Assume you want to do what I wanted to do and have a search box that searches the current section (assumed to be section1 in the code below) as well as the always-searched section3 and section4. Note that making these modifications results in any/every search on your site always searching the section3 and section4 content regardless of what other settings you have in the admin panels.

================================================
MOD #1: this is the standard way of limiting a search to one section.
see: http://textpattern.org/tips/427/restricting-search-to-one-section
================================================

Modify your search_input tag on the page template where you want this section-specific search box to appear to include the section attribute which specifies the section that the search should be limited to:

<code><txp:search_input section=”<b>section1</b>” label=“Search” button=“Search” /></code>

Modify your article tag on the page template to specify the attribute <i>searchall</i> to limit the search to the current section plus the global ones (requires MOD #2 below to function properly):

<code>
<txp:article searchall=“0” />
</code>

================================================
MOD #2:
FILE: /textpattern/textpattern/publish.php (back it up 1st)
================================================

FIND: this line (~540): <code>$section = (!$section) ? ‘’ : “ and Section = ‘”.doslash($section).”’”;</code>

MODIFICATIONS:
Replace the line above with the following 3 lines:
<i>
// $section = (!$section) ? ‘’ : “ and Section = ‘”.doslash($section).’”;
$section_all_search = “ Section = ‘section3’ or Section = ‘section4’ “;
$section = (!$section) ? “ and ($section_all_search)” : “ and (Section = ‘“.doslash($section).”’ or $section_all_search) “;
</i>

Change the 2nd line above to reflect the sections that you want included in every search anywhere on your site. You would be replacing ‘section3’ and ‘section4’ in line 2 above with your section names that you wanted to be searched every time.

================================================

If there are problems with this code or someone has an improvement please post to let me know.

Last edited by leith1 (2006-08-22 20:42:25)

Offline

#43 2006-08-22 18:37:19

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: search only one section?

If you replace it with the following line, it would give you the option of using a comma separated list of sections in the section attribute of the txp:article tag (section=“section_1,section_2”) instead of hardcoding a specific section:
<code>$section = (!$section) ? ‘’ : “ and (Section = ‘” . join(“’ or Section = ‘”, array_map(‘doslash’, explode(‘,’, $section))) . “’)”;</code>

Offline

#44 2006-08-22 18:50:15

leith1
New Member
Registered: 2006-08-21
Posts: 6

Re: search only one section?

ruud, that’s a much better idea. The problem remains that this should probably be part of the original publish.php TXP release instead of requiring a mod. Not sure if suggestions here are considered for subsequent releases or not…

I tested it though and adding a ‘section’ attribute to the article tag isn’t picked up in publish.php. I like the idea of specifying the additional sections to be searched in the article tag so I added an attribute ‘searchmore’ to the article tag where I specified the additional categories that should be searched. I needed to modify the publish.php file to accomodate the additional attribute. I’ve redone the code mod description above to show all the steps with this new non-hard-coding approach.

================================================
TXP Version: 4.03
================================================

CONTEXT: based on comments #39-41 in the discussion above. Assume you want to do what I wanted to do and have a search box that searches the current section (assumed to be section1 in the code below) as well as the always-searched section3 and section4.

================================================
MOD #1: limit the search to the current category
see also: http://textpattern.org/tips/427/restricting-search-to-one-section
================================================

Modify your article tag on the page template to specify the attribute <i>searchall</i> to limit the search to the current section. Also add the <i>searchmore</i> attribute and comma-separate-list the additional sections you would like the search to look in.

<code>
<txp:article searchall=“0” searchmore=“section1,section3,section4” />
</code>

================================================
MOD #2:
FILE: /textpattern/textpattern/publish.php (back it up 1st)
================================================

FIND: this code (~500): <code>‘searchall’ => ‘’,</code>
ADD: this code to the next line: <code>‘searchmore’ => ‘’,</code>

This defines a new attribute to be used with the <code><txp:article /></code> tag.

FIND: this line (~540): <code>$section = (!$section) ? ‘’ : “ and Section = ‘”.doslash($section).”’”;</code>
ADD: the following lines after it

<code>
// if searching include any searchmore attribute sections in search
if (($searchmore != ‘’) && $q) { $section = ($section = = ‘’) ? “ and ( Section = ‘” . join(“’ or Section = ‘”, array_map(‘doslash’, explode(‘,’, $searchmore))) . “’)” : str_replace(‘and Section’, ‘ and (Section’, $section). “ or Section = ‘” . join(“’ or Section = ‘”, array_map(‘doslash’, explode(‘,’, $searchmore))) . “’)”;
}
</code>

<b>Note:</b> the second line shows a space between <i>==</i>. There should be no space there – the forum wouldn’t let me post the double equal sign without a space.

Now when a search is performed if the searchmore attribute is defined, all those sections specified in the searchmore attribute will be searched. Other undesirable implications may arise from this code – not entirely tested yet.

================================================

Last edited by leith1 (2006-08-22 20:53:27)

Offline

Board footer

Powered by FluxBB