Пример #1
4
 public function solrSearch($text)
 {
     $this->solrConnect();
     $query = new \SolrQuery();
     $query->setQuery('text: *' . $text . '*');
     $query->setStart(0);
     $query->setRows(50);
     $query_response = $this->client->query($query);
     $response = $query_response->getResponse();
     return $response->response;
 }
Пример #2
0
 /**
  * @return \SolrQuery
  */
 public function getSolrQuery()
 {
     $searchTerm = $this->getQueryString();
     if (strlen($searchTerm) > 0) {
         $this->solrQuery->setQuery($searchTerm);
     }
     return $this->solrQuery;
 }
Пример #3
0
 public function query($q, $start = 0, $rows = 50)
 {
     $query = new SolrQuery();
     $query->setQuery($q);
     $query->setStart($start);
     $query->setRows($rows);
     $query_response = $this->client->query($query);
     $response = $query_response->getResponse();
     return $response;
 }
Пример #4
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;
 }
Пример #5
0
 /**
  * Constructor
  * @param array|null $data the parameters to initialize the criteria with
  */
 public function __construct($data = null)
 {
     parent::__construct();
     if ($data !== null) {
         foreach ($data as $key => $value) {
             $this->{$key} = $value;
         }
     }
 }
Пример #6
0
 /**
  *
  * @param SolrQuery $query
  * @return array resultados de la busqueda
  */
 function executeQuery($query)
 {
     if ($query instanceof SolrQuery) {
         $solrUrl = $this->getHost();
         $queryData = $query->getQuery();
         $file = $solrUrl . '/select?';
         $aux = array();
         foreach ($queryData as $queryType => $currentQuery) {
             $aux[] = $queryType . '=' . urlencode($currentQuery);
         }
         $queryPart = implode('&', $aux);
         $file = $file . $queryPart . '&wt=phps';
         $serializedResult = file_get_contents($file);
         $result = unserialize($serializedResult);
         return $result;
     } else {
         throw new Exception('not allowed class');
     }
 }
Пример #7
0
 public function testAutoUpdate()
 {
     $s = new Entity\TestAutoUpdate();
     $s->setContent('Lorem');
     $this->em->persist($s);
     $this->em->flush();
     $query = new \SolrQuery();
     $query->setQuery("id:" . $s->getSolrId());
     $response = $this->client->query($query)->getResponse();
     $this->assertEquals(1, $response->response->numFound);
     $s->setContent('Ipsum');
     $this->em->persist($s);
     $this->em->flush();
     $query = new \SolrQuery();
     $query->setQuery("content:Ipsum");
     $response = $this->client->query($query)->getResponse();
     $this->assertGreaterThanOrEqual(1, $response->response->numFound);
     $query = new \SolrQuery();
     $query->setQuery("id:" . $s->getSolrId());
     $this->em->remove($s);
     $this->em->flush();
     $response = $this->client->query($query)->getResponse();
     $this->assertEquals(0, $response->response->numFound);
 }
Пример #8
0
function getResults($userQuery)
{
    $core = 'techknowledgy_core';
    $options = array('hostname' => 'localhost', 'port' => 8983, 'timeout' => 10, 'path' => '/solr/' . $core);
    $client = new SolrClient($options);
    #if (!$client->ping()) {
    #	exit('Solr service not responding.');
    #}
    #else{
    #	print "Worked!";
    #}
    $query = new SolrQuery();
    $query->setQuery($userQuery);
    $query->setStart(0);
    $query->setRows(1000);
    $query->addField('url')->addField('title')->addField('host')->addField('content');
    $query_response = $client->query($query);
    $response = $query_response->getResponse();
    #print_r($response);
    return $response;
}
Пример #9
0
faq/usage-fink.php#unstable">use
unstable</a> and then download the latest descriptions by running <i>fink selfupdate-rsync</i> 
(or <i>fink selfupdate-cvs</i> if you can't use rsync for some reason).
</p>
<p>Help is also needed to find new maintainers for the <a
href="<?php 
echo $pdbroot;
?>
browse.php?maintainer=None&amp;nochildren=on">packages without maintainers</a>.</p>

<?
$pkgcount = memcache_get_key('pdb-package-count');

if (!$pkgcount) {
	$names = array();
	$q = new SolrQuery();
	$q->addQuery("dist_visible:true", true);
	$q->addField("name_e");
	$q->setUnique(true);
	$r = $q->fetch();
	if ($r != null) {
		$pkgcount = count($r);
		if ($pkgcount > 0) {
			memcache_set_key('pdb-package-count', $pkgcount, false, $cache_timeout);
		}
	}
}

$dyndate = date_create($update_date)->format('U');

$seccount = count($sections);
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT);
$client = new SolrClient($options);
$query = new SolrQuery();
$userInput = 'USB/2';
$escapedUserInput = SolrUtils::escapeQueryChars($userInput);
$query->setQuery('text:' . $escapedUserInput);
echo $query . PHP_EOL;
Пример #11
0
<?php

$options = array('hostname' => 'localhost', 'login' => 'amit', 'password' => 'amit', 'port' => '8983');
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setQuery('pe*');
$query->setStart(0);
$query->setRows(50);
$query->addField('first_product_name')->addField('id');
$query_response = $client->query($query);
$response = $query_response->getResponse();
print_r($response);
?>

Пример #12
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);
Пример #13
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());
 }
Пример #14
0
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setTerms(true);
/* Return only terms starting with $prefix */
$prefix = 'c';
/* Return only terms with a frequency of 2 or greater */
$min_frequency = 2;
$query->setTermsField('cat')->setTermsPrefix($prefix)->setTermsMinCount($min_frequency);
$updateResponse = $client->query($query);
print_r($updateResponse->getResponse());
<?php

$query = new SolrQuery();
$query->setHighlight(0);
$query->addHighlightField('a')->addHighlightField('a')->addHighlightField('a');
$query->removeHighlightField('a')->removeHighlightField('a')->removeHighlightField('a');
$query->setHighlightSnippets(4)->setHighlightSnippets(5, 'june');
$query->setHighlightFragsize(41)->setHighlightFragsize(52, 'june');
$query->setHighlightMergeContiguous(true)->setHighlightMergeContiguous(false, 'june');
$query->setHighlightRequireFieldMatch(true);
$query->setHighlightMaxAnalyzedChars(44)->setHighlightMaxAnalyzedChars(53);
$query->setHighlightAlternateField('pizza')->setHighlightAlternateField('bread', 'june');
$query->setHighlightAlternateField('blue')->setHighlightAlternateField('red', 'june');
$query->setHighlightAlternateField('a')->setHighlightAlternateField('b', 'june');
$query->setHighlightMaxAlternateFieldLength(300)->setHighlightMaxAlternateFieldLength(335, 'june');
$query->setHighlightFormatter('F')->setHighlightFormatter('G', 'june');
$query->setHighlightSimplePre('OO')->setHighlightSimplePre('PP', 'june');
$query->setHighlightSimplePost('ZZ')->setHighlightSimplePost('YY', 'june');
$query->setHighlightFragmenter('gap')->setHighlightFragmenter('space', 'june');
$query->setHighlightUsePhraseHighlighter(false);
$query->setHighlightHighlightMultiTerm(1);
$query->setHighlightRegexSlop(0.0025);
$query->setHighlightRegexPattern("israel")->setHighlightRegexPattern("ekpo");
$query->setHighlightRegexMaxAnalyzedChars(444)->setHighlightRegexMaxAnalyzedChars(5.0);
echo $query;
echo "\n";
 /**
  * Run the search against a sanitized query string via Solr.
  *
  * @param string $string
  * @param array $scriptProperties The scriptProperties array from the SimpleSearch snippet
  * @return array
  */
 public function search($string, array $scriptProperties = array())
 {
     /** @var SolrQuery $query */
     $query = new SolrQuery();
     $query->setQuery($string);
     /* set limit */
     $perPage = $this->modx->getOption('perPage', $scriptProperties, 10);
     if (!empty($perPage)) {
         $offset = $this->modx->getOption('start', $scriptProperties, 0);
         $offsetIndex = $this->modx->getOption('offsetIndex', $scriptProperties, 'sisea_offset');
         if (isset($_REQUEST[$offsetIndex])) {
             $offset = (int) $_REQUEST[$offsetIndex];
         }
         $query->setStart($offset);
         $query->setRows($perPage);
     }
     /* add fields to search */
     $fields = $this->modx->getFields('modResource');
     foreach ($fields as $fieldName => $default) {
         $query->addField($fieldName);
     }
     $includeTVs = $this->modx->getOption('includeTVs', $scriptProperties, false);
     $includeTVList = $this->modx->getOption('includeTVList', $scriptProperties, '');
     if ($includeTVs) {
         $sql = $this->modx->newQuery('modTemplateVar');
         $sql->select($this->modx->getSelectColumns('modTemplateVar', '', '', array('id', 'name')));
         if (!empty($includeTVList)) {
             $includeTVList = explode(',', $includeTVList);
             $includeTVList = array_map('trim', $includeTVList);
             $sql->where(array('name:IN' => $includeTVList));
         }
         $sql->sortby($this->modx->escape('name'), 'ASC');
         $sql->prepare();
         $sql = $sql->toSql();
         $tvs = $this->modx->query($sql);
         if ($tvs && $tvs instanceof PDOStatement) {
             while ($tv = $tvs->fetch(PDO::FETCH_ASSOC)) {
                 $query->addField($tv['name']);
             }
         }
     }
     /* handle hidemenu option */
     $hideMenu = $this->modx->getOption('hideMenu', $scriptProperties, 2);
     if ($hideMenu != 2) {
         $query->addFilterQuery('hidemenu:' . ($hideMenu ? 1 : 0));
     }
     /* handle contexts */
     $contexts = $this->modx->getOption('contexts', $scriptProperties, '');
     $contexts = !empty($contexts) ? $contexts : $this->modx->context->get('key');
     $contexts = implode(' ', explode(',', $contexts));
     $query->addFilterQuery('context_key:(' . $contexts . ')');
     /* handle restrict search to these IDs */
     $ids = $this->modx->getOption('ids', $scriptProperties, '');
     if (!empty($ids)) {
         $idType = $this->modx->getOption('idType', $this->config, 'parents');
         $depth = $this->modx->getOption('depth', $this->config, 10);
         $ids = $this->processIds($ids, $idType, $depth);
         $query->addFilterQuery('id:(' . implode(' ', $ids) . ')');
     }
     /* handle exclude IDs from search */
     $exclude = $this->modx->getOption('exclude', $scriptProperties, '');
     if (!empty($exclude)) {
         $exclude = $this->cleanIds($exclude);
         $exclude = implode(' ', explode(',', $exclude));
         $query->addFilterQuery('-id:(' . $exclude . ')');
     }
     /* basic always-on conditions */
     $query->addFilterQuery('published:1');
     $query->addFilterQuery('searchable:1');
     $query->addFilterQuery('deleted:0');
     /* sorting */
     if (!empty($scriptProperties['sortBy'])) {
         $sortDir = $this->modx->getOption('sortDir', $scriptProperties, 'desc');
         $sortDirs = explode(',', $sortDir);
         $sortBys = explode(',', $scriptProperties['sortBy']);
         $dir = 'desc';
         for ($i = 0; $i < count($sortBys); $i++) {
             if (isset($sortDirs[$i])) {
                 $dir = $sortDirs[$i];
             }
             $dir = strtolower($dir) == 'asc' ? SolrQuery::ORDER_ASC : SolrQuery::ORDER_DESC;
             $query->addSortField($sortBys[$i], $dir);
         }
     }
     /* prepare response array */
     $response = array('total' => 0, 'start' => !empty($offset) ? $offset : 0, 'limit' => $perPage, 'status' => 0, 'query_time' => 0, 'results' => array());
     /* query Solr */
     try {
         $queryResponse = $this->client->query($query);
         $responseObject = $queryResponse->getResponse();
         if ($responseObject) {
             $response['total'] = $responseObject->response->numFound;
             $response['query_time'] = $responseObject->responseHeader->QTime;
             $response['status'] = $responseObject->responseHeader->status;
             $response['results'] = array();
             if (!empty($responseObject->response->docs)) {
                 foreach ($responseObject->response->docs as $doc) {
                     $d = array();
                     foreach ($doc as $k => $v) {
                         $d[$k] = $v;
                     }
                     /** @var modResource $resource */
                     $resource = $this->modx->newObject($d['class_key']);
                     if ($resource->checkPolicy('list')) {
                         $response['results'][] = $d;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error running query on Solr server: ' . $e->getMessage());
     }
     return $response;
 }
Пример #17
0
 /**
  * Sets fields to be returned in the result.
  *
  * @param SolrQuery $query object.
  */
 public function add_fields($query)
 {
     $documentclass = $this->get_document_classname();
     $fields = array_keys($documentclass::get_default_fields_definition());
     foreach ($fields as $field) {
         $query->addField($field);
     }
 }
Пример #18
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());
 }
Пример #19
0
 /**
  * 
  * @param SolrQuery $query
  * @param array $facetFields
  * @return SolrQuery
  */
 public function setFacetQuery(SolrQuery $query, array $facetFields = array())
 {
     if (!empty($facetFields)) {
         $this->_facetFields = array_merge($this->_facetFields, $facetFields);
     }
     for ($i = 0, $fc = count($this->_facetFields); $i < $fc; $i++) {
         $query->addFacetField($this->_facetFields[$i]);
     }
     return $query;
 }
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery('*:*');
$query->setFacet(true);
$query->addFacetQuery('price:[* TO 500]')->addFacetQuery('price:[500 TO *]');
$query_response = $client->query($query);
$response = $query_response->getResponse();
print_r($response->facet_counts->facet_queries);
Пример #21
0
		}
	}
	if ($pobj['infofile']) {
		# where the info file sits on a local Fink installation
		$infofile_path = $pobj['rcspath'];
		$infofile_cvs_url = 'http://fink.cvs.sourceforge.net/fink/'.$pobj['rcspath'];
		if ($pobj['rel_type'] == 'bindist')
			$infofile_tag = '?pathrev=' . $pobj['tag'];
		else
			$infofile_tag = '';
		$infofile_html  = '<a href="'.$infofile_cvs_url.$infofile_tag.($infofile_tag ? '&amp;' : '?').'view=markup" title="' . $pobj['name'] . ' info file">'.$infofile_path.'</a><br>';
		$infofile_html .= '<a href="'.$infofile_cvs_url.$infofile_tag.'?view=log" title="' . $pobj['name'] . ' CVS log">CVS log</a>, Last Changed: '. format_solr_date($pobj['infofilechanged']);
		it_item("Info-File:", $infofile_html);
	}

	$sq = new SolrQuery();
	$sq->addQuery('rel_id:"' . $pobj['rel_id'] . '"', true);
	$sq->addQuery('parentname_e:"' . $pobj['pkg_id'] . '"', true);
	$splitoffs = $sq->fetch();

	if ($splitoffs != null && count($splitoffs) != 0 && is_array($splitoffs)) {
		$contents = "<table>";
		foreach ($splitoffs as $doc) {
			$contents .= "<tr><td>" . link_to_package($doc, $showall) . "</td><td>" . $doc['descshort'] . "</td></tr>\n";
		}
		$contents .= "</table>\n";
		it_item("SplitOffs:", $contents);
	}

	it_end();
