14 Dec 2006, 12:36 PM
New Zenner
- Join Date:
- Dec 2006
- Posts:
- 3
- Plugin Contributions:
- 0
Search results ordered by products_name LIKE $keyword
Hi, I looked this up in the other threads and wasn't able to find it, so I did it myself. I'm developping a bookstore and the customer complained that when a user did a search, the books with whose titles matched the search keywords (and, therefeore, possibly the most relevant ones) did not always appear in the first places among the list of search results. I took a look at store > includes > modules > pages > advanced_search_result and fixed this problem by changing ```php
$order_str .= " order by p.products_sort_order, pd.products_name";
```php
$order_str .= " order by";
$claves = explode(' ', $keywords);
for($a = 0; $a < count($claves); $a++) {
$clave = $claves[$a];
$order_str .= " pd.products_name LIKE '%$clave%'";
if(($a + 1) < count($claves)) {
$order_str .= " OR";
}
}
$order_str .= " DESC";
```I'm not too good at php, so i'm sure this code can be improved. Anyway, now the books whose titles match some of the search keywords appear in the first places of the listing. By the way, you can take a look at the site at [www.catalogobuffet.com](http://www.catalogobuffet.com)