gbif / hosted-portals

Support material for establishing the GBIF Hosted Portals
Apache License 2.0
9 stars 6 forks source link

filter with "AND" for networkKey #244

Closed ymgan closed 4 months ago

ymgan commented 1 year ago

@antonarctica asked if it is possible to request the feature to filter for records with multiple networkKey?

e.g. to obtain records from datasets that belong to both OBIS and SCAR network

Thank you so much for all of the great work that you have been doing!

MortenHofft commented 1 year ago

It isn't possible through the UI no. I will label this a feature request.

MortenHofft commented 1 year ago

If this is more for a report or such that you yourself are doing, then the API supports it. Is this feature something you believe has interest for the users of the site more broadly?

ymgan commented 1 year ago

Thank you Morten!! In my humble opinion, being able to query it with the API is sufficient.

I believe many users may not understand the meaning of having a record associated with a Network nor query for records based on this filter unless they are extremely familiar with GBIF Network. But I could be too short sighted because I don't know how GBIF Networks will evolve. (e.g. having Project as Network) ...

I wonder if @Antonarctica has a different perspective? (There is a reason why the issue started with "Anton asked") :D

MortenHofft commented 1 year ago

https://graphql.gbif.org/graphql

query

query table($predicate: Predicate, $size: Int = 100){
  occurrenceSearch(predicate: $predicate, size: 0, from: 0) {
    cardinality {
      datasetKey
    }
    facet {
      datasetKey(size: $size) {
        count
        dataset {
          key
          title
          description
          license
        }
      }
    }
  }
}

enter variables on the bottom (open Query variables bottom left)

{
  "predicate": {
    "type": "and",
    "predicates": [
      {
        "type": "within",
        "key": "geometry",
        "value": "POLYGON((180 -44.3,173 -44.3,173 -47.5,170 -47.5,157 -47.5,157 -45.9,150 -45.9,150 -47.5,143 -47.5,143 -45.8,140 -45.8,140 -44.5,137 -44.5,137 -43,135 -43,135 -41.7,131 -41.7,131 -40.1,115 -40.1,92 -40.1,92 -41.4,78 -41.4,78 -42.3,69 -42.3,69 -43.3,47 -43.3,47 -41.7,30 -41.7,12 -41.7,12 -40.3,10 -40.3,10 -38.3,-5 -38.3,-5 -38.9,-9 -38.9,-9 -40.2,-13 -40.2,-13 -41.4,-21 -41.4,-21 -42.5,-39 -42.5,-39 -40.7,-49 -40.7,-49 -48.6,-54 -48.6,-54 -55.7,-62.7972582608082 -55.7,-64 -55.7,-64 -57.8,-71 -57.8,-71 -58.9,-80 -58.9,-80 -40,-125 -40,-167 -40,-167 -42.6,-171 -42.6,-171 -44.3,-180 -44.3,-180 -90, 0 -90,180 -90,180 -44.3))"
      },
      {
        "type": "or",
        "predicates": [
          {
            "type": "equals",
            "key": "networkKey",
            "value": "2b7c7b4f-4d4f-40d3-94de-c28b6fa054a6"
          },
          {
            "type": "equals",
            "key": "networkKey",
            "value": "8534dd20-c368-4a1f-bdaf-e6b390710f89"
          }
        ]
      }
    ]
  },
  "size": 100
}

press play to get the results.

spoiler: 267 datasets in common

ymgan commented 1 year ago

ah thank you Morten!! I am being spoiled here! I didn't know about the graphql playground!

Quick question about the predicates:

If I do the following, do I then get datasets associate with BOTH OBIS and SCAR networks AND within the polygon?

{
  "predicate": {
    "type": "and",
    "predicates": [
      {
        "type": "within",
        "key": "geometry",
        "value": "POLYGON((180 -44.3,173 -44.3,173 -47.5,170 -47.5,157 -47.5,157 -45.9,150 -45.9,150 -47.5,143 -47.5,143 -45.8,140 -45.8,140 -44.5,137 -44.5,137 -43,135 -43,135 -41.7,131 -41.7,131 -40.1,115 -40.1,92 -40.1,92 -41.4,78 -41.4,78 -42.3,69 -42.3,69 -43.3,47 -43.3,47 -41.7,30 -41.7,12 -41.7,12 -40.3,10 -40.3,10 -38.3,-5 -38.3,-5 -38.9,-9 -38.9,-9 -40.2,-13 -40.2,-13 -41.4,-21 -41.4,-21 -42.5,-39 -42.5,-39 -40.7,-49 -40.7,-49 -48.6,-54 -48.6,-54 -55.7,-62.7972582608082 -55.7,-64 -55.7,-64 -57.8,-71 -57.8,-71 -58.9,-80 -58.9,-80 -40,-125 -40,-167 -40,-167 -42.6,-171 -42.6,-171 -44.3,-180 -44.3,-180 -90, 0 -90,180 -90,180 -44.3))"
      },
      {
        "type": "and",
        "predicates": [
          {
            "type": "equals",
            "key": "networkKey",
            "value": "2b7c7b4f-4d4f-40d3-94de-c28b6fa054a6"
          },
          {
            "type": "equals",
            "key": "networkKey",
            "value": "8534dd20-c368-4a1f-bdaf-e6b390710f89"
          }
        ]
      }
    ]
  },
  "size": 100
}
MortenHofft commented 1 year ago

yes, so this could be flattened to (instead of the current A & (B & C)) to A & B & C

{
  "predicate": {
    "type": "and",
    "predicates": [
      {
        "type": "within",
        "key": "geometry",
        "value": "POLYGON((180 -44.3,173 -44.3,173 -47.5,170 -47.5,157 -47.5,157 -45.9,150 -45.9,150 -47.5,143 -47.5,143 -45.8,140 -45.8,140 -44.5,137 -44.5,137 -43,135 -43,135 -41.7,131 -41.7,131 -40.1,115 -40.1,92 -40.1,92 -41.4,78 -41.4,78 -42.3,69 -42.3,69 -43.3,47 -43.3,47 -41.7,30 -41.7,12 -41.7,12 -40.3,10 -40.3,10 -38.3,-5 -38.3,-5 -38.9,-9 -38.9,-9 -40.2,-13 -40.2,-13 -41.4,-21 -41.4,-21 -42.5,-39 -42.5,-39 -40.7,-49 -40.7,-49 -48.6,-54 -48.6,-54 -55.7,-62.7972582608082 -55.7,-64 -55.7,-64 -57.8,-71 -57.8,-71 -58.9,-80 -58.9,-80 -40,-125 -40,-167 -40,-167 -42.6,-171 -42.6,-171 -44.3,-180 -44.3,-180 -90, 0 -90,180 -90,180 -44.3))"
      },
      {
        "type": "equals",
        "key": "networkKey",
        "value": "2b7c7b4f-4d4f-40d3-94de-c28b6fa054a6"
      },
      {
        "type": "equals",
        "key": "networkKey",
        "value": "8534dd20-c368-4a1f-bdaf-e6b390710f89"
      }
    ]
  },
  "size": 100
}
ymgan commented 1 year ago

Thank you so much Morten! I am wondering if you can please advise me how to add the number of occurrence records associated with OBIS and SCAR to the homepage like the screenshot here (red rectangle)? Because Anton believes that it would be helpful to display this on the page for policy makers/funders. But I am not sure how to do that with data-ajax-url ...

Screenshot 2022-10-06 at 15 39 22
MortenHofft commented 4 months ago

It sounds like the API was fine for this use case. I'm closing this issue. Feel free to revive if this should be a UI feature