/**
  * @param $id
  * @param $assignments
  * @param $arguments
  * @return mixed
  */
 protected function getTheRecordSpecified($id, $assignments)
 {
     $connection = $this->getConnection();
     $this->createQuery();
     $escapedID = $this->query->getHelper()->escapeTerm($id);
     $this->query->setQuery('id:' . $escapedID);
     try {
         /** @var \Solarium\Core\Query\Result\ResultInterface $selectResults */
         $selectResults = $connection->execute($this->query);
         if (count($selectResults) > 0) {
             $assignments['results'] = $selectResults;
             $resultSet = $selectResults->getDocuments();
             $assignments['document'] = $resultSet[0];
         } else {
             $message = sprintf('find: »detail« action query for id »%d« returned no results.', $id);
             LoggerUtility::logError($message, ['arguments' => $this->getRequestArguments()]);
         }
     } catch (HttpException $exception) {
         $message = 'find: Solr Exception (Timeout?)';
         LoggerUtility::logError($message, ['arguments' => $this->getRequestArguments(), 'exception' => LoggerUtility::exceptionToArray($exception)]);
     }
     return $assignments;
 }
示例#2
0
 /**
  * @depends testConstructorAndGetters
  *
  * @param PreCreateQuery $event
  */
 public function testSetAndGetQuery($event)
 {
     $query = new Query();
     $query->setQuery('test123');
     $event->setQuery($query);
     $this->assertEquals($query, $event->getQuery());
 }
示例#3
0
 public function testWithTags()
 {
     $this->query->setTags(array('t1', 't2'));
     $this->query->setQuery('cat:1');
     $request = $this->builder->build($this->query);
     $this->assertEquals('{!tag=t1,t2}cat:1', $request->getParam('q'));
 }
示例#4
0
 public function testConstructorAndGetters()
 {
     $query = new Query();
     $query->setQuery('test123');
     $event = new PreCreateRequest($query);
     $this->assertEquals($query, $event->getQuery());
     return $event;
 }
示例#5
0
文件: Builder.php 项目: irto/solrio
 /**
  * Prepare query for to run
  * 
  * @param array $fields to be selected
  * 
  * @return self
  */
 public function prepare(array $fields = null)
 {
     if ($fields !== null) {
         $this->query->setFields($fields);
     }
     $this->query->setQuery($this->rawQuery);
     return $this;
 }
 public function testConstructorAndGetters()
 {
     $query = new Query();
     $query->setQuery('test123');
     $request = new Request();
     $request->addParam('testparam', 'test value');
     $event = new PostCreateRequest($query, $request);
     $this->assertEquals($query, $event->getQuery());
     $this->assertEquals($request, $event->getRequest());
 }
 public function testConstructorAndGetters()
 {
     $type = 'testtype';
     $options = array('key' => 'value');
     $query = new Query();
     $query->setQuery('test123');
     $event = new PostCreateQuery($type, $options, $query);
     $this->assertEquals($type, $event->getQueryType());
     $this->assertEquals($options, $event->getOptions());
     $this->assertEquals($query, $event->getQuery());
 }
示例#8
0
 public function testCreateQueryWithOverridingPlugin()
 {
     $type = Client::QUERY_SELECT;
     $options = array('query' => 'test789');
     $expectedQuery = new SelectQuery();
     $expectedQuery->setQuery('test789');
     $expectedEvent = new PreCreateQueryEvent($type, $options);
     $expectedEvent->setDispatcher($this->client->getEventDispatcher());
     $expectedEvent->setName(Events::PRE_CREATE_QUERY);
     $test = $this;
     $this->client->getEventDispatcher()->addListener(Events::PRE_CREATE_QUERY, function (PreCreateQueryEvent $event) use($test, $expectedQuery, $expectedEvent) {
         $test->assertEquals($expectedEvent, $event);
         $event->setQuery($expectedQuery);
     });
     $returnedQuery = $this->client->createQuery($type, $options);
     $this->assertEquals($expectedQuery, $returnedQuery);
 }
