如何将 ft_min_word_len=4 修改为 ft_min_word_len=1 以便 osclass 3.7.1 可以搜索最小 1 个字符的单词,而不是 4 个? [英] 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?

查看:90
本文介绍了如何将 ft_min_word_len=4 修改为 ft_min_word_len=1 以便 osclass 3.7.1 可以搜索最小 1 个字符的单词,而不是 4 个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将搜索的最小字符长度从 4 更改为 1.

I want to change minimum character length for search from 4 to 1.

我找到了这个文档 https://doc.osclass.org/Fine-Tuning_MySQL_Full-Text_Search_-_Improving_search 关于 osclass.

I found this documentation https://doc.osclass.org/Fine-Tuning_MySQL_Full-Text_Search_-_Improving_search about osclass.

问题是,从我在主机上使用的数据库中,只有这个有 4 个字符的限制,其余的有 0 或未设置.

The thing is that, from the databases I use on my host, only this one has this 4 character limit, the rest of them have 0 or not set.

所以我只需要在 osclass 数据库中将这个 ft_min_word_len=4 修改为 `ft_min_word_len=1'.

So I need to modify this ft_min_word_len=4 to `ft_min_word_len=1' ONLY in the osclass database.

有人可以帮忙解决吗?我可以访问 cpanel 和 phpMyAdmin

Can someone help with a sollution? I have access to cpanel and phpMyAdmin

推荐答案

原来还有另一种方法可以避免更改此变量.

Turns out that there is another way to avoid changing this variable.

我在这里写这个答案是因为如果没有在论坛上共享信息的其他人的帮助,我自己无法弄清楚(https://forums.osclass.org/development/i-am-not-able-to-apply-a-regex-item-title/https://forums.osclass.org/general-help/brilliant-3-letter-word-search-is-possible!!!-read-this-提示/).

I write this answer here because I wouldn't have been able to figure it out by my own without the help of others that shared information on forums ( https://forums.osclass.org/development/i-am-not-able-to-apply-a-regex-item-title/ or https://forums.osclass.org/general-help/brilliant-3-letter-word-search-is-possible!!!-read-this-tip/).

所以这里有 2 天的工作:

So here goes 2 days work:

ideea是先过滤item的title和description再加入数据库.此过滤器必须为少于 4 个字母的单词中缺少的每个字母添加_".例如:e___前任__例如_

The ideea is to filter the title and description of items before adding it to the database. This filter must add '_' for every letter missing from a less than 4 letter word. For example: e___ ex__ exa_

要做到这一点,我们需要 2 个函数:addunderline($t) 和 removeunderline($t)

For this to happen we need 2 functions: addunderline($t) and removeunderline($t)

想法是将标题、描述和搜索模式中少于4个字符的单词全部转换为使用下划线字符的最少4个字符的单词.

The ideea is to turn all the words with less than 4 characters from title, description and search pattern, to min 4 character words using underscore characters.

所以,在数据库中会有e___"之类的词.然后,当显示信息时,我们使用 removeunderline 函数.

So, in the database there will be words like "e___" etc. Then, when the information is displayed we use removeunderline function.

请在开始前备份您的文件!!!

Please do a back-up for your files before starting!!!

按照以下步骤操作

对于 Osclass 3.7.1 和 Bender 主题:

For Osclass 3.7.1 and Bender theme:

在复制粘贴之前停止并分析代码.我是一个人,可能会发生错误,因为我在多次修改后做了以下说明......

Stop and analize the code before copy-pasting it. I'm a human and error can happen, as I made the below instructions after many modifications....

1./oc-content/themes/bender/item-post.php

1. /oc-content/themes/bender/item-post.php

替换

 <?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( bender_item_title() )); ?>

 <?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_title()) )); ?>

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( bender_item_description() )); ?>

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_description()) )); ?>

  1. /oc-includes/osclass/gui/item-post.php

替换

 <?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( bender_item_title() )); ?>

 <?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_title()) )); ?>

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( bender_item_description() )); ?>

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_description()) )); ?>

  1. 如果您根据第 13 点进行修改,则无需进行这些更改!

/oc-content/themes/bender/item.php

/oc-content/themes/bender/item.php

替换

 osc_item_title()

 removeunderline(osc_item_title())

 osc_item_description()

 removeunderline(osc_item_description())

4./oc-content/themes/bender/search.php

4. /oc-content/themes/bender/search.php

替换

 if(osc_count_items() == 0) {?>
 <p class="empty" ><?php printf(__('There are no results matching "%s"', 'bender'), osc_search_pattern()) ; ?></p>

 if(osc_count_items() == 0) {?>
 <p class="empty" ><?php printf(__('There are no results matching "%s"', 'bender'), removeunderline(osc_search_pattern())); ?></p>

5./oc-includes/osclass/helpers/hSearch.php

5. /oc-includes/osclass/helpers/hSearch.php

之后:

 /**
  * Gets current search pattern
  *
  * @return string
  */
 function osc_search_pattern() {
     if(View::newInstance()->_exists('search_pattern')) {
         return View::newInstance()->_get('search_pattern');
     } else {
         return '';
     }
 }

添加:

    /**
     * transforms all words with under 4 characters to 4 characters ones
     *
     * @return string
     */

 function addunderline($t)
 {
 if(count($t))
 {
  $words = explode(" ", $t);
  for ($i=0; $i<count($words); $i++)
  { $ln=strlen($words[$i]);
  if($ln==1)  $words[$i]=$words[$i].='___';
  if($ln==2)  $words[$i]=$words[$i].='__';
  if($ln==3)  $words[$i]=$words[$i].='_';
  }
  return implode(" ", $words);
 }
 else { return $t;
      }
 }

    /**
     * Removes '_' from the end of the 4 characters words
     *
     * @return string
     */
 function removeunderline($t)
 {
 if(count($t))
 {
  $words = explode(" ", $t);
  for ($i=0; $i<count($words); $i++)
  { 
    if(strlen($words[$i])==4)  $words[$i]=chop($words[$i],"_");

  }
  return implode(" ", $words);
 }
 else { return $t;
      }
 }

6./oc-content/themes/bender/search-sidebar.php

6. /oc-content/themes/bender/search-sidebar.php

替换

 <input class="input-text" type="text" name="sPattern"  id="query" value="<?php echo osc_esc_html(osc_search_pattern()); ?>" />

 <input class="input-text" type="text" name="sPattern"  id="query" value="<?php echo removeunderline(osc_esc_html(osc_search_pattern())); ?>" />

7./oc-includes/osclass/controller/search.php

7. /oc-includes/osclass/controller/search.php

替换

 $p_sPattern   = trim(strip_tags(Params::getParam('sPattern')));

 $p_sPattern   = addunderline(trim(strip_tags(Params::getParam('sPattern'))));

8./oc-content/themes/bender/functions.php

8. /oc-content/themes/bender/functions.php

添加到文件末尾(文件末尾不要留空行)

Add to the end of the file (do not leave empty lines at the end of file)

 <?php
 function cust_filter_title_description($aItem) {

    foreach(@$aItem['title'] as $key => $value) {
        $aItem['title'][$key] = addunderline($value);
    }

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

    return $aItem;
 }

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

9./oc-includes/osclass/classes/Breadcrumb.php

9. /oc-includes/osclass/classes/Breadcrumb.php

替换

 $pattern    = osc_search_pattern();

 $pattern    = removeunderline(osc_search_pattern());

如果您根据第 13 点进行修改,则无需进行这些更改[以下使用 osc_item_title()] 进行修改!

NO NEED TO MAKE THESE CHANGES[the ones below with osc_item_title()] IF YOU MAKE THE MODIFICATIONS FROM POINT 13!

和所有

 osc_item_title()

 removeunderline(osc_item_title())

10./oc-content/themes/bender/common/head.php

10. /oc-content/themes/bender/common/head.php

替换

 <title><?php echo meta_title() ; ?></title>

 <title><?php echo removeunderline(meta_title()) ; ?></title>

11.如果您根据第 13 点进行修改,则无需进行这些更改!

11.NO NEED TO MAKE THESE CHANGES IF YOU MAKE THE MODIFICATIONS FROM POINT 13!

/oc-content/themes/bender/loop-single.php

/oc-content/themes/bender/loop-single.php

全部替换

 osc_item_title()

 removeunderline(osc_item_title())

 osc_item_description()

 removeunderline(osc_item_description())

12.如果您根据第 14 点进行修改,则无需进行这些更改!

12.NO NEED TO MAKE THESE CHANGES IF YOU MAKE THE MODIFICATIONS FROM POINT 14!

/oc-content/themes/bender/loop-single-premium.php

/oc-content/themes/bender/loop-single-premium.php

替换

 osc_premium_description()

 removeunderline(osc_premium_description())

和所有

 osc_premium_title()

 removeunderline(osc_premium_title())

13./oc-includes/osclass/helpers/hItems.php

13. /oc-includes/osclass/helpers/hItems.php

替换

 /**
 * Gets title from current item, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string
 */
 function osc_item_title($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $title = osc_item_field("s_title", $locale);
    if($title=='') {
        $title = osc_item_field("s_title", osc_language());
        if($title=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $title = osc_item_field("s_title", @$locale['pk_c_code']);
                if($title!='') {
                    break;
                }
            }
        }
    }
    return (string) $title;
 }

 /**
 * Gets title from current item, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string
 */
 function osc_item_title($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $title = osc_item_field("s_title", $locale);
    if($title=='') {
        $title = osc_item_field("s_title", osc_language());
        if($title=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $title = osc_item_field("s_title", @$locale['pk_c_code']);
                if($title!='') {
                    break;
                }
            }
        }
    }
    return (string) removeunderline($title);
 }

 /**
 * Gets description from current item, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string $desc
 */
 function osc_item_description($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $desc = osc_item_field("s_description", $locale);
    if($desc=='') {
        $desc = osc_item_field("s_description", osc_language());
        if($desc=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $desc = osc_item_field("s_description", @$locale['pk_c_code']);
                if($desc!='') {
                    break;
                }
            }
        }
    }
    return (string) $desc;
 }

 /**
 * Gets description from current item, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string $desc
 */
 function osc_item_description($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $desc = osc_item_field("s_description", $locale);
    if($desc=='') {
        $desc = osc_item_field("s_description", osc_language());
        if($desc=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $desc = osc_item_field("s_description", @$locale['pk_c_code']);
                if($desc!='') {
                    break;
                }
            }
        }
    }
    return (string) removeunderline($desc);
 }

