Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dlbnco opened this issue May 10, 2019 · 4 comments
Open

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

dlbnco opened this issue May 10, 2019 · 4 comments

Comments

@dlbnco
Copy link

dlbnco commented May 10, 2019

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"
    }
  }
}
@dlbnco dlbnco changed the title Use unique IDs for substances Use unique IDs and allow partial matches when querying for names May 10, 2019
@19h
Copy link
Member

19h commented May 10, 2019

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
Copy link
Author

dlbnco commented May 11, 2019

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:

  • MDMA
  • MDA
  • MDPV
  • MDEA
  • MDAI

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

@19h 19h closed this as completed May 17, 2019
@19h
Copy link
Member

19h commented May 17, 2019

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.

@19h 19h reopened this May 17, 2019
@aLoneWitness
Copy link

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

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

No branches or pull requests

3 participants