Howto : show joomla search results com_search

More
10 years 5 months ago - 10 years 5 months ago #1546 by bram
The component does not support the native search of joomla, so you either search in joomla using com_search and the ?searchword=<term> parameter or you search within a com_datafeed menu using ?q=<term>

If you have a content rich site ( and you all have since the google updates .... ) you might want to search both at once.

Fortunately accessing the joomla native search is quite easy. You can use the code below in either a component or module template.
Code:
<?php $q=JRequest::getVar('q'); if ( $q ) { JRequest::setVar('searchword',$q); JLoader::import('joomla.application.component.model'); JLoader::import( 'search', JPATH_SITE . DS . 'components' . DS . 'com_search' . DS . 'models' ); $search_model = JModel::getInstance( 'search', 'SearchModel' ); $res=$search_model->getData(); if (count($res) ) { print '<ul>'; foreach ( $res as $v ) { print '<li>'; print '<a href="'.JRoute::_($v->href).'">'.$v->title.'</a>'; print '</li>'; } print '</ul>'; } }

you want to show articles related to some other selection (menu) field.

Assume you have the type of clothing in your menu field 2.
Then replacing the first line with
Code:
$q=JRequest::getVar('q2');

will show articles related to the value of q2

Or related to a displayed item
Code:
$q=$item['Select2'];
but keep in mind that the joomla native search is rather expensive.

This information is about com_search, com_finder is next
Last edit: 10 years 5 months ago by bram.

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago - 10 years 5 months ago #1547 by bram
This seems to work with com_finder (smart search)

I have no clue (yet) how to work with this components settings and filters

Code:
<?php $q = JFactory::getApplication()->input->request->get('q'); if ( $q ) { JLoader::import('joomla.application.component.model'); JLoader::import( 'search', JPATH_SITE . DS . 'components' . DS . 'com_finder' . DS . 'models' ); $search_model = JModel::getInstance( 'search', 'FinderModel' ); $query=$search_model->getQuery(); $state=$search_model->getState(); $res=$search_model->getResults(); if (count($res) ) { print '<ul>'; foreach ( $res as $v ) { print '<li>'; print '<a href="'.JRoute::_($v->route).'">'.$v->title.'</a>'; print '</li>'; } print '</ul>'; } }

setting the 'q' manually :
Code:
JFactory::getApplication()->input->request->set('q','<term>');
Last edit: 10 years 5 months ago by bram.
The following user(s) said Thank You: mackelito

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #2836 by mackelito
When I make a search on something that doesn't exists I just get all of the items on that page instead...

Is there someway to just display a message like "No results" instead of just showing them "default" products?

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #2843 by bram
you can't directy

using the 'REQUERY' ( affiliatefeeds.nl/13-new-features-change...s-svn-1660.html#1787 ) you can set a message. you could even include javascript of css to hide the items.

The 'requery' status is not passed to the template, I will need to add that.

Then you can change you layout to catch the requery and modify you content

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago - 9 years 5 months ago #2861 by mackelito
Is it possible to not send the http response as 404?

edit:

Go to www.homeofsweden.se/q-asdasd
It works but I get a "Status Code:404 Not Found".. and that means that I cant get the error search message via my ajax script!.
Last edit: 9 years 5 months ago by mackelito.

Please Log in or Create an account to join the conversation.

More
9 years 5 months ago #2866 by bram
you really need the 404 on those pages otherwise you will clutter up google.

if you use the REQUERY with ajax you need to adust the ajax/send function with the error callback part.

( the ajax part is not on the site now right? Can't see what version you are using)

Please Log in or Create an account to join the conversation.

Time to create page: 0.228 seconds