14./oc-includes/osclass/helpers/hPremium.php

14. /oc-includes/osclass/helpers/hPremium.php

替换

 /**
 * Gets title from current premium, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string
 */
 function osc_premium_title($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $title = osc_premium_field("s_title", $locale);
    if($title=='') {
        $title = osc_premium_field("s_title", osc_language());
        if($title=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $title = osc_premium_field("s_title", $locale);
                if($title!='') {
                    break;
                }
            }
        }
    }
    return (string) $title;
 }

 /**
 * Gets title from current premium, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string
 */
 function osc_premium_title($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $title = osc_premium_field("s_title", $locale);
    if($title=='') {
        $title = osc_premium_field("s_title", osc_language());
        if($title=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $title = osc_premium_field("s_title", $locale);
                if($title!='') {
                    break;
                }
            }
        }
    }
    return (string) removeunderline($title);
 }

 /**
 * Gets description from current premium, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string $desc
 */
 function osc_premium_description($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $desc = osc_premium_field("s_description", $locale);
    if($desc=='') {
        $desc = osc_premium_field("s_description", osc_language());
        if($desc=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $desc = osc_premium_field("s_description", $locale);
                if($desc!='') {
                    break;
                }
            }
        }
    }
    return (string) $desc;
 }

 /**
 * Gets description from current premium, if $locale is unspecified $locale is current user locale
 *
 * @param string $locale
 * @return string $desc
 */
 function osc_premium_description($locale = "") {
    if ($locale == "") $locale = osc_current_user_locale();
    $desc = osc_premium_field("s_description", $locale);
    if($desc=='') {
        $desc = osc_premium_field("s_description", osc_language());
        if($desc=='') {
            $aLocales = osc_get_locales();
            foreach($aLocales as $locale) {
                $desc = osc_premium_field("s_description", $locale);
                if($desc!='') {
                    break;
                }
            }
        }
    }
    return (string) removeunderline($desc);
 }

结束.

