May 23, 2013, 02:05:49 PM

Login with username, password and session length

FORUM POSTING GUIDELINES - Please read and follow them.

Pages: [1]
  Print  
Author Topic: How to make a Simple Search Module that searches title, content & custom fields  (Read 1696 times)
Steven Koontz
Hero Member
*****
Online Online

Posts: 425



WWW
« on: May 17, 2012, 08:17:57 AM »

Some of us prefer the functionality of the Simple Search that is on the list pages over the keyword search from the Advanced Search Module. So here is how to make a module with the functionality of the Simple Search.

Navigate to one of your list pages and view the source code (Ctrl+U). Find the Simple Search code. Should look something like this:

Code:
<!--  BEGIN SEARCH CONTROLS  -->
 
   <div class="jr_listSearch">
   <form name="jr_simpleSearchForm" action="" method="post">
   <input size="20" type="text" name="data[keywords]" class="jrText" value="Search" onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search') this.value='';" />
                <button onclick="jQuery(this).parents('form:eq(0)').attr('action',s2AjaxUri).submit();" class="jrButton">Buscar</button>
   &nbsp;<a href="http://yourdomain.com/your-advanced-search-menu-url" >Advanced Search</a>                                <input type="hidden" name="data[simple_search]" value="1" />
   <input type="hidden" name="data[dir]" value="2" />
   <input type="hidden" name="data[controller]" value="search" />
   <input type="hidden" name="data[action]" value="_process" />
   <input type="hidden" name="data[menu_id]" value="232" />
   
<input type="hidden" name="data[cat]" value="" />

   </form>
   </div>
<!--  END SEARCH CONTROLS  -->

Copy and paste this code into a Custom HTML Module.

You might have to tweak the HTML a bit to get the layout how you want it, depending on your template and where you are inserting the module.

That's it!

Notes:

Most likely, all of the parameters below will already be set according to your search preferences you set in JReviews Configuration, 'Search' tab. But I include them here for clarification.

This code limits results to a specific directory:
Code:
<input type="hidden" name="data[dir]" value="2" />

This code limits results to the current category:
Code:
<input type="hidden" name="data[cat]" value="" />

Erase both of those lines to search across all listings, or change the values to limit results to the directory/category IDs you desire.



You might have to paste the URL of one of your Advanced Search Menus here:
Code:
<a href="http://yourdomain.com/your-advanced-search-menu-url" >Advanced Search</a>

Here you have to input the ID of the menu you want to use on the results page, or leave the value blank to use the current page menu ID:
Code:
<input type="hidden" name="data[menu_id]" value="232" />


You can change the code in /jreviews/controllers/categories_controller.php, function search if you want to show results that include one or more of multiple keyword searches, instead of only showing results containing the entire text string.

WARNING: these results are not ordered by relevance, so changing this code will likely result in very broad search results on most sites.

Change:      
Code:
$simplesearch_query_type = 'all'; // any|all

to:

Code:
$simplesearch_query_type = 'any'; // any|all
« Last Edit: May 17, 2012, 08:49:51 AM by Steven Koontz » Logged
lies
Full Member
***
Offline Offline

Posts: 69


« Reply #1 on: July 09, 2012, 09:41:03 PM »

When I type a keyword and get the results, and then try another search it does not work.  It stay on the last search and the URL stays the same until I click on a different menu item to get out of the search results page.  Do you get this as well?
Logged
Steven Koontz
Hero Member
*****
Online Online

Posts: 425



WWW
« Reply #2 on: July 10, 2012, 05:26:07 AM »

Quote
When I type a keyword and get the results, and then try another search it does not work.  It stay on the last search and the URL stays the same until I click on a different menu item to get out of the search results page.  Do you get this as well?

No, I do not get that behavior. Try setting Caching to 'No caching' in the module's Advanced options.
Logged
insanojaco
Sr. Member
****
Offline Offline

Posts: 203


« Reply #3 on: July 24, 2012, 02:15:16 PM »

Hi, thank you!

but it only works inside a jreview page, right?
it only reloads the page if the form is submited in another component page.

there is a way to make it work in any page?
Logged
Steven Koontz
Hero Member
*****
Online Online

Posts: 425



WWW
« Reply #4 on: July 24, 2012, 02:31:37 PM »

Quote
but it only works inside a jreview page, right?

I think it only works on non-Jreviews pages if you have another JReviews module on the page. Otherwise it will not load the necessary JavaScript. Try publishing a JReviews module along with the custom HTML module on your page and see if it works.

Sorry I can't test but I'm not using it anymore. I switched to the Joomla 2.5 Smart Search.
Logged
insanojaco
Sr. Member
****
Offline Offline

Posts: 203


« Reply #5 on: July 24, 2012, 02:37:46 PM »

Quote
but it only works inside a jreview page, right?

I think it only works on non-Jreviews pages if you have another JReviews module on the page. Otherwise it will not load the necessary JavaScript. Try publishing a JReviews module along with the custom HTML module on your page and see if it works.

