javascript - 如何从维基百科检索内容以进行大量冗长的查询?

标签 javascript api mediawiki wikipedia-api

我尝试使用 Wikipedia API 检索数据

url: "http://en.wikipedia.org//w/api.php?action=opensearch&format=json&search=" + searchvalue + "&limit=12"

其中 searchvalue 是从文本框获取的值。我的问题是,当 searchvalue = "the flash" 时我得到了想要的结果,但当 searchvalue = "the flash and the supergirl 时我没有得到任何结果(空数组)。如何做如果不存在与标题完全匹配的文章,我会调用 API 来检索包含任何单词 searchvalue 的文章。我正在尝试实现如下目标:

https://en.wikipedia.org/w/index.php?search=the+flash+and+the+supergirl&title=Special:Search&go=Go&searchToken=6wtdjlxknk7q715hkdp52cegf 

最佳答案

您可以使用 bool 搜索:

Boolean search – All major search engines support the "-" character for "logical not", the AND, the OR, and the grouping parentheses brackets: (_). Logical OR must be spelled in capital letters; the AND operator is assumed for all terms (separated by spaces), but capital AND is equivalent. Parentheses are a necessary feature because: (blue OR red) AND green, differs from: blue OR (red AND green) -- Wikipedia documentation

因此,如果您想搜索“The Flash”“Supergirl”搜索值将为:“the flash”或“supergirl”.

Here's that query in action

关于javascript - 如何从维基百科检索内容以进行大量冗长的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36365593/

相关文章:

java - 使用 Lucene 索引维基百科

javascript - 自动从上到下滚动页面,然后返回(并重复)

javascript - 通过具有多个值的标签属性查找元素

javascript - 创建 HTML 结构并使用附加函数

android - Google Play 服务已过时。需要 3159100 但找到 3158130

mediawiki - 维基百科/MediaWiki API : Find if an article is about a person, 组织或位置

wiki - MediaWiki之后要使用哪个Wiki?

javascript - 如何使用小数的最大长度

xml - 这个 cURL 命令中的 -d 是什么意思?

api - API验证错误格式