Skip to content

Add API for getting facets.#279

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

Add API for getting facets.#279
colinrobinsonuib wants to merge 4 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"
        }
      ]
    }
  ]
}

@JeroenDeDauw
Copy link
Member

@colinrobinsonuib Thanks for the patch! What is your use case that motivates the addition of this new API endpoint?

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 89 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.29%. Comparing base (00e7753) to head (5fe2d19).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/EntryPoints/ApiWikibaseFacetedSearch.php 0.00% 89 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #279      +/-   ##
============================================
- Coverage     74.07%   69.29%   -4.78%     
- Complexity      399      414      +15     
============================================
  Files            47       48       +1     
  Lines          1292     1381      +89     
============================================
  Hits            957      957              
- Misses          335      424      +89     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@colinrobinsonuib
Copy link
Author

@colinrobinsonuib Thanks for the patch! What is your use case that motivates the addition of this new API endpoint?

I'm running mediawiki fully headless, so I need the API to be able to use faceted searches in my frontend.

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.

3 participants