title: Spotify developer search
body: <p>I am confused about how the search function works in the Spotify API.  Their example is like this:</p>
  
  <pre><code>    var sp = getSpotifyApi();
      var models = sp.require('$api/models');
  
      var search = new models.Search('Rihanna');
      search.localResults = models.LOCALSEARCHRESULTS.APPEND;
  
      var searchHTML = document.getElementById('results');
  
      search.observe(models.EVENT.CHANGE, function() {
          var results = search.tracks;
          var fragment = document.createDocumentFragment();
          for (var i=0; i&lt;results.length; i++){
              var link = document.createElement('li');
              var a = document.createElement('a');
              a.href = results[i].uri;
              link.appendChild(a);
              a.innerHTML = results[i].name;
              fragment.appendChild(link);
          }
  
          searchHTML.appendChild(fragment);
      });
  
      search.appendNext();
  </code></pre>
  
  <p>So, I guess that calling appendNext() initiates the search, and the inner function is called when it has results?  But the results are limited to a certain number (default 50) of the total.  How do you get the rest?  Do you call appendNext() again recursively from inside the callback?  Also, does that mean that after you do that, your list includes the original results, or are the original results replaced?  Anyone know of an example that searches through <em>all</em> available results?</p>
  
  <p>Also they mention that if the search is running, appendNext() does nothing.  So how do you gracefully wait until the current search is complete before getting the next 'page'?</p>
  
  <p>Their documentation is terrible, IMHO.  Say you have 1000 search results total from the server.  And say I want to see results 900-1000.  Have I got to keep calling AppendNext over and over until I get to 900?</p>
  
  <p>Thanks
  Bob</p>