Skip to content

Add API for getting facets.#279

Open
colinrobinsonuib wants to merge 3 commits intoProfessionalWiki:masterfrom
colinrobinsonuib:master
Open

Add API for getting facets.#279
colinrobinsonuib wants to merge 3 commits intoProfessionalWiki:masterfrom
colinrobinsonuib:master

Conversation

@colinrobinsonuib
Copy link

It is already possible to search using facets with the existing search API.

Example:

/api.php?action=query&list=search&format=json&srsearch=john+haswbfacet%3AP1%3DQ91&srnamespace=120

Is the same as searching john haswbfacet:P1=Q91 on the search page. But this only gives you the results, not the facets available to do another search. Getting those facets is crucial for building a headless application.

You can search on the elasticsearch server directly as I show in this comment #275 (comment)

This PR adds a new API endpoint for retriving those values directly through mediawiki without needing to expose the elasticsearch server.

Example usage:

api.php?action=wbfacetsearch&search=john+haswbfacet:P1=Q91&format=json&namespaces=120

Response:

{
  "wbfacetsearch": [
    {
      "property": "P55",
      "label": "country of citizenship",
      "values": [
        {
          "value": "Q365",
          "count": 6,
          "label": "United States"
        },
        {
          "value": "Q372",
          "count": 2,
          "label": "Australia"
        },
        {
          "value": "Q366",
          "count": 1,
          "label": "United Kingdom"
        },
        {
          "value": "Q373",
          "count": 1,
          "label": "Netherlands"
        },
        {
          "value": "Q389",
          "count": 1,
          "label": "Republic of Ireland"
        },
        {
          "value": "Q93",
          "count": 1,
          "label": "Canada"
        }
      ]
    },
    {
      "property": "P56",
      "label": "date of birth",
      "values": [
        {
          "value": -5837961600000,
          "count": 1,
          "label": "-5837961600000"
        },
        {
          "value": -1262304000000,
          "count": 1,
          "label": "-1262304000000"
        },
        {
          "value": -441849600000,
          "count": 1,
          "label": "-441849600000"
        },
        {
          "value": -378691200000,
          "count": 1,
          "label": "-378691200000"
        },
        {
          "value": 504921600000,
          "count": 1,
          "label": "504921600000"
        }
      ]
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant