Important security update, please update to Osclass 3.7.4
At Osclass we have changed our Privacy Policy and Terms of Use in order to adapt them to the new General Data Protection Regulation (GDPR). We want you to know what user data we store, what we need them for, and who we share them with in each specific case. Furthermore, we are making it even easier for you to exercise your right to manage your own data.
Our goal is that you enjoy the best possible experience with our website. As the GDPR comes into force, legislation requires us that you grant us permission—both to us and our partners—to store cookies in your browser. Remember you can find more information about what we do with your data by clicking here.
I accept Osclass SL’s Terms of Use and Cookies Policy and grant them permission to manage my data.
This will slow down your db queries because it searches directly into your table. The osclass search is made not into the table that helds the items' title and description, but in the full index generated when the item was saved. You can read more about this online.
The wildcard is used on full index, it returns more results, so yes, but not so much as querying directly into the db tabes.
I'm on my phone now. Try to var_dump();die; on a test server the whole query to see it.
function cust_search_keyword_wildcard_with_customfield($params) { if ($params['sPattern']) { $mSearch = Search::newInstance(); $query_elements = (array) json_decode($mSearch->toJson()); $pattern = $query_elements['sPattern']; $query_elements['sPattern'] = str_replace(' ', '* ', $pattern) . '*'; $mSearch->setJsonAlert($query_elements); // Search by customfield too $mSearch->addJoinTable(count($query_elements['tables_join']), DB_TABLE_PREFIX."t_item_meta u", "pk_i_id = u.fk_i_item_id", 'LEFT'); $aPattern = explode(' ', $pattern); $customfieldCond = ''; foreach ($aPattern as $word) { if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word); } $mSearch->addConditions("1 = 1 " . $customfieldCond); $mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id'); }}osc_add_hook('search_conditions', 'cust_search_keyword_wildcard_with_customfield', 1); [/code]
Swich to bender(put that function into functions.php) and test. If it doesn't work it's not theme related.
I think this is the problem. foreach ($aPattern as $word) { if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word); }That || ( or ) makes results show even if they don't belong to a region.Is that the behaviour?
<?php$customfieldCond = '(';foreach ($aPattern as $word) { if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);}$customfieldCond .= ')';?>
Quote from: marius-ciclistu on June 18, 2018, 08:53:31 pmI think this is the problem. foreach ($aPattern as $word) { if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word); }That || ( or ) makes results show even if they don't belong to a region.Is that the behaviour?Hello,I suggest you put OR queries between braces. I've had a similar problem on one plugin I worked on, if I would do this like I did on the plugin it would look like this:Code: [Select]<?php$customfieldCond = '(';foreach ($aPattern as $word) { if ($word) $customfieldCond .= sprintf(" || u.s_value like '%%%s%%'", $word);}$customfieldCond .= ')';?>Regards.