示例#9
0
 public function testSetAndGetQueryWithBind()
 {
     $this->query->setQuery('id:%1%', array(678));
     $this->assertEquals('id:678', $this->query->getQuery());
 }
 /**
  * @param \Solarium\QueryType\Select\Query\Query $select
  */
 public function addKritsToSolr(&$select)
 {
     foreach ($this->krits as $krit) {
         switch ($krit["typ"]) {
             case "betreff":
                 $helper = $select->getHelper();
                 $select->createFilterQuery("betreff")->setQuery("antrag_betreff:" . $helper->escapeTerm($krit["suchbegriff"]));
                 break;
             case "antrag_typ":
                 $select->createFilterQuery("antrag_typ")->setQuery("antrag_typ:" . $krit["suchbegriff"]);
                 break;
             case "antrag_wahlperiode":
                 $select->createFilterQuery("antrag_wahlperiode")->setQuery("antrag_wahlperiode:" . $krit["suchbegriff"]);
                 break;
             case "volltext":
                 /** @var Solarium\QueryType\Select\Query\Component\DisMax $dismax */
                 $dismax = $select->getDisMax();
                 $dismax->setQueryParser('edismax');
                 $dismax->setQueryFields("text text_ocr");
                 $select->setQuery($krit["suchbegriff"]);
                 break;
             case "ba":
                 $select->createFilterQuery("dokument_bas")->setQuery("dokument_bas:" . $krit["ba_nr"]);
                 break;
             case "geo":
                 $helper = $select->getHelper();
                 $select->createFilterQuery("geo")->setQuery($helper->geofilt("geo", $krit["lat"], $krit["lng"], $krit["radius"] / 1000));
                 break;
             case "referat":
                 $helper = $select->getHelper();
                 $select->createFilterQuery("referat")->setQuery("referat_id:" . $helper->escapeTerm($krit["referat_id"]));
                 break;
             case "antrag_nr":
                 /** @var Solarium\QueryType\Select\Query\Component\DisMax $dismax */
                 $dismax = $select->getDisMax();
                 $dismax->setQueryParser('edismax');
                 $dismax->setQueryFields("antrag_nr");
                 $select->setQuery("*" . $krit["suchbegriff"] . "*");
                 break;
         }
     }
 }
 /**
  * Set the query keywords.
  *
  * @param Query $solarium_query
  * @param string $keywords
  */
 private function set_keywords(Query $solarium_query, $keywords)
 {
     $solarium_query->setQuery(WpSolrSchema::_FIELD_NAME_DEFAULT_QUERY . ':' . !empty($keywords) ? $keywords : '*');
 }
示例#12
0
 public function match(Query $query)
 {
     if ($this->expression && ($queryString = $this->expression->build()) !== NULL) {
         $query->setQuery($queryString);
     }
 }
 /**
  * Set the query keywords.
  *
  * @param Query $solarium_query
  * @param string $keywords
  */
 private function set_keywords(Query $solarium_query, $keywords)
 {
     $query_field_name = '';
     $keywords = trim($keywords);
     if (!WPSOLR_Global::getOption()->get_search_fields_is_active()) {
         // No search fields selected, use the default search field
         $query_field_name = WpSolrSchema::_FIELD_NAME_DEFAULT_QUERY . ':';
     } else {
         /// Use search fields with their boost defined in qf instead of default field 'text'
         $query_fields_str = $this->get_query_fields();
         if (!empty($query_fields_str)) {
             $solarium_query->getEDisMax()->setQueryFields($query_fields_str);
         }
         /// Add boosts on field values
         $query_boosts_fields_str = $this->get_query_boosts_fields();
         if (!empty($query_boosts_fields_str)) {
             $solarium_query->getEDisMax()->setBoostQuery($query_boosts_fields_str);
         }
     }
     if (WPSOLR_Global::getOption()->get_search_is_partial_matches()) {
         // Add '*' to each world of the query string.
         // 'word1  word2 ' => 'word1*  word2* '
         $keywords1 = preg_replace('/(\\S+)/i', '$1*', $keywords);
         if ($keywords1 === $keywords . '*') {
             // then use 'OR' to ensure results include the exact keywords also (not only beginning with keywords) if there is one word only
             $keywords = $keywords . ' OR ' . $keywords1;
         } else {
             $keywords = $keywords1;
         }
         $solarium_query->setQuery($query_field_name . !empty($keywords) ? $keywords : '*');
     } elseif (WPSOLR_Global::getOption()->get_search_is_fuzzy_matches()) {
         $keywords = preg_replace('/(\\S+)/i', '$1~', $keywords);
     }
     $this->is_query_wildcard = empty($keywords) || '*' === $keywords;
     // Escape Solr special caracters
     $keywords = $this->escape_solr_special_catacters($keywords);
     $solarium_query->setQuery($query_field_name . (!$this->is_query_wildcard ? $keywords : '*'));
 }