Search API parameters

Hi guys!

Have a question regarding the search API - we are using Discourse for this crowdsourcing project: Amnesty Decoders

Basically, thousands of people from around the world are helping Amnesty International digitise documents that are hand written. Each of them does a simple task - at the end of the task, they can ask a question or make comments on a Discourse instance. Each task is done by multiple users so we can have more than one comment to a thread which is opened the first time someone comments a task.

We are having some problems with it now and hope you can help.

To post a reply to an existing task, we are using the search API. Basically, when someone posts a comment (we call it ā€˜flagā€™), it looks if anyone else commented the same task - if not, it creates a new topic; if yes, it replies to the the topic that has already been created by the first poster.

The problem is that the search of topic sometimes returns random topicsā€¦ so users end up answering to old, completely unrelated conversationsā€¦

Is there any parameter to the search API that returns the exact topic, as opposed to the approximate one

Or do you have any ideas on how we could fix this problem?

Would really appreciate your answers!

Thanks

2 Likes

When you create the topic for the first ā€œflagā€ you donā€™t store the topic id?

Also, if you store / have a specific format for the title, you donā€™t need to use the search too, for example this topic resolves properly without the ID on the URL: https://meta.discourse.org/t/search-api-parameters

3 Likes

Hey @Falco, you linked to this same conversation?

Yes, if you have the slug (or the title, from which you can derive the slug) you have enough to find a topic.

Iā€™m just not getting why you use the search in this use case, because saving the topic id would be the best topic canonical reference.

2 Likes

I see, so you are suggesting to search for ā€˜topic-slugā€™ instead of topic-id?

I am not a developer, I lead the project and am super frustrated that this is not working for users.

I think this is the call we make to the API: https://discuss.decoders.amnesty.org/search/query.json?api_key=xxxxxxxxxxx&term=2788&api_username=system

as far as I understand, the only parameter of the search API is termā€¦ are we doing something wrong?

1 Like

The topic id is preferable but you make sound like you are not saving the topic id. Given that you donā€™t have the topic id (which would obviate searching), if your topics have unique names, you can just access the slug (as @falcoā€™s example that points to this topic using the title /slug).

2 Likes

is there any way to specify what kind of ā€˜termā€™ we are looking for? whether itā€™s part of a ā€˜topic-slugā€™, a ā€˜topic-idā€™ or anything else?

And thanks so much @pfaffman and @Falco! This is extremely helpful - we spent few days working on this and it keeps throwing bugs at usā€¦

The way you are approaching the problem is the problem.

The first time you create a new topic, you must save the topic ID. Next time you need to direct a user to this topic, just use the same ID to create a new post.

3 Likes

Thanks @Falco. The problem is now that we have a Discourse instance full of existing topics and we want to allow users to reply to thoseā€¦is there any search query we can run to see if the topic-slug already exists?

The only thing you have stored is the topic slug?

If thatā€™s the case a GET request to https://example.com/t/slug will return 301 for an existing topic and 404 for one that donā€™t exists yet.

4 Likes

Thanks! I am not sure we store the topic idā€¦ might be that we have to use the slugā€¦ Thanks so much!!!

I signed up so that I could take a look. What you are doing looks great! This is a very interesting use of Discourse.

It looks like you are using the same pattern to create all the topic titles, with the asset_id as the unique element in each title. @Falcoā€™s approach should be able to work for you: https://discuss.decoders.amnesty.org/t/flag-asset-number-2550.json

5 Likes

This is amazing! I signed up but it doesnā€™t look like discourse.

1 Like

Hi @RBoy, We use discourse for the discussion page , the other bit of the platform is on Hive a crowdsourcing platform from NYT

this is the discourse part: https://discuss.decoders.amnesty.org/

3 Likes