Skip to content
schnatterer edited this page Sep 6, 2014 · 3 revisions

Some explanation and examples on how to perform searches

Search

First you have to instantiate a controller:

Controller controller = new(Controller);

then just hit the search:

controller.search("queryText");

and get the results:

List <searchResult> results;
results = controller.getFullSearchResultList();

the method above hit the server with as many requests are needed, depending on the number of results the query has found.

You could use pagination instead:

results = controller.getFirstSearchResultPage();
while (controller.hasMore()) {
   results = controller.getNextSearchResultPage();
}

Filters

to set the number of results per page:

Long perPage = (long)80;
controller.getSearchFilter().setLimit(perPage);

to stop getting results when Score is too Low:

Long minScore = (long)50;
controller.getSearchFilter().setMinScore(minScore);

Note that the query will always return a full page, also if the score is below the limit you fixed, thid is just a way to break the pagination loop, not really a filter.

Example

(see: org.muscibrainz.junit.unitTests.synopsisUseCase1):

To retrieve all the labels with name similar to "EMI":

Label label = new Label();

label.search("EMI");

List <LabelResultWs2> results = label.getFullSearchResultList();

(see: org.muscibrainz.junit.unitTests.synopsisUseCase2):

To retrieve the first 30 artists with name similar to "pink floyd", scored 50 or over:

Artist artist = new Artist();
      
artist.getSearchFilter().setLimit((long)30);
artist.getSearchFilter().setMinScore((long)50);
   
artist.search("pink floyd");
List<ArtistResultWs2> results  =  artist.getFirstSearchResultPage();
doSomething(results);

to get the remainders (if any):

while (artist.hasMore()) {

    results = artist.getNextSearchResultPage();
    doSomethingElse(results);
}

(see: org.muscibrainz.junit.unitTests.synopsisUseCase3)

To search releases by pink floyd, released in 1982:

Release release = new Release();

release.search("date:1990-??-?? AND creditname:pink floyd");

List<ReleaseResultWs2> results  =  release.getFullSearchResultList()

Please, visit http://musicbrainz.org/doc/Text_Search_Syntax and http://musicbrainz.org/doc/Next_Generation_Schema/SearchServerXML for details.

Once you get a searchResult, you could use the entity that comes with it.

The actual information in the entity depends on the Entity itself, see http://musicbrainz.org/doc/Next_Generation_Schema/SearchServerXML

The query results schema definition is changing, so I prefer not depend too much on it.

You could handle the entity 'as is', in order to print out a list or what else, since at least Id (musicbrainzId) and name or title are always in the result's entity.

see http://musicbrainz.org/doc/Next_Generation_Schema/SearchServerXML

Whenever you need some more information about an entity, you could perform a Lookup.

Clone this wiki locally