现在您必须编辑并保存您网站上的所有列表,或者等待所有列表由他们的作者编辑和保存.(或在数据库中重新生成全文搜索表 - 您可以在线找到相关详细信息).

Now you must edit and save al the listings from your website or wait for all the listings to be edited and saved by their autors.(or regenerate the fulltext search tables in DB - you can find details about that online).

观察.这使得:- urls, item_titles 和 item_description 在自动生成的电子邮件中保留下划线,- 网址在 seo 友好网址中保留下划线- item_title 和 item_description 在 osclass 管理区域中保留下划线(仅适用于管理员,不适用于登录用户).-像bmw x5这样的词,在数据库中变成bmw_ x5,_,所以需要修改添加和删除下划线函数来解决标点问题,正则表达式中不用<>字符,因为osclass将它们转化为<;和 >;如果项目被编辑和保存,这些字符会随着每个编辑保存操作而增加.我用 obs 解决了这个问题.让用户不要使用 <> 字符.

Obs. This makes: - urls, item_titles and item_description remain with underscores in automatic generated emails , - urls remain with underscores in seo friendly urls - item_title and item_description remain with underscores in osclass admin area(only for admin, not for signed in users). -words like bmw x5, become bmw_ x5,_ in the database, so you need to make modifications to add and remove underline functions to solve punctuation problem, without using <> characters in regex, because osclass transforms them into <; and >; and if the item gets edited and saved those characters are beeing multiplied with each edit-save action. I resolved this with an obs. for users not to use <> characters.

编辑.

物品链接可以这样解析:

The item link can be resolved like this:

/oc-includes/osclass/helpers/hDefines.php

/oc-includes/osclass/helpers/hDefines.php

 $url = str_replace('{ITEM_TITLE}', osc_sanitizeString(removeunderline($item['s_title'])), $url);

代替

 $url = str_replace('{ITEM_TITLE}', osc_sanitizeString($item['s_title']), $url);

对于{ITEM_TITLE}和{ITEM_DESCRIPTION}:

For {ITEM_TITLE} and {ITEM_DESCRIPTION}:

/oc-includes/osclass/emails.php

/oc-includes/osclass/emails.php

将 removeunderline() 放在 {ITEM_TITLE} 和 {ITEM_DESCRIPTION} 值处.

Put removeunderline() at {ITEM_TITLE} and {ITEM_DESCRIPTION} values.

示例:

 $words   = array();
    $words[] = array(
        '{ITEM_DESCRIPTION_ALL_LANGUAGES}',
        '{ITEM_DESCRIPTION}',
        '{ITEM_COUNTRY}',
        '{ITEM_PRICE}',
        '{ITEM_REGION}',
        '{ITEM_CITY}',
        '{ITEM_ID}',
        '{USER_NAME}',
        '{USER_EMAIL}',
        '{ITEM_TITLE}',
        '{ITEM_URL}',
        '{ITEM_LINK}',
        '{VALIDATION_LINK}',
        '{VALIDATION_URL}',
        '{EDIT_LINK}',
        '{EDIT_URL}',
        '{DELETE_LINK}',
        '{DELETE_URL}'
    );
    $words[] = array(
        $all,
        removeunderline($item['s_description']), // here
        $item['s_country'],
        osc_format_price($item['i_price']),
        $item['s_region'],
        $item['s_city'],
        $item['pk_i_id'],
        $item['s_contact_name'],
        $item['s_contact_email'],
        removeunderline($item['s_title']), // here
        $item_url,
        $item_link,
        '<a href="' . $validation_url . '" >' . $validation_url . '</a>',
        $validation_url,
        '<a href="' . $edit_url . '">' . $edit_url . '</a>',
        $edit_url,
        '<a href="' . $delete_url . '">' . $delete_url . '</a>',
        $delete_url
    );

对这个文件中的所有 {ITEM_TITLE} 执行相同的操作(10 个替换).

Do the same for all {ITEM_TITLE} in this file (10 replacements).

对此文件中的所有 {ITEM_DESCRIPTION} 执行相同操作(3 个替换).

Do the same for all {ITEM_DESCRIPTION} in this file (3 replacements).

这篇关于如何将 ft_min_word_len=4 修改为 ft_min_word_len=1 以便 osclass 3.7.1 可以搜索最小 1 个字符的单词,而不是 4 个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