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

Api search #1782

Merged
merged 8 commits into from Feb 7, 2018
Merged

Api search #1782

merged 8 commits into from Feb 7, 2018

Conversation

teleyinex
Copy link
Member

This new PR will allow using the @> Postgresql operator within the info fields. Basically, you will be able to get all the domain objects that follow a path like this:

http://localhost:5001/api/taskrun?info={"answer":[{"relevant":false}]}

NOTE: you might need to escape your URL if you are using it directly from JS, otherwise chrome does the work for you.

@teleyinex teleyinex added this to the v2.9.1 milestone Feb 6, 2018
@teleyinex
Copy link
Member Author

@alexandermendes this is the first approach for using @> JSONB operator. It's sooo cool and powerful. And the best part is that it's backwards compatible ;-)

@coveralls
Copy link

coveralls commented Feb 6, 2018

Coverage Status

Coverage increased (+0.001%) to 98.053% when pulling 9ffc6bf on api-search into e651837 on master.

It's important to know that if in your info, you don't pass a
proper integer: info="75" PYBOSSA will transform it into a string to
make the query valid.
@teleyinex
Copy link
Member Author

This new query format now allow us to do really complex queries like this:

http://localhost:5001/api/task?info={%22entities%22:%20{%20%22media%22:%20[{%22source_user_id%22:1}]}}

Basically, you can get to any nested data by writing its path within JSON. This one is like this entities->media -> [{source_user_id: value}]

@KrzysztofMadejski
Copy link

Is it limited only if you have an admin API key? Won't such queries hit hard on the database?

@teleyinex
Copy link
Member Author

Hi,

This works for anyone :-)

It won't hit hard at all. Actually, JSONB stores the data efficiently. Also, you can build reverse indexes. I've been testing with Crowdcrafting DB and without an index, it takes around 2s to return something. With an index, it returns it in 0.02 ms. And this is why PostgreSQL is so cool!!

Also, you can create specific indexes, as your data may be different due to the JSON free format.

@therealmarv
Copy link
Contributor

🍰 🍰

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.

None yet

5 participants