Ejemplo n.º 1
0
 /**
  * Set the query string
  *
  * This overwrites the current value
  *
  * @param string $query
  * @param array $bind Bind values for placeholders in the query string
  * @return Solarium_Query_Select_Facet_Query Provides fluent interface
  */
 public function setQuery($query, $bind = null)
 {
     if (!is_null($bind)) {
         $helper = new Solarium_Query_Helper();
         $query = $helper->assemble($query, $bind);
     }
     return $this->_setOption('query', $query);
 }
Ejemplo n.º 2
0
 /**
  * Populates document with bundle data.
  *
  * @param \Solarium_Document_ReadWrite $document
  * @param Bundle                       $bundle
  * @param \Solarium_Query_Helper       $helper
  */
 private function updateDocumentFromBundle(\Solarium_Document_ReadWrite $document, Bundle $bundle, \Solarium_Query_Helper $helper)
 {
     $document->setField('id', $bundle->getId());
     $document->setField('name', $bundle->getName());
     $document->setField('ownerName', $bundle->getOwnerName());
     $document->setField('ownerType', $bundle->getOwnerType());
     $document->setField('fullName', $bundle->getFullName());
     $document->setField('description', $bundle->getDescription());
     $document->setField('readme', $bundle->getReadme());
     $document->setField('totalScore', $bundle->getScore());
     $document->setField('state', $bundle->getState());
     $document->setField('avatarUrl', $bundle->getOwner()->getAvatarUrl());
     $document->setField('lastCommitAt', $helper->formatDate(clone $bundle->getLastCommitAt()));
     $document->setField('lastTweetedAt', null !== $bundle->getLastTweetedAt() ? $helper->formatDate($bundle->getLastTweetedAt()) : null);
     $keywords = array();
     foreach ($bundle->getKeywords() as $keyword) {
         $keywords[mb_strtolower($keyword->getValue(), 'UTF-8')] = true;
     }
     $document->setField('keywords', array_keys($keywords));
 }
Ejemplo n.º 3
0
 /**
  * Prevents XSS and escapes characters used in Lucene query syntax.
  * Any query string transformations before sending to backend should be placed here.
  * @see    WikiaSearchTest::testSanitizeQuery
  * @param  string $query
  * @return string
  */
 public static function sanitizeQuery($query)
 {
     wfProfileIn(__METHOD__);
     if (self::$queryHelper === null) {
         self::$queryHelper = new Solarium_Query_Helper();
     }
     // non-indexed number-string phrases issue workaround (RT #24790)
     $query = preg_replace('/(\\d+)([a-zA-Z]+)/i', '$1 $2', $query);
     // escape all lucene special characters: + - && || ! ( ) { } [ ] ^ " ~ * ? : \ (RT #25482)
     // added html entity decoding now that we're doing extra work to prevent xss
     $query = self::$queryHelper->escapeTerm(html_entity_decode($query, ENT_COMPAT, 'UTF-8'));
     wfProfileOut(__METHOD__);
     return $query;
 }
Ejemplo n.º 4
0
 /**
  * Set the query string
  *
  * This overwrites the current value
  *
  * @param string $query
  * @param array $bind Bind values for placeholders in the query string
  * @return Solarium_Query Provides fluent interface
  */
 public function setQuery($query, $bind = null)
 {
     if (!is_null($bind)) {
         $helper = new Solarium_Query_Helper();
         $query = $helper->assemble($query, $bind);
     }
     $this->_query = trim($query);
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Build nested query string 
  * @see Solarium_Client_Builder::build()
  * @param Solarium_Query_Select $query
  * @return string
  */
 public function build($query)
 {
     $helper = new Solarium_Query_Helper();
     return sprintf('_query_:"{!%s %s}%s"', $this->getDefType($query), $this->constructParamString($this->getSubQueryParams($this->getParamsFromQuery($query))), $helper->escapeTerm($query->getQuery()));
 }
Ejemplo n.º 6
0
 public function testJoinDereferenced()
 {
     $this->assertEquals('{!join from=$deref_1 to=$deref_2}', $this->_helper->join('manu_id', 'id', true));
     $this->assertEquals(array('deref_1' => 'manu_id', 'deref_2' => 'id'), $this->_query->getParams());
 }