REST API "search2" function not clearly described

Need help? Post your questions here.

Moderator: moderators

REST API "search2" function not clearly described

Postby peter123 » Tue Feb 01, 2011 8:38 am

Hi,

Does anyone have a clue on how to use the new "search2" REST API feature?

There is a parameter named "query" but the API description does not detail how to use it.

Basically I want to know how I can construct the query parameter with album and/or artist and/or title info to search for specific item in database.
I've tried some likely permutations but cannot get it to work.

Any help appreciated.

Thanks.
peter123
 
Posts: 8
Joined: Fri Jan 29, 2010 8:06 am

Postby albertsj1 » Mon May 09, 2011 3:57 pm

I was very confused about this as well, but I think I have figured it out. I'm using curl to test the API. It seems the search2 query accepts the same parameters as the original search; however, you must specify query=1 for it to work.

This works for me.
Code: Select all
curl -d "u=user&p=mypass&c=mycurl&v=1.5.0" http://<serverip>:4040/rest/search2.view\?query\=1\&artist\=AFI


Hope this helps.[/code]
albertsj1
 
Posts: 6
Joined: Mon May 09, 2011 3:54 pm

Re: REST API "search2" function not clearly described

Postby anthony » Fri Sep 02, 2011 10:40 pm

Hi,

I've done a bit of research, here's the result (which completely contradicts what albertsj1 has stated, I'm afraid). It would definitely be helpful if someone in the know could pipe up at some point :)

background

The API call relies on a lucene backend to index and retrieve results http://subsonic.svn.sourceforge.net/viewvc/subsonic/trunk/subsonic-main/src/main/java/net/sourceforge/subsonic/service/LuceneSearchService.java?revision=2409&view=markup.

The query parameter should be a valid lucene query. I've had some success following this documentation http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Grouping

The other parameters (*Count, *Offset) are simply used for paging the results.

in practice

So queries can be structured like this (path/standard parameters omitted, param values not encoded for readability):

Get 10 songs with index entries starting with 'e':
Code: Select all
?query=e*&songCount=10&artistCount=0&albumCount=0


Get 10 artists whose names start with 'a' OR 'z':

Code: Select all
?query=a* OR z*&songCount=10&artistCount=0&albumCount=0


Note that artistCount and albumCount are explicitly set to 0 in these examples, because we want ONLY songs. The default values for those parameters are 20 (subsonic api docs).

I haven't found a way to:

  • query all artists/song/albums (no way to specify 'unlimited' in the *Count parameters, no way to start the query parameter with a wildcard (as stated in lucene doc)
  • send queries like "

So it seems this is really an api call suited for full text searching, and not at all for listing data of various types.

I have come up with the following hack as a solution for the "all artists" query problem like so (javascript):

Code: Select all
var letters = 'abcdefghijklmnopqrstuvwxyz';
var query = letters.split('').join('* OR ') + '*';
// api is just an object I wrote for querying the api
api.search2({query: query, artist: 'a', artistCount: 1000000, songCount: 0, albumCount: 0});


Not satisfactory, really... :D
anthony
 
Posts: 1
Joined: Fri Sep 02, 2011 10:07 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 19 guests