A partial archive of meta.discourse.org as of Tuesday July 18, 2017.

Search API parameters

Milena_Marin

Hi guys!

Have a question regarding the search API - we are using Discourse for this crowdsourcing project: https://decoders.amnesty.org/projects/decode-oil-spills

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

Falco

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

Milena_Marin

Hey @Falco, you linked to this same conversation?

Falco

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.

Milena_Marin

I see, so you are suggesting to search for ‘topic-slug’ instead of topic-id?

Milena_Marin

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?

pfaffman

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).

Milena_Marin

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?

Milena_Marin

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…

Falco

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.

Milena_Marin

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?

Falco

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.

Milena_Marin

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

Simon_Cossar

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

RBoy

This is amazing! I signed up but it doesn’t look like discourse.

Milena_Marin

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/