-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
53 lines (49 loc) · 1.77 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require_once dirname(__FILE__) . '/lib/SwiSolr.php';
SwiSolr::autoload('SwiSolrQuery');
SwiSolr::autoload('SwiSolrSearchField');
SwiSolr::autoload('SolrSimpleSearchField');
$solr = SwiSolr::connect('http://127.0.0.1:9080/solr1');
// $solr = SwiSolr::connect();
/* first query with string */
// $query = new SwiSolrQuery("title:this^5.0 OR content:blog^1.0");
// $query->setFieldList(array('id', 'title', 'content', 'score'));
//
// $query->setRows(2);
// print_r($solr);
// $result = $solr->query($query);
//
// echo "<br />";
// 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";
// 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);
?>