维基百科API全文搜索:仅返回完全匹配

时间:2016-06-07 04:26:45

标签: php wikipedia-api

使用维基百科API的搜索功能:

https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=This%20Is%20An%20Example&srwhat=text

我想只收到与字符串完全匹配的结果,但是,这不是返回的结果。

如何在API中引发此行为?

1 个答案:

答案 0 :(得分:1)

leo所说的内容并不多:维基百科现在使用CirrusSearch扩展,因此在使用search API时,您必须参考https://mediawiki.org/wiki/Help:CirrusSearch#Prefer_phrase_matches,它会告诉您{{3} }:

{
    "batchcomplete": "",
    "continue": {
        "sroffset": 1,
        "continue": "-||"
    },
    "query": {
        "searchinfo": {
            "totalhits": 1100
        },
        "search": [
            {
                "ns": 0,
                "title": "Woman in a Purple Coat",
                "snippet": "costume, surrounded by a complex of abstract design and exotic color. <span class=\"searchmatch\">This</span> <span class=\"searchmatch\">is</span> <span class=\"searchmatch\">an</span> <span class=\"searchmatch\">example</span> of one of the final groups of oil paintings in Matisse's career, in",
                "size": 1347,
                "wordcount": 96,
                "timestamp": "2016-10-20T16:52:48Z"
            }
        ]
    }
}