Originally, my client had only the Virtuemart Search Module installed on their site. Then they wanted to expand it to search for both content and products. So I disables the Virtuemart search module and replaced it with the Joomla core search.
I had to make some modifications to the core search so that it would search their products more efficiently. This was done by modifying plugins/search/vmxsearch.plugin.php. I wanted to only match whole words in product descriptions, instead of partial words. So I used some regular expressions...
"($field REGEXP '[ .:,]".$database->getEscaped($word)."[ .,:]'
OR $field = '".$database->getEscaped($word)."'
OR $field REGEXP '[ .:,]".$database->getEscaped($word)."$'
OR $field REGEXP '^".$database->getEscaped($word)."[ .:,]' )" ;
I also modified the virtuemart portion to handle numbers differently, to specifically find model numbers and part numbers more quickly. And I had already incorporated a special 'sort order' field to improve search relevancy, so I included that logic in returning search results.
Ok, then I presented the client with all my hard work. They liked it, but then made another request. Please add a 'products only' checkbox to the search page. When this box is checked, the search will revert back to the old search (meaning the virtuemart search). Hmmm...
I thought this was going to be difficult, and I tried a few things. But then a very simple solution worked. In the file components/com_search/views/search/tmpl/default_form.php I added an extra field:
<input type="checkbox" name="products_only" /> Search Only Products?Then I modified the form tag in the following way:
<?php /** Modified by This email address is being protected from spambots. You need JavaScript enabled to view it.* Dynamically swaps names for form name and search phrase input name,
* Depending on whether the 'products_only' checkbox is checked.
* If checked, we want the form to submit to Virtuemart Search instead of
* the core Joomla search
*/ ?>
<form id="searchForm" onSubmit="if(this.products_only.checked == true){
this.action = 'index.php?page=shop.browse&option=com_virtuemart&Itemid=15';
this.search_searchword.name = 'keyword'; }
return true;"
method="post" name="searchForm" action="<?php echo JRoute::_('index.php?option=com_search' );?>" >
Works like a charm!