Tags:
create new tag
view all tags

SID-01372: Keyword search among children of a particular topic

Status: Answered Answered TWiki version: 5.1.0 Perl version: 5.0
Category: CategorySearch Server OS: Debian 6.0 Last update: 14 years ago

How would I define a keyword search that only searches topics that are children of a given topic? As far as I can tell, there is not a parameter for standard keyword search that allows for this kind of specification.

I realize that I can use the topic="" and excludetopic="" parameters to specify the search space but I'm wondering if there's a more straightforward way to limit the keyword search just to a set of children with a common parent.

-- JordanEcker - 2012-01-09

Discussion and Answer

I'm trying to use a nested search to accomplish this. So far I've put together the following:

%SEARCH{"foobar" type="keyword" topic="$percntSEARCH{$quotparent.name='ParentTopic'$quot separator=$quot, $quot format=$quot$ltnop$gt$topic$quot type=$quotquery$quot}$percnt"}%

The goal is to have the inner search spit out a comma-separated, non-link (plain text) list of child topics of ParentTopic. Then the outer search looks for the search string "foobar" in this list of topics.

When I pull out the inner search and run it by itself to test it (with all $ escape variables replaced with their corresponding special characters), I get the list of ParentTopic's children as expected. However, the two searches nested together do not seem to produce the desired result. I'm not sure where I'm going wrong...

-- JordanEcker - 2012-01-09

I think I found the issue... Looks like the inner search was actually returning search header text and number of results along with the list of children. Turning nonoise="on" for the inner search gets rid of that extra stuff and seems to make the nesting work as expected.

Now, how would I further nest this structure inside an %IF{}% construct? How does escaping work for a clause that is doubly nested?

-- JordanEcker - 2012-01-09

Here is the code I'm working with if anyone can help:


<form><input type="text" name="search_string" size="60" />&nbsp;&nbsp;<input type="submit" value="Search" /></form>

%IF{"defined 'search_string'"
       then="%SEARCH{
                                   "%URLPARAM{search_string}%"
                                   type="keyword" 
                                   topic="%SEARCH{"parent.name='KnownIssues'" format="$topic" separator=", " nonoise="on" excludetopic="*Form, *Template, *Resolutions*" type="query"}%"
       }%"
       else="search_string not defined"
}%

The SEARCH inside the then-branch of the IF has another search nested in its topic parameter, and this nested structure works when I test it by itself (outside of the IF). When I put it in the IF, I get "<span class=" which seems to indicate that I haven't nested something correctly.

I'm confused about why the SEARCH within the SEARCH works without using any escaping, but I need to escape when dropping these in an IF? If this is the case, how do I escape correctly to make this structure work as intended?

-- JordanEcker - 2012-01-10

A "<span class=" indicates an early termination of a parameter. For example "%URLPARAM{search_string}%" embedded in another variable as a parameter could resolve in a string that has a double quote, which terminates the parameter early. A WikiWord for example resolves to a "<span class=" type link. You need to escape the URLPARAM string, see VarURLPARAM.

A variable within another variable gets evaluated first. So your inner SEARCH in topic="" gets evaluated before the SEARCH in then="". I believe the IF gets evaluated last. You can delay the then="" and else="" of IF by escaping % with $percnt. By delaying the SEARCHes you need to escape the " as well using \". So try:

then="$searchSEARCH{ \"$percntURLPARAM{search_string}$percnt\" ...

-- PeterThoeny - 2012-01-10

Thanks Peter for your help.

I made the changes you suggested to the then-branch value (escaping the outer search SEARCH and URLPARAM) and played around with escaping the inner SEARCH until I thought to try not escaping the inner search at all, which worked:

%IF{"defined 'search_string'"
    then="$percntSEARCH{
                  \"$percntURLPARAM{search_string}$percnt\"
                  type=\"keyword\" 
                  topic=\"%SEARCH{"parent.name='KnownIssues'" format="$topic" separator=", " nonoise="on" type="query"}%\"
         }$percnt"
    else="search_string not defined"
}%

I'm not sure I completely understand why this works. Why does the first double-quote after the inner SEARCH not terminate the then-branch parameter of the IF?

-- JordanEcker - 2012-01-10

Because of the inside-out evaluation order, all that IF sees is the result of the inner SEARCH.

-- PeterThoeny - 2012-01-11

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Keyword search among children of a particular topic
SupportCategory CategorySearch
TWiki version 5.1.0
Server OS Debian 6.0
Web server apache 2.2.21
Perl version 5.0
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2012-01-11 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.