Osclass forums
Support forums => General help => Topic started by: Syed on February 27, 2017, 08:39:23 am
-
Hi,
I want to improve search results so that when someone searches for "samsung galaxy edge" search result must show only those ads that contain all these keywords and sorted by time.
I have already gone through following topic and used 4th version, it shows related results but not ordered by time.
http://forums.osclass.org/3-5-x/search-problem-oc-3-5-3/
Please guide me to the right direction.
Regards,
-
Hi,
That would be possible (altough I wouldn't recommend it, people might include irrelevant keywords, like "looking for samsung galaxy edge", that couldn't give any results). Anyway, are you interested also in "search all languages" feature? ??? If you only have one language, the code would be a lot simpler...
Regards
-
thanks teseo for response,
Currently I have only one language but I have plan to add more, then I will be interested in "search all languages"
Regards,
-
Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.
<?php
function cust_pattern_search_all_keywords_only($params) {
if (@$params['sPattern'] != '') {
$mSearch = Search::newInstance();
$query_elements = (array) json_decode($mSearch->toJson());
$pattern = $query_elements['sPattern'];
foreach (explode(' ', $pattern) as $word) {
$query_elements['sPattern'] = str_replace($word, '+' . $word, $query_elements['sPattern']);
}
$mSearch->addLocale('%');
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
$mSearch->setJsonAlert($query_elements);
}
}
osc_add_hook('search_conditions', 'cust_pattern_search_all_keywords_only', 10);
function cust_alerts_user_dashboard() {
if (Params::getParam('page') == "user" && Params::getParam('action') == "alerts") {
$webUser = new CWebUser;
$aAlerts = Alerts::newInstance()->findByUser( Session::newInstance()->_get('userId'), false );
$user = User::newInstance()->findByPrimaryKey( Session::newInstance()->_get('userId'));
foreach($aAlerts as $k => $a) {
$array_conditions = (array)json_decode($a['s_search']);
$search = new Search();
$search->setJsonAlert($array_conditions);
if (osc_version() > 361) $search->notFromUser(Session::newInstance()->_get('userId'));
$search->addLocale('%');
$search->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
$search->limit(0, 3);
$aAlerts[$k]['items'] = $search->doSearch();
}
$webUser->_exportVariableToView('alerts', $aAlerts);
View::newInstance()->_reset('alerts');
$webUser->_exportVariableToView('user', $user);
}
}
osc_add_hook('before_html', 'cust_alerts_user_dashboard');
?>
Regards
-
Thank you very much teseo, it works fine.
1. Do it search all languages?
2. Do it work for search alerts subscribed by users?
3. Is it possible to add some more relevant search results at the end of these search results.
4. Is it good to use following wildcard code with it (currently searching for duck egg do not include results containing duck eggs)
<?php
function cust_search_keyword_wildcard($params) {
if ($params['sPattern']) {
$mSearch = Search::newInstance();
$query_elements = (array) json_decode($mSearch->toJson());
$query_elements['sPattern'] = str_replace(' ', '* ', $query_elements['sPattern']) . '*';
$mSearch->setJsonAlert($query_elements);
}
}
osc_add_hook('search_conditions', 'cust_search_keyword_wildcard', 10);
?>
Regards,
-
1 & 2: Yes
4.- In the function cust_pattern_search_all_keywords_only($params), replace this line:
$query_elements['sPattern'] = str_replace($word, '+' . $word, $query_elements['sPattern']);
with:
$query_elements['sPattern'] = str_replace($word, '+' . $word . '*', $query_elements['sPattern']);
3.- Many things are possible, but they would need much time to develop, I'm just trying here to provide generic procedures useful to many people.
You're welcome, please add [SOLVED] to the title of this thread.
Regards
-
Thank you teseo
You are very much helpful.
Regards,
-
Teseo!! i don`t know who are you or where are you from but i reallllyyyy love you man!!!
-
Hi,
I want to improve search results so that when someone searches for "samsung galaxy edge" search result must show only those ads that contain all these keywords and sorted by time.
I have already gone through following topic and used 4th version, it shows related results but not ordered by time.
https://time4buying.com/best-power-scrubbers
Please guide me to the right direction.
Regards,
That would be possible (altough I wouldn't recommend it, people might include irrelevant keywords, like "looking for samsung galaxy edge", that couldn't give any results). Anyway, are you interested also in "search all languages" feature? ??? If you only have one language, the code would be a lot simpler...