public function createSearchInfoXml(DataObject $params = null) { !is_null($params) or $params = new DataObject(); // Search string $searchInfoXml = new XmlElement('<SearchInformation/>'); if ($params->hasQuery()) { $query = $this->_escapeQueryString($params->getQuery()); $searchInfoXml->addChild('Query', $query); $searchInfoXml->addChild('OriginalQuery', $query); } // Filters if ($params->hasFilters() && is_array($params->getFilters())) { // create answer container element $answersXml = $searchInfoXml->addChild('QwiserAnsweredAnswers'); $answerCount = 0; foreach ($params->getFilters() as $name => $optionIds) { if (!in_array($name, $this->systemFilters)) { is_array($optionIds) or $optionIds = array($optionIds); foreach ($optionIds as $optionId) { // create answer element $answerXml = $answersXml->addChild('QwiserAnsweredAnswer'); $answerXml->setAttribute('AnswerId', $optionId); $answerXml->setAttribute('EffectOnSearchPath', '0'); // add answer element ++$answerCount; } } } $answersXml->setAttribute('Count', $answerCount); } // Sorting if ($params->hasSortBy() && is_array($params->getSortBy())) { // [<field-name>, <order>] $sortBy = $params->getSortBy(); $name = array_shift($sortBy); $order = array_shift($sortBy); if (!is_null($name)) { // create sorting options element $fieldName = $this->_getSortingFieldName($name); $ascending = $order == 'desc' ? 'false' : 'true'; list($method, $isNumeric) = $this->_getSortingMethod($name); $sortingOptionsXml = $searchInfoXml->addChild('SortingOptions'); $sortingOptionsXml->setAttribute('FieldName', $fieldName); $sortingOptionsXml->setAttribute('Ascending', $ascending); $sortingOptionsXml->setAttribute('Method', $method); if (!is_null($isNumeric)) { $sortingOptionsXml->setAttribute('NumericSort', $isNumeric ? 'true' : 'false'); } } } // Page size if ($params->hasPageSize()) { $searchInfoXml->setAttribute('IsDefaultPageSize', 'false'); $searchInfoXml->setAttribute('PageSize', $params->getPageSize()); } // Current page if ($params->hasCurrentPage()) { $searchInfoXml->setAttribute('CurrentPage', $params->getCurrentPage()); } // some mandatory arguments $searchInfoXml->setAttribute('PriceFieldName', 'Price'); $searchInfoXml->setAttribute('NumberOfPages', 9999999); return $searchInfoXml; }