How - t o create a Full Text Index on ERP5
author: Rafael Monnerat Al t e r Compatibility Table Go to /instance_name / p o r t a l _ c a t a l o g / e r p 5 _ m y s q l ( in ZMI) and acess and run ( test) the Z SQL Method 'z0_drop_compatibility'. This DROP the compatibility table on mysql. In same folder, modify the Z SQL Method 'z_create_compatibility'. Add the index and alter the Table Type. The new end of file will be:
KEY `review_state ` (`review_state ` ) , FULLTEXT(`SerachableText ` ) } TYPE=MyISAM
Run ( test) the ZSQLMethod to create the table.
Edit catalog properties Go to /instance_name / p o r t a l _ c a t a l o g / e r p 5 _ m y s q l ( in ZMI ) and edit the properties ( properties tab ). With CRTL press, mark these options:
s q l_ c a t a l o g _ o b j e c t _ l i s t s q l_ s e a r c h _ t a b l e s s q l_ c a t a l o g _ f u l l_ t e x t _ s e a r c h _ k e y s
z_c a t a l o g _ c o m p a t i b i l i t y _li s t co m p a t i b i li t y Se r a c h a b l e T e x t co m p a t i b i li t y .Se a r c h a b l e T e x t
Now the ERP5 use the compatibility table to catalog all objects too.
Add Full Text Search to Portal T h e normal portal Search Box don't do the full text Search. The portal needs a new Z SQL Method. This is just a simple and pratical example. Cr e a t e ZSQL Method In portal_catalog contents, create a Z SQL METHOD with name 'FTSearch' and argument 'SearchableText'. The code is:
SELECT catalog.path, catalog.uid, catalog.title, catalog.portal_type, catalog.description FROM compatibility , catalog WHERE compatibility.uid = catalog.uid AND MATCH (`SearchableText ` ) AGAINST (<dtml - s q l v a r expr="SearchableText" type="string">)
Doing search and show the results In folder portal_skin / c u s t o m add a ZPT with name 'ftsearch_results_tem p l a t e ' and the code: < h t m l metal:use - m a c r o = " c o n t e x t / m a i n _ t e m p l a t e / m a c r o s / m a s t e r " > <body > < m e t a l : s l o t metal:fill- sl o t = " h e a d e r " i18n:domain = " c m f _ d e f a u l t " > < h 1 i18n:translate = " " > S e a r c h Results < / h 1 > < / m e t a l: sl o t > < d i v class = " D e s k t o p " > < m e t a l : s l o t metal:fill- sl o t = " m a i n " i18n:domain = " c m f _ d e f a u l t " > < t a b l e class = " S e a r c h R e s u l t s " tal:define = " b a t c h python:here.portal_catalog.FTSearch(SearchableText = r e q u e s t . S e a r c h a b l e T e x t )" > <thead > <tr > <th i18n:translate = " " > T i t l e < / t h > <th i18n:translate = " " > T y p e < / t h > </tr> </thead > <tbo d y tal:repeat = " i t e m batch"> <tr > <td > <a href = " " tal:attributes = " h r e f python:item[0]"> <span tal:condition = " p y t h o n : i t e m [ 2 ] " tal:replace = " p y t h o n : i t e m [ 2 ]" > T i t l e < / s p a n > <span tal:condition = " n o t : p y t h o n : i t e m [ 2 ]" tal:omit - t a g = " " i18n:translate = " " > ( N o title)< / s p a n > </a> </td> <td tal:content = " p y t h o n : i t e m [ 3 ] " i18n:translate = " " > T y p e < / t d > </tr> <tr > <td > & n b s p ; < / t d > <td colspan = " 3 " > <em tal:condition = " p y t h o n : i t e m [ 4 ]" tal:content = " p y t h o n : i t e m [ 4 ] " > D e s c r i p t i o n < / e m > < e m tal:condition = " p y t h o n : n o t ( i t e m [ 4 ] )" i18n:translate = " " > ( N o description)< / e m > < / t d > </tr> </tbody> < / t a ble > < / m e t a l: sl o t > < / div > </body > </html >
Alter navagation_box T o finish alter the navegation_box in portal_skin / e r p 5 _ h t m l _ s t y l e . Put on line 177 the new method:
title="Search" alt="Search" name=" tsearch_results_template:method f "
O n l y the button do the search, if you press enter you don't do the execute these metho d . About the Mysql FULLTEXT index you cam find more information on reference guide on mysql site. I'm use the default config, but you can modify to improve y o u r search.
AB OU T Au t h o r : Rafael Monnerat M ai l : rmonnerat@gmail.com We b S i t e : http: / / m o n n e r a t . o b j e c t i s . n e t ( In portuguese) Do c u m e n t source ( .odt ) on my website ( erp5 section ). Mail me for any question or use the lists!