Page MenuHomePhabricator

Extend query items by statement properties and values functionality to include the 'OR' operator
Closed, ResolvedPublic8 Estimated Story Points

Description

This functionality will allow for a user to find a particular set of QIDs that match one or another criteria. It will work based on how CirrusSearch implements OR, see more here: https://www.mediawiki.org/wiki/Help:CirrusSearch/Logical_operators#Lucene,_MUST,_and_SHOULD. The haswbstatement keyword already implements this, see more here: https://www.mediawiki.org/wiki/Help:Extension:WikibaseCirrusSearch

After we build it, something like this should be possible:
“citizenship=germany AND field of work=chemistry OR physics AND occupation=scientist” ->
haswbstatement:P27=Q183 haswbstatement:P101=Q2329|P101=Q413 haswbstatement:P106=Q90. It will just not be possible to do this with nesting, the criteria cannot be of the form (A OR (B AND C))

Details

Event Timeline

Ifrahkhanyaree_WMDE changed the task status from Open to Stalled.Jan 27 2026, 2:36 PM

CirrusSearch does not support the OR operator as this ticket intends it to work. This ticket is thus stalled until there are some changes made to that

Ifrahkhanyaree_WMDE changed the task status from Stalled to Open.Feb 2 2026, 3:37 PM

We found a work around. GraphQL could support OR after all, just not with nesting and the criteria cannot be of the form
(A OR (B AND C))

Helpful page: https://www.mediawiki.org/wiki/Help:CirrusSearch/Logical_operators#Lucene,_MUST,_and_SHOULD

After we build it, something like this should be possible:
“citizenship=germany AND field of work=chemistry OR physics AND occupation=scientist” ->
haswbstatement:P27=Q183 haswbstatement:P101=Q2329|P101=Q413 haswbstatement:P106=Q901

WMDE-leszek set the point value for this task to 8.Feb 26 2026, 11:19 AM
WMDE-leszek moved this task from Polished to Ready for planning on the Wikibase Reuse Team board.

Change #1248513 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] GQL: Support OR operator in searchItems

https://gerrit.wikimedia.org/r/1248513

Change #1248513 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] GQL: Support OR operator in searchItems

https://gerrit.wikimedia.org/r/1248513

@Silvan_WMDE qq - how does it work now? still have to use AND and just use a pipe operator between the values? or is there an example handy somewhere?

No pipes needed. With this task we introduced or: as a second operator, that can be used within AND clauses.

This query searches for Swiss singers on beta, returning two results

query {
  searchItems(
    query: {
      and: [
        { property: "P694", value: "Q557298" } # singer
        { property: "P748", value: "Q548170" } # Switzerland
      ]
    }
  ) { edges { node { id label(languageCode: "en") } } }
}

Now the new or: operator allows searching for Swiss singers OR actors, giving three results

query {
  searchItems(
    query: {
      and: [
        { or: [
            { property: "P694", value: "Q557298" } # singer
            { property: "P694", value: "Q508927" } # actor
        ] }
        { property: "P748", value: "Q548170" } # Switzerland
      ]
    }
  ) { edges { node { id label(languageCode: "en") } } }
}

You can use or: on the top level (instead of and:) or within an AND clause as shown here. Note that it doesn't work the other way around: and: cannot be used within OR clauses. This means, that only two query levels are possible and complex nesting is effectively impossible.

Maybe we should document the query syntax in the task description

works perfectly! we should probably document this in the GraphQL doc on Wikidata as well but there's a ticket we can pick up next time https://phabricator.wikimedia.org/T419562