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