Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
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