/**
  * Parse a query string given in SMW's query language to create an Query.
  * Parameters are given as key-value-pairs in the given array. The parameter
  * $context defines in what context the query is used, which affects certaim
  * general settings.
  *
  * @since 2.5
  *
  * @param string $queryString
  *
  * @return Query
  */
 public function createFromString($queryString)
 {
     $context = $this->getFromConfigurationWith('context', self::INLINE_QUERY);
     $queryParser = $this->queryFactory->newQueryParser($context == self::CONCEPT_DESC ? $this->conceptFeatures : $this->queryFeatures);
     $contextPage = $this->getFromConfigurationWith('contextPage', null);
     $queryMode = $this->getFromConfigurationWith('queryMode', self::MODE_INSTANCES);
     $queryParser->setContextPage($contextPage);
     $queryParser->setDefaultNamespaces($this->defaultNamespaces);
     $query = $this->queryFactory->newQuery($queryParser->getQueryDescription($queryString), $context);
     $query->setQueryString($queryString);
     $query->setContextPage($contextPage);
     $query->setQuerymode($queryMode);
     $query->setExtraPrintouts($this->getFromConfigurationWith('extraPrintouts', array()));
     $query->setMainLabel($this->getFromConfigurationWith('mainLabel', ''));
     $query->setQuerySource($this->getFromConfigurationWith('querySource', null));
     // keep parsing or other errors for later output
     $query->addErrors($queryParser->getErrors());
     // set sortkeys, limit, and offset
     $query->setOffset(max(0, trim($this->getFromConfigurationWith('offset', 0)) + 0));
     $query->setLimit(max(0, trim($this->getFromConfigurationWith('limit', $this->defaultLimit)) + 0), $queryMode != self::MODE_COUNT);
     $sortKeys = $this->getSortKeys($this->getFromConfigurationWith('sort', array()), $this->getFromConfigurationWith('order', array()), $this->getFromConfigurationWith('defaultSort', 'ASC'));
     $query->addErrors($sortKeys['errors']);
     $query->setSortKeys($sortKeys['keys']);
     return $query;
 }
 private function newQueryResultFromCache($queryId, $query, $container)
 {
     $results = array();
     $this->transientStatsdCollector->incr($query->getContextPage() !== null ? 'hits.embedded' : 'hits.nonEmbedded');
     $this->transientStatsdCollector->calcMedian('medianRetrievalResponseTime.cached', round(microtime(true) - $this->start, 5));
     foreach ($container->get('results') as $hash) {
         $results[] = DIWikiPage::doUnserialize($hash);
     }
     $queryResult = $this->queryFactory->newQueryResult($this->store, $query, $results, $container->get('continue'));
     $queryResult->setCountValue($container->get('count'));
     $queryResult->setFromCache(true);
     $time = round(microtime(true) - $this->start, 5);
     $this->log(__METHOD__ . ' (sec): ' . $time . " ({$queryId})");
     return $queryResult;
 }
 public function testCanConstructConfigurableQueryCreator()
 {
     $instance = new QueryFactory();
     $this->assertInstanceOf('\\SMW\\Query\\ConfigurableQueryCreator', $instance->newConfigurableQueryCreator());
 }