How to use data api to constrain and combine searches

I'm trying to use the data api to search for specific notes

if i try curl http://localhost:41184/search?query=/foo' i get back the list of notes containing foo
If i leave off the / before foo it returns no notes

If I try to constrain the search to just titles by using
curl 'http://localhost:41184/search?query=title:bar' or
curl 'http://localhost:41184/search?query=title:/bar'
it returns an empty json array...

Once I figure this out I would like to also be able to combine filters such as:
curl 'http://localhost:41184/search?query=notebook:foo%20title:bar'
but I don't know how to separate the two different filters????

just off the top of my head, maybe the first thing is related to the fact that querying "foo" probably does literal/exact search, while "/foo" also matches prefixes?
(If you're confused by that, it's explained somewhere in the docs.)

You just separate filters with a space. So notebook:foo title:bar is OK.

A search with / is a basic search where foo is searched in all combinations (foobar, foo or tofoo) in the note content. A search title:foo search for a note with the word foo in the title, but not for foobar! A search title:/foo search for a /foo word in the title. In the searchfilters you can use Wildcards title:foo*
The search filters do not use wildcards by default and not all support wildcards!
https://joplinapp.org/help/#searching

1 Like

Thank you for the replies... I totally understand the difference between searching for foo and /foo, BUT what you have explained is not how it is working when using the data API.

I have a note with the title foo. When I use curl http://localhost:41184/notes I can see the note with the title foo.

If I use curl http://localhost:41184/search?query=foo the return is an empty json array.

If I use curl http://localhost:41184/search?query=/foo the server returns the information about the note with the title foo
If I try curl http://localhost:41184/search?query=title:foo or curl http://localhost:41184/search?query=title:/foo the server returns an empty json array - ie nothing found

Just to be clear... I am not trying to run these queries inside the terminal app! I am running the terminal app and the webclip server that is supposed to be supporting the data api.

Works for me:

curl 'http://localhost:41184/search?query=foo&token=...'                                
{"items":[{"id":"f4fbd8c7390a4b3a9a4a51a068cf34ff","parent_id":"1c206db76e55453aba852ccaca587f8d","title":"foo"}],"has_more":false}% 

HMMMM. What version of the CLI Client are you using? I'm using 2.9.1, sync version 3, profile version 41

I took a clean empty joplin system and did the following:
curl --silent "http://localhost:41184/notes?token=..."
{"items":[],"has_more":false}

Next:
curl --data '{ "title": "Bar" }' "http://localhost:41184/folders?token=..."
{ "title": "Bar", "id": "e20e0faa0b5d4dc0aa8cd31e4a6b2e37", "updated_time": 1668039924878, "created_time": 1668039924878, "user_updated_time": 1668039924878, "user_created_time": 1668039924878, "type_": 2}
Next:
curl --data '{ "title": "foo", "body": "just some random text" }' "http://localhost:41184/notes?token=..."
{"title":"foo","body":"just some random text","parent_id":"e20e0faa0b5d4dc0aa8cd31e4a6b2e37","markup_language":1,"updated_time":1668040004930,"created_time":1668040004930,"user_updated_time":1668040004930,"user_created_time":1668040004930,"source":"joplin","source_application":"net.cozic.joplin-cli","order":1668040004930,"id":"acb2f082e70d4364950b3a0027946244","type_":1}

Then:
curl 'http://localhost:41184/search?query=foo&token=...'
{"items":[],"has_more":false}

But:
curl 'http://localhost:41184/search?query=/foo&token=...'
{"items":[{"id":"acb2f082e70d4364950b3a0027946244","parent_id":"e20e0faa0b5d4dc0aa8cd31e4a6b2e37","title":"foo"}],"has_more":false}

So what am I doing wrong????

My bad - didn't check the version. And also I am using the desktop app as I assume the code should be the same.

I noticed that if you search immediately after creating a note the search returns nothing, but once the search index has been updated the same query finds the note.

But this could be different between the CLI and desktop versions.