Jump to content

How to search in CMS pages


Recommended Posts

Sorry for my late reply.

It's hard to guide you step by step from single forum post, so I'll give you general guidelines of what I'd do.

 

I'd create a module to hold the search box. This module would come with a (I'm just inventing names here) cmsSearchController.

The search button of this module would drive the user to that page. Here, the controller would submit the searched term to the new class CmsSearch.php, calling its method find().

 

You can copy part of the native search engine here, till the point where it looks int the search index.

 

Now comes the tricky part.

 

A search engine needs a search index table to look for keywords. It would take ages for a sql query to search in a big single field such as the cms content. Therefore, my suggestion is to create a new table 'cms_search_index' (id_cms, id_lang, keyword). Create a button in the module, which you can use to scan all your cms articles and add words over a certain number of characters you decide.)

 

Once they are added, in the search's find() method I previously mentioned, look for each of the keywords the user entered in the cms_search_index table, order by number of occurrences, then, depending on the type of search you want (match any keyword, or match all) intersect or merge the arrays generated by each keyword search.

 

With the retrieved cms ids, use a query to grab what you need to be displayed in the search list, and return them to the controller, which will display them using a template file.

 

 

THis is what I'd generally do :)

Link to comment
Share on other sites

  • 2 years later...
  • 4 weeks later...
×
×
  • Create New...