简体   繁体   English

如果用户在osclass的搜索栏中键入类别名称,则搜索将不显示任何内容

[英]Search shows nothing if user types category name in search bar in osclass

I hope this will help others too. 我希望这也会对其他人有所帮助。 The search bar shows nothing if a user types category/sub-category name in the search bar. 如果用户在搜索栏中键入类别/子类别名称,则搜索栏中将不显示任何内容。 I know there is a separate field for selecting category/sub-category along with the search bar but in my case i have only a single search bar and when i search by typing the category/sub-category name the search shows me 0 results found even though i have items in the category/sub-category. 我知道有一个单独的字段可以与搜索栏一起选择类别/子类别,但是在我的情况下,我只有一个搜索栏,当我通过键入类别/子类别名称进行搜索时,搜索显示给我0条结果即使我在类别/子类别中也有项目。 Is there anyone could assist me the solution please 有没有人可以帮助我解决方案

The search in osclass is made by title and description only. osclass中的搜索仅按标题和描述进行。 If you insert the category name into the description then it will work as you want. 如果将类别名称插入描述中,则它将按需要工作。

In your theme's functions.php file, add to the end 在主题的functions.php文件中,添加到最后

<?php
function endsWith($haystack, $needle)
{
$length = strlen($needle);

return $length === 0 || 
(substr($haystack, -$length) === $needle);
}
function mc_addcategory($desc, $catId) {
$Cat = Category::newInstance()->toRootTree($catId);
$d = '\n\n  ';
foreach($Cat as $c) {
$d = $d . $c["s_name"] .' / ';
}
if(endsWith($desc, $d))
return $desc;
else return $desc . $d;
}
function mc_filter_description($aItem) {

    foreach(@$aItem['description'] as $key => $value) {
        $aItem['description'][$key] = mc_addcategory($value,$aItem['catId']);
    }

    return $aItem;
}

osc_add_filter('item_add_prepare_data', 'mc_filter_description');
osc_add_filter('item_edit_prepare_data', 'mc_filter_description');
?>

Step 2 第2步

You would want to remove the added text from description when displaying the description to the public and to the owner when it edits hi's item. 在向公众显示说明时,以及在编辑hi的项目时向所有者显示说明时,您希望从说明中删除添加的文本。 You can do that with a function Put this before the above code in functions.php 您可以使用一个函数来做到这一点,将其放在functions.php中上面的代码之前

<?php
    function mc_hide_categ_in_description($desc, $catId) {

    $Cat = Category::newInstance()->toRootTree($catId);
    $d = '\n\n  ';
    foreach($Cat as $c) {
    $d = $d . $c["s_name"] .' / ';
    }
    if(endsWith($desc, $d))
    return str_replace($d,'',$desc);
    else return $desc;
    }
?>

and call this function where the description is shown. 并在显示说明的地方调用此函数。 Have a look here 在这里看看

How to modify ft_min_word_len=4 to ft_min_word_len=1 so that osclass 3.7.1 can search min 1 character word, instead of 4? 如何将ft_min_word_len = 4修改为ft_min_word_len = 1,以便osclass 3.7.1可以搜索最少1个字符的单词,而不是4个字符?

And see where I call 'removeunderline(' for description. 并查看我称之为“ removeunderline(”)的说明。

OBS OBS

After this you must update the descriptions in your db by editing and saving each item. 之后,您必须通过编辑和保存每个项目来更新数据库中的描述。 This will work if the item is edited and it's category is changed by user. 如果用户编辑了该项目并且其类别已更改,则此方法将起作用。

If the admin makes the editing and the above function can't be called from oc-admin/themes/modern... files, the last function from above must be placed in /oc-includes/osclass/helpers/hSearch.php and removed from functions.php file. 如果管理员进行编辑,并且无法从oc-admin / themes / modern ...文件中调用上述功能,则必须将上述最后一个功能放在/oc-includes/osclass/helpers/hSearch.php中,从functions.php文件中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM