示例#1
0
 /**
  * @param <string> $solrSpecVerion
  * @return <string>
  */
 public function getQueryString($solrSpecVerion = null)
 {
     $queryString = parent::getQueryString($solrSpecVersion);
     if (!is_null($this->sortField)) {
         $queryString .= '&sort=' . urlencode($this->sortField['fieldName'] . ' ' . $this->sortField['order']);
     }
     return $queryString;
 }
示例#2
0
 /**
  * Sends a query to the Solr server.
  * 
  * Although it is recommended to provide the query as a {@link SolrQuery}
  * object, it is also possible to pass it as a string. So, the following
  * two lines of code produce exactly the same result:
  * 
  * <code>
  * $result = $solr->query('hello world');
  * $result = $solr->query(new SolrQuery('hello world'));
  * </code>
  * 
  * Please refer to the {@link SolrQuery} class for more details on query
  * parameters and the query syntax.
  * 
  * @see SolrQuery
  * @uses json_decode()
  * 
  * @param SolrQuery|string $query The query.
  * 
  * @return SolrSearchResult
  */
 public function query($query)
 {
     Solr::autoload('SolrSearchResult');
     if (is_string($query)) {
         Solr::autoload('SolrQuery');
         $query = new SolrQuery($query);
     } elseif (!$query instanceof SolrQuery) {
         throw new InvalidArgumentException('Invalid query.');
     }
     $response = $this->httpClient->sendRequest('/select' . $query->getQueryString());
     return SolrSearchResult::parseResponse($response->getBody());
 }
示例#3
0
 /**
  * Tests the magic faceting parameter.
  */
 function testFaceting()
 {
     $query = new SolrQuery($this->solrQuery);
     $this->assertType('SolrSimpleFacets', $query->facets);
     $this->assertEquals('', $query->facets->getQueryStringPart());
     $query->facets->setFields('foo');
     $this->assertEquals($this->queryString . '&facet=true&facet.field=foo', $query->getQueryString());
 }
示例#4
0
//    echo 'result set contains ' . count($result) . ' documents.' . "<br />\n";
//    echo 'starting with document no. ' . $result->getStart() . '.' . "<br />\n";
//    echo "<br />\n";
//
//    $hit = $result[0];
//
//    print_r($hit);
//
//    /* second query */
//    $query = new SwiSolrQuery(array(
//            new SolrSimpleSearchField('title', 'blog'),
//            new SolrSimpleSearchField('content', 'blog')
//        ));
//    echo "The query - " . $query->getQuery() . "<br />\n";
//
//    $result = $solr->query($query);
//
//
//    echo 'found ' . $result->getNumFound() . ' documents total.' . "<br />\n";
//    echo 'result set contains ' . count($result) . ' documents.' . "<br />\n";
//    echo 'starting with document no. ' . $result->getStart() . '.' . "<br />\n";
//
//    $hit = $result[0];
//    print_r($hit);
$query = new SolrQuery("contentType:activity");
$query->facets->setFields("content");
echo $query->getQueryString();
$result = $solr->query($query);
$contentArray = array_rand($result->facets->fields["content"], 10);
//    shuffle($contentArray);
print_r($contentArray);