?>
 public function findQuery($y_query, $y_options = array('settings' => array(), 'sort' => array(), 'filters' => array(), 'facets' => array(), 'fields' => array()))
 {
     //--
     $connect = $this->solr_connect();
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-queries', 1, '+');
         //--
         $time_start = microtime(true);
         //--
     }
     //end if
     //--
     $query = new SolrQuery();
     $query->setQuery(SolrUtils::escapeQueryChars("'" . $y_query) . "'");
     if (Smart::array_size($y_options['settings']) > 0) {
         foreach ($y_options['settings'] as $key => $val) {
             $method = ucfirst(strtolower($key));
             $query->{'set' . $method}($val);
         }
         //end for
     }
     //end if
     if (Smart::array_size($y_options['sort']) > 0) {
         foreach ($y_options['sort'] as $key => $val) {
             //echo 'Sort by: '.$key.' / '.$val.'<br>';
             $query->addSortField($key, $val);
         }
         //end for
     }
     //end if
     if (Smart::array_size($y_options['filters']) > 0) {
         foreach ($y_options['filters'] as $key => $val) {
             //echo 'Filter Query: '.$key.' / '.$val.'<br>';
             $query->addFilterQuery($key . ':"' . SolrUtils::escapeQueryChars($val) . '"');
         }
         //end for
     }
     //end if
     $have_facets = false;
     if (Smart::array_size($y_options['facets']) > 0) {
         $have_facets = true;
         $query->setFacet(true);
         $query->setFacetMinCount(1);
         for ($i = 0; $i < Smart::array_size($y_options['facets']); $i++) {
             $query->addFacetField((string) $y_options['facets'][$i]);
         }
         //end for
     }
     //end if
     if (Smart::array_size($y_options['fields']) > 0) {
         for ($i = 0; $i < Smart::array_size($y_options['fields']); $i++) {
             $query->addField((string) $y_options['fields'][$i]);
         }
         //end for
     }
     //end if
     try {
         //--
         $response = $this->instance->query($query);
         //--
     } catch (Exception $e) {
         //--
         Smart::log_warning('Solr ERROR # Query # EXCEPTION: ' . $e->getMessage() . "\n" . 'Query=' . print_r($query, 1));
         return array();
         // not connected
         //--
     }
     //end try catch
     $response->setParseMode(SolrResponse::PARSE_SOLR_DOC);
     $data = $response->getResponse();
     //print_r($data);
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $time_end = (double) (microtime(true) - (double) $time_start);
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-time', $time_end, '+');
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|log', ['type' => 'nosql', 'data' => 'FIND-QUERY: ' . $y_query, 'command' => $y_options, 'time' => Smart::format_number_dec($time_end, 9, '.', '')]);
         //--
     }
     //end if
     //--
     if (!is_object($data)) {
         Smart::log_warning('Solr Query: Invalid Object Result');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     if ($data instanceof SolrObject !== true) {
         Smart::log_warning('Solr Query: Invalid Object Instance Result');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     //--
     if (!is_object($data['responseHeader'])) {
         Smart::log_warning('Solr Query: Invalid Object ResponseHeader');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     if ($data['responseHeader'] instanceof SolrObject !== true) {
         Smart::log_warning('Solr Query: Invalid Object Instance ResponseHeader');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     //--
     if ((string) $data['responseHeader']->status != '0') {
         Smart::log_warning('Solr Query: Invalid Status Result');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     //--
     if (!is_object($data['response'])) {
         Smart::log_warning('Solr Query: Invalid Object Response');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     if ($data['response'] instanceof SolrObject !== true) {
         Smart::log_warning('Solr Query: Invalid Object Instance Response');
         return array();
         // connection errors will be threated silently as Solr is a remote service
     }
     //end if
     //--
     if (!is_array($data['response']->docs)) {
         $this->error('Solr Query', 'Invalid Response Document Format', $y_query);
         return array();
     }
     //end if
     //--
     if ($have_facets and is_object($data['facet_counts'])) {
         return array('header' => $data['responseHeader'], 'total' => (int) $data['response']->numFound, 'docs' => (array) $data['response']->docs, 'facets' => (array) $data['facet_counts']->facet_fields);
     } else {
         return array('header' => $data['responseHeader'], 'total' => (int) $data['response']->numFound, 'docs' => (array) $data['response']->docs);
     }
     //end if else
     //--
 }
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setQuery('manu:"Apple Computer Inc." OR text:apple');
$query->setStart(0);
$query->setRows(50);
$query->addField('cat')->addField('features')->addField('id')->addField('timestamp');
$query_response = $client->query($query);
$response = $query_response->getResponse();
print_r($response);
Пример #24
0
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery('*:*');
$query->setFacet(true);
$query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2);
$query->setFacetMinCount(4, 'name');
$updateResponse = $client->query($query);
$response_array = $updateResponse->getResponse();
$facet_data = $response_array->facet_counts->facet_fields;
print_r($facet_data);
Пример #25
0
 /**
  * Get the currently indexed files for a particular document, returns the total count, and a subset of files.
  *
  * @param document $document
  * @param int      $start The row to start the results on. Zero indexed.
  * @param int      $rows The number of rows to fetch
  * @return array   A two element array, the first is the total number of availble results, the second is an array
  *                 of documents for the current request.
  */
 protected function get_indexed_files($document, $start = 0, $rows = 500)
 {
     // Build a custom query that will get any document files that are in our solr_filegroupingid.
     $query = new \SolrQuery();
     // We want to get all file records tied to a document.
     // For efficiency, we are building our own, stripped down, query.
     $query->setQuery('*');
     $query->setRows($rows);
     $query->setStart($start);
     // We want a consistent sorting.
     $query->addSortField('id');
     // We only want the bare minimum of fields.
     $query->addField('id');
     $query->addField('modified');
     $query->addField('title');
     $query->addField('solr_fileid');
     $query->addField('solr_filecontenthash');
     $query->addField('solr_fileindexstatus');
     $query->addFilterQuery('{!cache=false}solr_filegroupingid:(' . $document->get('id') . ')');
     $query->addFilterQuery('type:' . \core_search\manager::TYPE_FILE);
     $response = $this->get_query_response($query);
     if (empty($response->response->numFound)) {
         return array(0, array());
     }
     return array($response->response->numFound, $this->convert_file_results($response));
 }
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setQuery('lucene');
$query->setStart(0);
$query->setRows(50);
$query->addField('cat')->addField('features')->addField('id')->addField('timestamp');
$query_response = $client->query($query);
$query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);
$response = $query_response->getResponse();
print_r($response);
Пример #27
0
 /**
  * Simple Search suggestions interface
  *
  * @deprecated after 1.9.0.0 - integrated into $this->_search()
  *
  * @param string $query The raw query string
  * @param array $params
  * @param int|bool $limit
  * @param bool $withResultsCounts
  * @return array
  */
 public function _searchSuggestions($query, $params = array(), $limit = false, $withResultsCounts = false)
 {
     /**
      * @see self::_search()
      */
     if ((int) ('1' . str_replace('.', '', solr_get_version())) < 1099) {
         $this->_connect();
     }
     $query = $this->_escapePhrase($query);
     if (!$query) {
         return false;
     }
     $_params = array();
     $languageSuffix = $this->_getLanguageSuffix($params['locale_code']);
     $solrQuery = new SolrQuery($query);
     $_params['solr_params'] = array('spellcheck' => 'true', 'spellcheck.collate' => 'true', 'spellcheck.dictionary' => 'magento_spell' . $languageSuffix, 'spellcheck.extendedResults' => 'true', 'spellcheck.count' => $limit ? $limit : 1);
     /**
      * Specific Solr params
      */
     if (!empty($_params['solr_params'])) {
         foreach ($_params['solr_params'] as $name => $value) {
             $solrQuery->setParam($name, $value);
         }
     }
     $this->_client->setServlet(SolrClient::SEARCH_SERVLET_TYPE, 'spell');
     /**
      * Store filtering
      */
     if (!empty($params['store_id'])) {
         $solrQuery->addFilterQuery('store_id:' . $params['store_id']);
     }
     if (!Mage::helper('cataloginventory')->isShowOutOfStock()) {
         $solrQuery->addFilterQuery('in_stock:true');
     }
     try {
         $this->ping();
         $response = $this->_client->query($solrQuery);
         $result = $this->_prepareSuggestionsQueryResponse($response->getResponse());
         $resultLimit = array();
         // Calc results count for each suggestion
         if ($withResultsCounts && $limit) {
             $tmp = $this->_lastNumFound;
             //Temporary store value for main search query
             $this->_lastNumFound = 0;
             foreach ($result as $key => $item) {
                 $this->search($item['word'], $params);
                 if ($this->_lastNumFound) {
                     $result[$key]['num_results'] = $this->_lastNumFound;
                     $resultLimit[] = $result[$key];
                     $limit--;
                 }
                 if ($limit <= 0) {
                     break;
                 }
             }
             $this->_lastNumFound = $tmp;
             //Revert store value for main search query
         } else {
             $resultLimit = array_slice($result, 0, $limit);
         }
         return $resultLimit;
     } catch (Exception $e) {
         Mage::logException($e);
         return array();
     }
 }
Пример #28
0
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setTerms(true);
$query->setTermsField('cat');
$updateResponse = $client->query($query);
print_r($updateResponse->getResponse());
<?php

include "bootstrap.php";
$options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH);
$client = new SolrClient($options);
$query = new SolrQuery('*:*');
$query->setFacet(true);
$query->addFacetDateField('manufacturedate_dt');
$query->setFacetDateStart('2006-02-13T00:00:00Z');
$query->setFacetDateEnd('2012-02-13T00:00:00Z');
$query->setFacetDateGap('+1YEAR');
$query->setFacetDateHardEnd(1);
$query->addFacetDateOther('before');
$updateResponse = $client->query($query);
$response_array = $updateResponse->getResponse();
$facet_data = $response_array->facet_counts->facet_dates;
print_r($facet_data);
Пример #30
0
<?php

$options = array('hostname' => 'localhost', 'port' => '8983', 'path' => 'solr/design_template', 'wt' => 'json');
$client = new SolrClient($options);
//$var=$client->getOptions();
//print_r($var);
//die;
$query = new SolrQuery();
$keyword = $_GET['keyword'];
$keyword = $keyword . "*";
//print "gettype($keyword)";
$keyword1 = "first_product_name:(" . $keyword . ")";
$query->setQuery($keyword1);
$query->setStart(0);
$query->setRows(1000);
$query->addField('first_product_name');
$query_response = $client->query($query);
$response = $query_response->getResponse();
$arr = array();
/*for($i =1; $i<sizeof($response["response"]["docs"]) ;$i++){
	
	if($response["response"]["docs"][$i]["first_product_name"]==$response["response"]["docs"][$i-1]["first_product_name"]){
		echo "dfasdfasdf\n";
	}
	
	else
	$arr[$i]=$response["response"]["docs"][$i]["first_product_name"];
}*/
function search($arr, $string)
{
    for ($i = 0; $i < sizeof($arr); $i++) {