问题描述
我正在尝试wikidata API,但搜索查询"Jas 39 C Gripen"遇到了一些麻烦.它会在wikidata网站上返回结果,但是如果我使用API,则不会返回结果.
I'm trying out the wikidata API but have some trouble with the search query "Jas 39 C Gripen". It returns results on the wikidata website, but not if I use the API.
在wikidata网站上,我得到了两个查询查询结果
On The wikidata website I get two search results for the query
https://www.wikidata.org/w/index.php?search=Jas+39+C+Gripen&title=Special:Search&full=1
使用API的同一查询,不会返回结果
The same query using the API, does not return a result
我缺少某些参数还是使用了错误的参数?对于许多其他查询,我从API获得结果.
Am I missing some parameters or using the wrong parameters? For many other queries I get results from the API.
推荐答案
在解释用户的条目时,本机Wikidata搜索似乎应用了一些模糊逻辑".就您而言,它显示了两个结果,尽管第一个字符中缺少字符C
.
It seems that the native Wikidata search applies some "fuzzy logic" when interpreting the user's entries. In your case, it shows two results, although the character C
is missing in the first one.
回到API 和您选择的操作,您可以使用Jas 39 Gripen
作为搜索词(将显示一个结果)以及Jas 39C Gripen
(也将显示一个结果)结果).但是看来您不能使用Jas 39 C Gripen
(请注意9
和C
之间的空格字符).
Coming back to the API and the action you have chosen, you could use Jas 39 Gripen
as search term (which will show one result) as well as Jas 39C Gripen
(which will also show one result). But it seems that you can't use Jas 39 C Gripen
(note the space character between 9
and C
).
换句话说,
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039%20Gripen
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039C%20Gripen
都可以,但是
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039%20C%20Gripen
没有.
我对此问题进行了进一步调查,最后找到了解决方法.试试这个:
I have investigated this issue further and finally found the solution. Try this:
https://www.wikidata.org/w/api.php?action=query&list=search&format=json&srsearch=Jas+39+C+Gripen
动作query
允许搜索词中出现一些模糊性".有关更多详细信息,请参阅API文档.简而言之,此操作将执行全文搜索(显然是您想要的),并允许使用nearmatch
搜索类型.
The action query
allows some "fuzziness" in the search term. Please refer to the API documentation for further details. In short, this action performs a full text search (which you obviously want) and allows for a nearmatch
search type.
这篇关于从Wikidata网站而不是API获取搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!