<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2008 - 2013 fusionLib. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * flSearchResults Class
 *
 * Class to provide access to search results.
 *
 * @package fusionLib
 */
class flSearchResults implements Iterator, Countable {

	/**
	 * The result list.
	 *
	 * @var array
	 */
	private $results;

	/**
	 * The total number of results if no limits were applied.
	 *
	 * @var int
	 */
	private $total;

	/**
	 * Construct the result object.
	 *
	 * @param array Array of results from the search.
	 * @param int The total number of results if no limits were applied.
	 */
	function __construct($results = array(), $total = 0) {
		$this->results = $results;
		$this->total = $total;
	}

	/**
	 * Get the next result in the list.
	 *
	 * @return string The document name or false.
	 */
	function next() {
		return next($this->results);
	}

	/**
	 * Rewind to the 1st element.
	 *
	 * @return string The document name or false.
	 */
	function rewind() {
		return reset($this->results);
	}

	/**
	 * The key of the current result.
	 *
	 * @return int The index of the result within the current set.
	 */
	function key() {
		return key($this->results);
	}

	/**
	 * Return the current result information.
	 *
	 * @return string The document name of the currently selected point in the list.
	 */
	function current() {
		return current($this->results);
	}

	/**
	 * Test if the current position in the results is valid.
	 *
	 * @return bool true if the position is valid; else false.
	 */
	function valid() {
		return current($this->results) !== false;
	}

	/**
	 * Return the total number of available documents matching the query.
	 *
	 * @return int The total number of available documents matching the query.
	 */
	function total() {
		return $this->total;
	}

	/**
	 * Return the count of the results held in the current set.
	 *
	 * @return int The number of results available.
	 */
	function count() {
		return count($this->results);
	}
}
