将 Joomla 中的搜索限制增加到 20 多个字符

灰暗的星星灰暗的星星灰暗的星星灰暗的星星灰暗的星星
 

如果您尝试在 Joomla 中搜索很长的句子,那么很可能您得到的唯一结果如下:

搜索词必须最少 3 个字符,最多 20 个字符。

如果你真的希望人们在你的网站上搜索长句子,那么显然你想改变这个上限。 但是怎么做呢?

好吧,在我们告诉你怎么做之前,我们不得不说,我们第一次尝试增加最大搜索限制时,我们花了很长时间才知道如何 - 这就像一场野鹅追逐:一个文件将你引导到另一个文件到另一个文件! 但是,我们终于发现了:它实际上是一种语言设置! 我们不知道为什么 Joomla 没有在一个明显的地方有这个设置——比如在指向搜索组件的菜单项的设置中。

更复杂的是,不能在 Joomla 的后端更改该设置,而是在语言文件中更改(换句话说,您需要进行一些编码)。 因此,如果您想更改最大搜索限制(并假设您的网站上只有一种语言,即英语),那么您可以这样做:

  • 的文件 en-GB.localise.php 位于 /language/en-GB/
  • 在函数 getUpperLimitSearchWord 中,您将返回值从 20 更改为 40(例如)。 换句话说,您更改以下代码:

    return 20;

    return 40;

  • 您保存文​​件并上传它!

  • 而已!

现在,要提一件事,如果您有其他语言,那么您需要对每种语言执行上述相同的步骤(例如,如果您的网站有法语版本,那么您需要对文件进行上述修改 fr-FR.localise.php 位于 /language/fr-FR/ 目录下)。 如果您没有时间做这项繁琐的工作,那么您可以改为对 Joomla 核心文件进行以下更改,以确保所有语言都具有您选择的相同搜索限制:

  • 打开 language.php 位于 library/joomla/language 目录
  • 就在这一行之前(第 582 行):

    if ($this-&upperLimitSearchWordCallback !== null)

    添加以下代码:

    return 40;//其中 40 是您的新搜索限制

  • 保存文件并上传回来。

  • 而已!

请注意,Joomla 的搜索模块默认将其 20—— 这就是为什么您不能在该模块的搜索字段中输入超过 20 个字符的原因。 但是,好消息是 maxlength 值来自函数 getUpperLimitSearchWord ,这意味着执行上述操作将自动确保将 maxlength 更改为您选择的值(例如,如果您将值更改为 40,那么 maxlength 值将自动 40).

现在,如果上述方法对您不起作用,或者您没有编程经验,那么为什么不 联系我们 呢? 我们会以光速为你解决问题(嗯,慢一点,但你明白了), 我们不会向你收取太多费用 ,而且我们是地球上最友好的程序员——甚至可能是整个太阳系系统!

注意:如果您想增加/减少搜索下限,只需将 upper 替换 lower 上述指南中的 例如,您需要更改函数 getLowerLimitSearchWord 的返回值,而不是更改函数 getUpperLimitSearchWord 的返回值。

原文:

If you have tried to search for a very long sentence in Joomla, then most likely the only result that you got was the following:

Search term must be a minimum of 3 characters and a maximum of 20 characters.

If you really want people to search for long sentences on your website, then obviously you want to change that upper limit. But how to do that?

Well, before we tell you how, we have to say that the first time we tried to increase the maximum search limit it took us ages to find out how – it was like a wild goose chase: a file leading you to another file which leads to another file! But, we finally discovered it: it was actually a language setting! We have no idea why Joomla doesn’t have this setting in a place that is obvious – such as in the settings of the menu item pointing to the search component.

To make things even more complicated, that setting cannot be changed in Joomla’s backend, but rather in the language file (in other words, you’ll need to do some coding). So, if you want to change the maximum search limit (and assuming that you have only one language on your website, which is English), then here’s how you do this:

  • You open the file en-GB.localise.php located under the /language/en-GB/ folder.
  • In the function getUpperLimitSearchWord, you change the return value from 20 to 40 (for example). In other words, you change the following code:

    return 20;

    to

    return 40;

  • You save the file and you upload it!

  • That’s it!

Now, one thing to mention, if you have other languages then you need to do the same steps above for each one of them (for example, if your website has a French version, then you will need to do the above modifications to the file fr-FR.localise.php located under the /language/fr-FR/ directory). If you don’t have the time to do this tedious job, then you can instead do the following change to a Joomla core file to make sure that all languages have the same search limit of your choice:

  • Open the file language.php which is located under the libraries/joomla/language directory.
  • Just before this line (line 582):

    if ($this-&upperLimitSearchWordCallback !== null)

    add the following code:

    return 40; //where 40 is your new search limit

  • Save the file and upload it back.

  • That’s it!

Note that Joomla’s search module, by default, has its maxlength set to 20 – that’s why you’re not able to enter more than 20 characters in the search field of that module. However, the good news is that the maxlength value comes from the function getUpperLimitSearchWord, which means that doing the above will automatically ensure that maxlength is changed to your value of choice (for example, if you changed the value to 40 then the maxlength value will be automatically 40).

Now, if the above hasn’t worked for you or if you don’t have the programming experience to do it – then why not contact us? We’ll fix the issue for you in the speed of light (well, a bit slower, but you get the point), we won’t charge you much, and we are the friendliest programmers on planet Earth – maybe even the whole solar system!

Note: If you want to increase/decrease the lower search limit, then just replace the word upper with lower in the above guide and you’ll be all set. For example, instead of changing the return value of the function getUpperLimitSearchWord, you will need to change the return value of the function getLowerLimitSearchWord.

 

提交评论


安全码
刷新

 

自1996年以来,公司一直专注于域名注册、虚拟主机、服务器托管、网站建设、电子商务等互联网服务,不断践行"提供企业级解决方案,奉献个性化服务支持"的理念。作为戴尔"授权解决方案提供商",同时提供与公司服务相关联的硬件产品解决方案。
 

联系方式

地址:河南省郑州市经五路2号

电话:0371-63520088 

QQ:76257322

网站:800188.com

电邮:该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。

微信:用企业微信联系