使用InputBox向MediaWiki搜索查询添加额外的搜索文本 [英] Adding extra search text to a MediaWiki search query using InputBox

查看:349
本文介绍了使用InputBox向MediaWiki搜索查询添加额外的搜索文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 InputBox 扩展名.我们希望有一个使用两个复选框的搜索功能,如下所示:

We are using the InputBox extension. We want to have a search function using two checkboxes like this:

因此,用户不能选择引用页面上特定文本的一个或两个复选框.也就是说,如果用户选择平台1.0",则搜索将返回页面上带有平台1.0"的页面. (实际上:他们将使用特定的语义属性返回页面,从而在页面上产生文本.)

So, a user can select neither, one or both checkboxes which refer to specific text on the page. That is, if the user selects "Platform 1.0" the search will return pages with "Platform 1.0" on the page. (Actually: they will return pages using a specific semantic property which results in text on the page.)

因此,我们需要一种搜索​​平台文本和在搜索框中输入的文本的方法.

So we want a way to search for the platform text and the text entered in the search box.

我们尝试过:

  • 将这些页面分为几类,但是我们使用模板(模板中的类别)完成此操作这使得它们无法使用类别进行搜索.
  • 使用名称空间/前缀代码为InputBox编写新的PHP代码,但是显然,它们都在搜索API中使用了特定的单词.我们无法在其中添加特定的单词搜索网址.
  • 使用语义的按属性搜索,但是我们无法向该查询添加自定义文本(由用户输入).

非常欢迎想法!

推荐答案

艰难的一个,则可以尝试利用JavaScript以添加所选的每个复选框的当你想要的关键词.大概是这样的:(使用jQuery来提高舒适度,但如果不能选择的话,也可以使用普通的JS):

Tough one, you could try utilizing JavaScript to add a keyword you want when each of the checkboxes is selected. Something like so: (jQuery is used for comfort, but normal JS can be used as well if not an option):

$("#search").submit(function(e) {
    var search_value = $('input[type="text"]', this).val();
    if ($("#checkbox1").checked) { search_value = "SomeValue " + search_value; }
    if ($("#checkbox2").checked) { search_value = "SomeOtherValue " + search_value; }

    $('#search input[type="text"]').val(search_value);
    $(this).submit();
    e.preventDefault();
});

注意,如果用户由于某种原因禁用了JavaScript,则您的功能将被破坏,这通常是一种不良做法.仅在您确实提取了所有其他可能性的情况下,才使用此功能.

Note, should the user disable JavaScript for some reason, your functionality will be damaged, which is always a bad practice. Only use this in case you've really extracted all other possibilities.

这篇关于使用InputBox向MediaWiki搜索查询添加额外的搜索文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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