# Excluding pages from search results

**URL:** <https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806>\
**Category:** Radiant CMS\
**Created:** [November 10, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806 "2007-11-10T19:26:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 10, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806/1 "2007-11-10T19:26:05Z")

</div>

I’m using the search extension and the Radiant 0.6.3 gem. I see that  
I can set it to exclude pages like /sitemap/,/feed/ etc. and that  
works fine.

Now I decided to exclude a whole section of my site. I tried adding  
the top level page of the section I want to exclude like /section-  
name/,/sitemap/ etc but it appears this mechanism is only for  
individual pages. So, I tried this on my search results page:

```
 ...
   <r:unless_content part="no-search">
   <r:search:results>
     <ul>
       <r:search:results:each><li><r:link/></li></

```

r:search:results:each\>  
  
\</r:search:results\>  
\</r:unless\_content\>  
…

and then added a no-search page part to some pages and cleared the  
page cache, but those pages still appear in the results.

Is this problem a limitation in the current search extension or am I  
just missing something obvious?

thanks,  
john

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 10, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806/2 "2007-11-10T19:39:33Z")

</div>

john wrote:

> ```
> <r:unless_content part="no-search">
> 
> ```
> 
> page cache, but those pages still appear in the results.
> 
> Is this problem a limitation in the current search extension or am I  
> just missing something obvious?
> 
> thanks,  
> john

Hi John,

Haven’t used the search extension, so I may be completely off.

But, shouldn’t the unless\_content come _inside_ search:results:each ?  
That’s how I exclude pages from showing up in the menu (that’s just a  
r:children:each…)

\<r:children:each by=“published\_at” order=“desc” status=“published”\>  
\<r:unless\_content part=“no\_menu”\>

- \<r:link  
/\>
\</r:unless\_content\>  
\</r:children:each\>

Cheers,  
Mohit.  
11/11/2007 | 2:36 AM.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 10, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806/3 "2007-11-10T20:05:56Z")

</div>

On Nov 10, 2007, at 11:38 AM, Mohit S. wrote:

> shouldn’t the unless\_content come _inside_ search:results:each ?

That works perfectly. Thanks for the tip, I’m still on the upside of  
the radius learning curve.

thanks,  
john

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 10, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/excluding-pages-from-search-results/119806/4 "2007-11-10T20:23:30Z")

</div>

john wrote:

> On Nov 10, 2007, at 11:38 AM, Mohit S. wrote:
> 
> > shouldn’t the unless\_content come _inside_ search:results:each ?
> 
> That works perfectly. Thanks for the tip, I’m still on the upside of  
> the radius learning curve.
> 
> thanks,  
> john

Hi John

You’re most welcome!

That’s the thing with Radius tags. I guess it does help to get a bit  
acquainted with Radius (or learn as you go along - as I ended up doing  
it).

The simple rule that pulls me through - when you do something like an  
:each, it switches the context of the tag to the item being referred to.

Since you wanted to check if the result page had a no-search page part,  
you need to switch the context to that page. Hence, the need to do  
search:results:each first - roughly translates to:

for each item in the search pages  
unless it has a no-search part  
show a link to it  
end unless  
end for

I’m rambling cos it’s late - glad to have been of help.

Cheers,  
Mohit.  
11/11/2007 | 3:22 AM.
