psychonautwiki / bifrost

The PsychonautWiki API.
MIT License
48 stars 10 forks source link

Use unique IDs and allow partial matches when querying for names #12

Open dlbnco opened 5 years ago

dlbnco commented 5 years ago

I guess the main identifier for substances is its name.

Should we have an additional nonmutable id field for Substance and maybe Effect?

Let's say we start using the names as the single source of truth for querying a substance. I'm not sure if this is a realistic scenario, but what if the name of a substance changes for some reason. The original query would be affected. This could lead to 404 errors, for instance.

It would also be nice to query for substances using its ID for a more assertive query. Right now, we use:

Query.substances

query {
  substances(query: "LSD") {
     name
  }
}
{
  "data": {
    "substances": [
      {
        "name": "LSD"
      }
    ]
  }
}

The response is an array, which suggests that we could have more than 1 result. This could be helpful for search boxes, like starting to type "25" and already get a list of the 25-NB family.

But still, I couldn't query a list of more than 1 result when searching for a partial name like "25" or "L", which I assume means that the query is searching for exact matches.

On the other hand, querying for an ID or slug could be useful for loading specific pages while being sure that they won't change. In this case, the result would be a single substance:

Query.substance

query {
  substance(id: "cj9mupzg00lz10155s9npo5n2") {
     name
  }
}
{
  "data": {
    "substance": {
      "name": "1P-LSD"
    }
  }
}
19h commented 5 years ago

There's no such concept in MediaWiki and no resource shall be considered static. That said, substance names are sufficiently stable for them to be considered IDs. We always create redirects if a substance article is moved, and the API respects redirects.

Example: https://api.psychonautwiki.org/?query=query%7Bsubstances(query:%221plsd%22)%7Bname%7D%7D. The 1plsd query implicitly aliases to 1P-LSD.

dlbnco commented 5 years ago

That said, substance names are sufficiently stable for them to be considered IDs.

Cool!

Still, IMO we should also have some method of querying that gives results that partially matches the query (similar behavior to the wiki's search bar).

For example, if I search for "MD" (https://api.psychonautwiki.org/?query=query%7Bsubstances(query:%22MD%22)%7Bname%7D%7D), I should receive all of the following as results:

Maybe use the $regex selector? https://docs.mongodb.com/manual/reference/operator/query/#query-selectors

19h commented 5 years ago

We're not using MongoDB.

That said, it appears as though we could be using a PrefixSearch: https://psychonautwiki.org/w/api.php?action=query&list=prefixsearch&pssearch=LS&format=json. The only issue is that we're not working with a generic search endpoint but with a semantic search (based on meta data inside articles). I'll look into this.

aLoneWitness commented 11 months ago

Hello, any update on this? Im trying to use the Apollo/GraphQL endpoint for a project and would really like prefix/post search capability <3