Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

opencart + sphinx


ufk
 Share

Recommended Posts

Собственно решил прикрутить к магазину sphinx на замену стандартного поиска.

С установкой и настройкой самого sphinx-са проблем ноль, но вот как вывести результаты в самом opencart-те к сожалению разбраться не получилось...все что нашел:

Next the Opencart product model code needs to be altered to use Sphinx rather than querying the MySQL database directly -- below is an example:-

$sphinx = new SphinxClient; // Instantiate PECL client

$sphinx->setServer('hostname',9999); // Hostname and port number that searchd is listening on

$mode = (strpos($keyword,'"') !== false ? SPH_MATCH_PHRASE : SPH_MATCH_ANY); // See if a phrase is being searched for

$sphinx->setMatchMode($mode);

$sphinx->setMaxQueryTime(100);

$sphinx->setLimits(0,2000,0,0);

// Get results from sphinx

$results = $sphinx->query($keyword,'getProductsByTitle');

$results['matches'] will contain an array of product ID values of all the matching products so when the Opencart query is issued the query's 'WHERE' clause should have added 'AND product.product_id IN (999,999,999) where 999 is the imploded list of IDs returned from Sphinx. There is also a command line tool (bin/search) supplied with Sphinx to test search queries.

отсюда - http://forum.opencart.com/viewtopic.php?t=18297

Собственно вопрос, может кто уже делал, подскажите где и что править в самом opencart-е(точнее даж так, куда воткнуть этот самый вызов sphinx-а дабы заменить оным встроенный поиск)?

Спасибо.

Link to comment
Share on other sites


Что именно тебя интересует?

Как выбрать товары по идентификаторам полученным из сфинкса или ты вообще не понимаеш что с этим кодом делать?

Link to comment
Share on other sites

Так..

Сейчас я постараюсь объяснить что я понимаю в этом коде:

это:

$sphinx = new SphinxClient; - понятно

$sphinx->setServer('hostname',9999); - соединяемся со сфинксом

$mode = (strpos($keyword,'"') !== false ? SPH_MATCH_PHRASE : SPH_MATCH_ANY); - поисковы запрос как понимаю

$sphinx->setMatchMode($mode); - понятно

$sphinx->setMaxQueryTime(100); - это понятно

$sphinx->setLimits(0,2000,0,0); - это тоже

$results = $sphinx->query($keyword,'getProductsByTitle'); - получаем результаты

тоесть я скорее вообще не понимаю что с этим кодом делать, точнее как "этим кодом" заменить поиск опенкарта.

Link to comment
Share on other sites


В Opencart тебя интересует вот этот код, в файле catalog/controller/product/search.php

// массив с параметрами поиска
$data = array(
	'filter_name' 		=> $filter_name, 
	'filter_tag'      	=> $filter_tag, 
	'filter_description'  => $filter_description,
	'filter_category_id'  => $filter_category_id, 
	'filter_sub_category' => $filter_sub_category, 
	'sort'            	=> $sort,
	'order'   			=> $order,
	'start'   			=> ($page - 1) * $limit,
	'limit'   			=> $limit
);
// подсчет общего количества товаров удовлетворяющих условиям поиска
$product_total = $this->model_catalog_product->getTotalProducts($data);
// получение полной информации о товарах удовлетворяющих условиям поиска
$results = $this->model_catalog_product->getProducts($data);
// дальше в цикле обрабатываются полученные товары
foreach ($results as $result) {
Вместо поиска с помощью Opencart ты ищеш с помощью сфинкса...

Сфинкс возвращает массив с идентификаторами товаров удовлетворяющих условиям поиска $results['matches']

Используя список идентификаторов товаров можно получить полную информацию о каждом товаре.

Вместо

foreach ($results as $result) {
пишеш

foreach ($results['matches'] as $product_id) {
	$result = $this->model_catalog_product->getProduct($product_id);
Не самый умный и быстрый вариант, но самый простой...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.