Sorry I can't test but I'm not using it anymore. I switched to the Joomla 2.5 Smart Search.
It worked, thank you! Smiley

Can Smart Search search custom_fields of jreviews?

Why did you switched?
Logged
Steven Koontz
Hero Member
*****
Online Online

Posts: 425



WWW
« Reply #6 on: July 24, 2012, 04:13:21 PM »

Quote
Can Smart Search search custom_fields of jreviews?

No, it can't. It is also in "beta" mode with the improved version promised for Joomla 3.5. I think at that point I will make a formal feature request for the Smart Search functionality to be incorporated into JReviews.

Quote
Why did you switched?

I don't like the fact that JReviews keyword searches only return exact matches for text strings. For example, if you have 100 hotels in New York and someone uses your JReviews keyword search and enters "hotels in new york" they will get zero results. But since Joomla Smart Search orders results by keyword matches and relevance, it will display most of your hotel listings in New York as well as any other content you have concerning hotels in New York. Of course, it is pure Joomla. The results page does not list the listings on a JReviews page. Just regular Joomla search results with links to the articles/listings.

I use the Smart Search in my header and a JReviews Advanced Search module in the sidebar to allow people to do proper JReviews searches, but as far as keyword searches go, despite the drawbacks, I prefer Joomla Smart Search because the user is guaranteed relevant results.
Logged
insanojaco
Sr. Member
****
Offline Offline

Posts: 203


« Reply #7 on: July 24, 2012, 04:47:29 PM »

Quote
Can Smart Search search custom_fields of jreviews?

No, it can't. It is also in "beta" mode with the improved version promised for Joomla 3.5. I think at that point I will make a formal feature request for the Smart Search functionality to be incorporated into JReviews.

Quote
Why did you switched?

I don't like the fact that JReviews keyword searches only return exact matches for text strings. For example, if you have 100 hotels in New York and someone uses your JReviews keyword search and enters "hotels in new york" they will get zero results. But since Joomla Smart Search orders results by keyword matches and relevance, it will display most of your hotel listings in New York as well as any other content you have concerning hotels in New York. Of course, it is pure Joomla. The results page does not list the listings on a JReviews page. Just regular Joomla search results with links to the articles/listings.

I use the Smart Search in my header and a JReviews Advanced Search module in the sidebar to allow people to do proper JReviews searches, but as far as keyword searches go, despite the drawbacks, I prefer Joomla Smart Search because the user is guaranteed relevant results.
hhmmm I understand.

when I tried to index my content with Smart Search, it created a giant table in my DB, I have more than 30.000 listings.

I was affraid it could bring my site down, and I deleted the index.

Ill try it again very soon.
Logged
Steven Koontz
Hero Member
*****
Online Online

Posts: 425



WWW
« Reply #8 on: July 24, 2012, 05:52:16 PM »

Quote
when I tried to index my content with Smart Search, it created a giant table in my DB, I have more than 30.000 listings.

Yes, it creates quite a few tables. But to reduce load on the server, you have to index your content before it will work, so it is not scanning all the DB tables of Joomla articles. It only scans its own tables. The jury is out as to whether this will be a good long-term search solution or not, but for now it's working fine for me.
Logged
insanojaco
Sr. Member
****
Offline Offline

Posts: 203


« Reply #9 on: August 29, 2012, 06:23:28 PM »

Is possible to remove the button and paste the ajax code to the input?

I tried remove the code and the form doesnt work...

<button onclick="jQuery(this).parents('form:eq(0)').attr('action',s2AjaxUri).submit();" class="jrButton">Buscar</button>
Logged
Alejandro
Global Moderator
Administrator
Hero Member
*
Offline Offline

Posts: 28406


« Reply #10 on: August 29, 2012, 06:31:37 PM »

I don't understand your question. How do you want to submit the form?
Logged

http://www.reviewsforjoomla.com/testimonials Leave a testimonial for JReviews
insanojaco
Sr. Member
****
Offline Offline

Posts: 203


« Reply #11 on: August 29, 2012, 06:33:06 PM »

I don't understand your question. How do you want to submit the form?
I want to submit the form when user hit "enter", without the submit button.
is that possible?
Logged
Alejandro
Global Moderator
Administrator
Hero Member
*
Offline Offline

Posts: 28406


« Reply #12 on: August 29, 2012, 07:07:11 PM »

I don't know the code off the top of my head, but you can bind the same code to the enter key press:

Code:
jQuery(this).parents('form:eq(0)').attr('action',s2AjaxUri).submit();

Logged

http://www.reviewsforjoomla.com/testimonials Leave a testimonial for JReviews
andragor
Full Member
***
Offline Offline

Posts: 99


« Reply #13 on: April 01, 2013, 02:20:49 PM »

Thanks for this topic! Very useful!

I added a small modification in categories_controller to search only in titles and custom fields. Maybe it will be useful to someone.

Change:

$scope = array("Listing.title","Listing.introtext","Listing.fulltext","Listing.metakey");

To:

$scope = array("Listing.title");
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!