简体   繁体   English

如何将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?

I want to change minimum character length for search from 4 to 1. 我想将搜索的最小字符长度从4更改为1。

I found this documentation https://doc.osclass.org/Fine-Tuning_MySQL_Full-Text_Search_-_Improving_search about osclass. 我在https://doc.osclass.org/Fine-Tuning_MySQL_Full-Text_Search_-__Improving_search中找到了有关osclass的文档。

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. 事实是,从我在主机上使用的数据库来看,只有一个数据库具有4个字符的限制,其余的都设置为0或未设置。

So I need to modify this ft_min_word_len=4 to `ft_min_word_len=1' ONLY in the osclass database. 所以我只需要在osclass数据库中将此ft_min_word_len=4修改为`ft_min_word_len = 1'。

Can someone help with a sollution? 有人可以提供解决方案吗? I have access to cpanel and phpMyAdmin 我可以访问cpanel和phpMyAdmin

It turns out that, from my scripts, only osclass uses this ft_min_word_len=4 variable from the server. 事实证明,从我的脚本来看,只有osclass使用服务器中的ft_min_word_len = 4变量。

So I can't change it because I have a shared server host, and the providers won't change it because of that. 所以我不能更改它,因为我有一个共享的服务器主机,并且提供程序也不会因此而更改它。

Turns out that there is another way to avoid changing this variable. 事实证明,还有另一种避免更改此变量的方法。

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/ ). 我在这里写下这个答案,因为如果没有在论坛上共享信息的其他人的帮助,我将无法自行解决( 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!!!-阅读此提示/ )。

So here goes 2 days work: 因此,这里需要2天的工作:

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. 此过滤器必须为少于4个字母的单词中的每个字母添加“ _”。 For example: e___ ex__ exa_ 例如:e___ ex__ exa_

For this to happen we need 2 functions: addunderline($t) and removeunderline($t) 为此,我们需要2个函数:addunderline($ t)和removeunderline($ t)

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. 想法是将所有少于4个字符的单词(从标题,描述和搜索模式)转换为使用下划线字符的最少4个字符的单词。

So, in the database there will be words like "e___" etc. Then, when the information is displayed we use removeunderline function. 因此,在数据库中将出现诸如“ e___”之类的词。然后,当显示信息时,我们使用removeunderline函数。

Please do a back-up for your files before starting!!! 开始之前,请备份您的文件!!!

Follow these steps 跟着这些步骤

For Osclass 3.7.1 and Bender theme: 对于Osclass 3.7.1和Bender主题:

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

Replace 更换

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

with

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

and

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

with

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_description()) )); ?>
  1. /oc-includes/osclass/gui/item-post.php /oc-includes/osclass/gui/item-post.php

Replace 更换

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

with

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

and

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

with

 <?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( removeunderline(bender_item_description()) )); ?>
  1. NO NEED TO MAKE THESE CHANGES IF YOU MAKE THE MODIFICATIONS FROM POINT 13! 如果您从要点13进行修改,则无需进行这些更改!

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

Replace 更换

 osc_item_title()

with

 removeunderline(osc_item_title())

and

 osc_item_description()

with

 removeunderline(osc_item_description())

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

Replace 更换

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

with

 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

After: 后:

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

Add this: 添加:

    /**
     * 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

Replace 更换

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

with

 <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

Replace 更换

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

with

 $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

Replace 更换

 $pattern    = osc_search_pattern();

with

 $pattern    = removeunderline(osc_search_pattern());

NO NEED TO MAKE THESE CHANGES[the ones below with osc_item_title()] IF YOU MAKE THE MODIFICATIONS FROM POINT 13! 如果您对要点13进行了修改,则无需进行这些更改[使用osc_item_title()在下面进行更改!

and all 和所有

 osc_item_title()

with

 removeunderline(osc_item_title())

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

Replace 更换

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

with

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

11.NO NEED TO MAKE THESE CHANGES IF YOU MAKE THE MODIFICATIONS FROM POINT 13! 11.如果您从要点13进行修改,则无需进行这些更改!

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

Replace all 全部替换

 osc_item_title()

with

 removeunderline(osc_item_title())

and

 osc_item_description()

with

 removeunderline(osc_item_description())

12.NO NEED TO MAKE THESE CHANGES IF YOU MAKE THE MODIFICATIONS FROM POINT 14! 12.如果您从第14点进行修改,则无需进行这些更改!

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

Replace 更换

 osc_premium_description()

with

 removeunderline(osc_premium_description())

and all 和所有

 osc_premium_title()

with

 removeunderline(osc_premium_title())

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

Replace 更换

 /**
 * 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;
 }

with

 /**
 * 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);
 }

and

 /**
 * 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;
 }

with

 /**
 * 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

Replace 更换

 /**
 * 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;
 }

with

 /**
 * 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);
 }

and

 /**
 * 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;
 }

with

 /**
 * 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);
 }

End. 结束。

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). 现在,您必须从网站上编辑并保存所有列表,或者等待所有列表由其自动编辑和保存(或在DB中重新生成全文搜索表-您可以在线找到有关该列表的详细信息)。

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). 这使得:-网址,item_titles和item_description在自动生成的电子邮件中带有下划线,-网址与seo友好url中的带有下划线-在osclass管理区域中item_title和item_description带有下划线(仅用于admin,不适用于已登录的用户)。 -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 < ; -bmw x5之类的单词在数据库中变为bmw_ x5,_,因此您需要进行修改以添加和删除下划线功能来解决标点问题,而无需在正则表达式中使用<>字符,因为osclass会将它们转换为< ; and > ; 和> ; and if the item gets edited and saved those characters are beeing multiplied with each edit-save action. 如果该项目被编辑并保存,则这些字符将与每个edit-save操作相乘。 I resolved this with an obs. 我用obs解决了这个问题。 for users not to use <> characters. 供用户不要使用<>字符。

EDIT. 编辑。

The item link can be resolved like this: 可以通过以下方式解决项目链接:

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

put

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

instead of 代替

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

For {ITEM_TITLE} and {ITEM_DESCRIPTION}: 对于{ITEM_TITLE}和{ITEM_DESCRIPTION}:

/oc-includes/osclass/emails.php /oc-includes/osclass/emails.php

Put removeunderline() at {ITEM_TITLE} and {ITEM_DESCRIPTION} values. 将removeunderline()放在{ITEM_TITLE}和{ITEM_DESCRIPTION}值处。

Example: 例:

 $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
    );

Do the same for all {ITEM_TITLE} in this file (10 replacements). 对此文件中的所有{ITEM_TITLE}执行相同操作(10个替换项)。

Do the same for all {ITEM_DESCRIPTION} in this file (3 replacements). 对此文件中的所有{ITEM_DESCRIPTION}执行相同操作(3个替换项)。

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

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