×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: search with more than 1 criteria

search with more than 1 criteria 12 years 10 months ago #14866

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
Hi Daniel,

I am wondering if it's possible to hack the code to search for more than one word.

What I am looking to do is:
If I enter 2 or more words in the search tab ( for example: mexican restaurant downtown), I want the results containing only those 3 words.

Right now we can search for only 1 word. How can I make this possible?

search with more than 1 criteria 12 years 10 months ago #14868

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hm, Ok! Try this thing. Go to the hotpot model and in the search function you will see:
$searchWord = $db->Quote( '%'.$db->getEscaped( $searchWord, true ).'%', false );

change it to
$searchWord = $db->Quote( $db->getEscaped( $searchWord, true ), false );

Let me know if this does the trick.
Daniel

search with more than 1 criteria 12 years 10 months ago #14881

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
Hi Daniel,

No, it didn't the trick at all. With that code the search results are not showing even one word search.

search with more than 1 criteria 12 years 10 months ago #14897

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
any other suggestion?

Re: search with more than 1 criteria 12 years 10 months ago #14944

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Eliecer,
I think that maybe I've misunderstood something.

So if you have the following text in your description:

"Good restaurant in a nice area"

And you are searching for

"restaurant nice area" - should you find this entry? or not?

Right now you won't find the entry. If you search for "good restaurant" you are going to find the entry.

So which of the above 2 options do you want to have?

Cheers,
Daniel

Re: search with more than 1 criteria 12 years 10 months ago #14945

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
Hi Daniel,

In the Detailpage, i have included the menu from the restaurant, and some information from the restaurant like "located in downtown".

If I am searching for: 'restaurant lobster downtown', I wanna show the 'restaurants' located in 'downtown' that serves 'lobster'. Right now, If I am using a single word: 'lobster', I can find the restaurant, but if I search for: 'restaurant lobster downtown', I am getting 0 entries.

If I am searching for: 'restaurant lobster downtown', I want that my results contains the words: restaurant and lobster and downtown.

Re: search with more than 1 criteria 12 years 9 months ago #14953

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
any idea?

Re: search with more than 1 criteria 12 years 9 months ago #14954

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Yep! Go to models/hotspot.php and change the search function to this:
public function search($searchWord, $offset = null, $limit = null) {
		$db = JFactory::getDBO();
		$data = array();
 
 
        $words = explode(' ', $searchWord);
 
        $where = array();
        foreach($words as $value) {
            $searchWord = $db->Quote( '%'.$db->getEscaped( $value, true ).'%', false );
            $where[] = 'm.name LIKE ' . $searchWord;
            $where[] = 'm.description LIKE ' . $searchWord;
            $where[] = 'm.description_small LIKE '. $searchWord;
            $where[] = 'c.cat_name LIKE '. $searchWord;
        }
 
		$query = 'SELECT SQL_CALC_FOUND_ROWS m.id AS hotspots_id, m.*,c.* FROM ' . $db->nameQuote('#__hotspots_marker') . 'AS m'
				. ' LEFT JOIN ' . $db->nameQuote('#__hotspots_categorie') . 'AS c'
				. ' ON m.catid = c.id ' 
				. ' WHERE '
                . '(' . implode( ') OR (', $where) . ')'
				. ' AND (m.published = 1 AND c.published = 1 )'
				. ' ORDER BY m.name ASC';
 
 
		if($offset >= 0 && $limit > 0) {
			$db->setQuery($query, $offset, $limit);
		} else {
			$db->setQuery($query);
		}
		$data['hotspots'] = $db->loadObjectList();
 
		$db->setQuery('SELECT FOUND_ROWS()');
		$data['count'] = $db->loadResult();
		return $data;
	}

This should do the trick and now your query should return results.

And to be honest - since in few hours we will see joomla 2.5 - I want to integrate our search with finder... I'll need to research what needs to be done, but finder seems to be an awesome edition to the CMS...

Cheers,
Daniel

Re: search with more than 1 criteria 12 years 9 months ago #14957

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
Well, still not working.

Another example:
We have 4 movie theaters, if i search for 'movie westbank', only one theater must be showed on the map. Right now, the search results are showing the 4 theaters (places that contain the word movie), and the rest of the places containing the word 'westbank'.

As I explained before:

If I am searching for: 'restaurant lobster downtown',
I want that 'each of my results' contains the words: restaurant AND lobster AND downtown.

Re: search with more than 1 criteria 12 years 9 months ago #14958

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Ok, let us try this:
public function search($searchWord, $offset = null, $limit = null) {
		$db = JFactory::getDBO();
		$data = array();
 
 
        $words = explode(' ', $searchWord);
 
        foreach($words as $value) {
            $searchWord = $db->Quote( '%'.$db->getEscaped( $value, true ).'%', false );
            $where = 'm.name LIKE ' . $searchWord;
            $where .= ' OR m.description LIKE ' . $searchWord;
            $where .= ' OR m.description_small LIKE '. $searchWord;
            $where .= ' OR c.cat_name LIKE '. $searchWord;
            $wheres[] = $where;
        }
 
		$query = 'SELECT SQL_CALC_FOUND_ROWS m.id AS hotspots_id, m.*,c.* FROM ' . $db->nameQuote('#__hotspots_marker') . 'AS m'
				. ' LEFT JOIN ' . $db->nameQuote('#__hotspots_categorie') . 'AS c'
				. ' ON m.catid = c.id ' 
				. ' WHERE '
                . '(' . implode( ') AND (', $wheres) . ')'
				. ' AND (m.published = 1 AND c.published = 1 )'
				. ' ORDER BY m.name ASC';
 
 
		if($offset >= 0 && $limit > 0) {
			$db->setQuery($query, $offset, $limit);
		} else {
			$db->setQuery($query);
		}
		$data['hotspots'] = $db->loadObjectList();
 
		$db->setQuery('SELECT FOUND_ROWS()');
		$data['count'] = $db->loadResult();
		return $data;
	}
 

Let me know if it does the trick for you!
Daniel

Re: search with more than 1 criteria 12 years 9 months ago #14960

  • Eliecer Marchante
  • Eliecer Marchante's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 493
  • Karma: 11
  • Thank you received: 13
Yeah man! That did the trick. Thanks!!!
  • Page:
  • 1
Time to create page: 0.128 seconds