# Extending the Search Extension

**URL:** <https://www.ruby-forum.com/t/extending-the-search-extension/105416>\
**Category:** Radiant CMS\
**Created:** [May 29, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/extending-the-search-extension/105416 "2007-05-29T20:32:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Thompson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@James\_Thompson](https://www.ruby-forum.com/u/James_Thompson)\
**Post date:** [May 29, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/extending-the-search-extension/105416/1 "2007-05-29T20:32:23Z")

</div>

Ok, I can’t find the solution to this problem. I have implemented the  
suggestion from Oliver [[http://lists.radiantcms.org/pipermail/radiant/](http://lists.radiantcms.org/pipermail/radiant/)  
2007-May/004927.html] to control extension load order, but my  
customized render call isn’t overwriting the default SearchPage one.  
When I look at the debug log I only see the call for Page.find. I  
went into Console and confirmed that CatalogSearchExtension is being  
included via ‘SearchPage.include? CatalogSearchExtension’ so am I  
missing something?

=== /catalog\_extension.rb SNIPPET ===  
[… SNIP …]

def activate  
admin.tabs.add “Catalog”, “/admin/catalog”, :after =\>  
“Pages”, :visibility =\> [:all]

```
 CatalogPage

 require_dependency 'search_extension'

 SearchPage.send :include, CatalogSearchExtension

```

end

[… SNIP …]  
=== END ===

=== /lib/catalog\_search\_extension.rb SNIPPET ===  
module CatalogSearchExtension  
include Radiant::Taggable

attr\_accessor :product\_results

[… SNIP …]

# Customized render method that also searches products

def render  
@query\_result = []  
@product\_results = []  
@query = “”  
q = @request.parameters[:q]

```
 unless (@query = q.to_s.strip).blank?
   tokens = query.split.collect { |c| "%#{c.downcase}%"}

   pages = Page.find(:all, :include => [:parts],
       :conditions => [(["((LOWER(content) LIKE ?) OR (LOWER

```

(title) LIKE ?))“] \* tokens.size).join(” AND "),  
\*tokens.collect { |token| [token] \*  
2 }.flatten])

```
   products = CatalogProduct.find(:all,
                                  :conditions => [(["((LOWER

```

(description) LIKE ?) OR (LOWER(title) LIKE ?))“] \* tokens.size).join  
(” AND "),  
\*tokens.collect  
{ |token| [token] \* 2 }.flatten])

```
   @query_result = pages.delete_if { |p| !p.published? }
   @product_results = products
 end

 lazy_initialize_parser_and_context

 if layout
   parse_object(layout)
 else
   render_page_part(:body)
 end

```

end  
end  
=== END ===

James Thompson  
IT Director & Web Programmer  
Stewart & Associates, Inc.  
550 West Kentucky Street  
Louisville, KY 40203  
(502) 583.5502  
removed\_email\_address@domain.invalid  
[http://www.stewartaa.com/](http://www.stewartaa.com/)

---

<div class="post-metadata">

**Author:** ![James\_Thompson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@James\_Thompson](https://www.ruby-forum.com/u/James_Thompson)\
**Post date:** [May 30, 2007, 3:01am UTC](https://www.ruby-forum.com/t/extending-the-search-extension/105416/2 "2007-05-30T03:01:06Z")

</div>

> Ok, I can’t find the solution to this problem. I have  
> implemented the  
> suggestion from Oliver  
> [[http://lists.radiantcms.org/pipermail/radiant/](http://lists.radiantcms.org/pipermail/radiant/)  
> 2007-May/004927.html] to control extension load order, but my  
> customized render call isn’t overwriting the default SearchPage one.  
> When I look at the debug log I only see the call for Page.find. I  
> went into Console and confirmed that CatalogSearchExtension is being  
> included via ‘SearchPage.include? CatalogSearchExtension’ so am I  
> missing something?

You can’t override an existing method when you include a module. Methods  
in the concrete class override those in the included  
modules.

What you need is to run a class\_eval to include those methods instead of  
a module inclusion.

Dan.

---

<div class="post-metadata">

**Author:** ![James\_Thompson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@James\_Thompson](https://www.ruby-forum.com/u/James_Thompson)\
**Post date:** [May 30, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/extending-the-search-extension/105416/3 "2007-05-30T15:31:53Z")

</div>

Thanks for the assist!

For future reference here’s how I changed my code to make this work,  
maybe there is a still cleaner way:

=== /catalog\_extension.rb SNIPPET ===  
[… SNIP …]  
def activate  
admin.tabs.add “Catalog”, “/admin/catalog”, :after =\>  
“Pages”, :visibility =\> [:all]

```
 CatalogPage

 require_dependency 'search_extension'

 # SearchPage.send :include, CatalogSearchExtension
 CatalogSearchExtension.extend_search

```

end  
[… SNIP …]  
=== end ===

=== /lib/catalog\_search\_extension.rb SNIPPET ===  
module CatalogSearchExtension  
def self.extend\_search  
SearchPage.class\_eval do  
# Custom tags and other modifications  
[… SNIP …]

```
   # Customized render method that also searches products
   def render
     [... SNIP ...]
   end
 end

```

end  
end  
=== end ===

James Thompson  
IT Director & Web Programmer  
Stewart & Associates, Inc.  
550 West Kentucky Street  
Louisville, KY 40203  
(502) 583.5502  
removed\_email\_address@domain.invalid  
[http://www.stewartaa.com/](http://www.stewartaa.com/)
