Esempio n. 1
0
 /**
  * search2
  * Get albums, artists and songs matching the given criteria.
  * Takes query with optional artist count, artist offset, album count, album offset, song count and song offset in parameters.
  */
 public static function search2($input, $elementName = "searchResult2")
 {
     self::check_version($input, "1.2.0");
     $query = self::check_parameter($input, 'query');
     $operator = 0;
     if (strlen($query) > 1) {
         if (substr($query, -1) == "*") {
             $query = substr($query, 0, -1);
             $operator = 2;
             // Start with
         }
     }
     $artistCount = isset($input['artistCount']) ? $input['artistCount'] : 20;
     $artistOffset = $input['artistOffset'];
     $albumCount = isset($input['albumCount']) ? $input['albumCount'] : 20;
     $albumOffset = $input['albumOffset'];
     $songCount = isset($input['songCount']) ? $input['songCount'] : 20;
     $songOffset = $input['songOffset'];
     $sartist = array();
     $sartist['limit'] = $artistCount;
     if ($artistOffset) {
         $sartist['offset'] = $artistOffset;
     }
     $sartist['rule_1_input'] = $query;
     $sartist['rule_1_operator'] = $operator;
     $sartist['rule_1'] = "name";
     $sartist['type'] = "artist";
     if ($artistCount > 0) {
         $artists = Search::run($sartist);
     }
     $salbum = array();
     $salbum['limit'] = $albumCount;
     if ($albumOffset) {
         $salbum['offset'] = $albumOffset;
     }
     $salbum['rule_1_input'] = $query;
     $salbum['rule_1_operator'] = $operator;
     $salbum['rule_1'] = "title";
     $salbum['type'] = "album";
     if ($albumCount > 0) {
         $albums = Search::run($salbum);
     }
     $ssong = array();
     $ssong['limit'] = $songCount;
     if ($songOffset) {
         $ssong['offset'] = $songOffset;
     }
     $ssong['rule_1_input'] = $query;
     $ssong['rule_1_operator'] = $operator;
     $ssong['rule_1'] = "anywhere";
     $ssong['type'] = "song";
     if ($songCount > 0) {
         $songs = Search::run($ssong);
     }
     $r = Subsonic_XML_Data::createSuccessResponse();
     Subsonic_XML_Data::addSearchResult($r, $artists, $albums, $songs, $elementName);
     self::apiOutput($input, $r);
 }