If you like to access a different RequestHander than '/select' you can change it via http://php.net/manual/en/solrclient.setservlet.phpΠΡΠΈΠΌΠ΅ΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ ΠΌΠΎΠ΄ΡΠ»Ρ Apache Solr Π² PHP
ΠΡΠΈΠΌΠ΅Ρ #1 Π‘ΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΡΠ°ΠΉΠ»Π° BootStrap
<?php
/* ΠΠΎΠΌΠ΅Π½Π½ΠΎΠ΅ ΠΈΠΌΡ ΡΠ΅ΡΠ²Π΅ΡΠ° Solr */
define('SOLR_SERVER_HOSTNAME', 'solr.example.com');
/* Π‘Π»Π΅Π΄ΡΠ΅Ρ Π»ΠΈ Π·Π°ΠΏΡΡΠΊΠ°ΡΡ Π² Π±Π΅Π·ΠΎΠΏΠ°ΡΠ½ΠΎΠΌ ΡΠ΅ΠΆΠΈΠΌΠ΅ */
define('SOLR_SECURE', true);
/* HTTP-ΠΏΠΎΡΡ Π΄Π»Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ */
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));
/* ΠΠΌΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ Π΄Π»Ρ Π±Π°Π·ΠΎΠ²ΠΎΠΉ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ HTTP */
define('SOLR_SERVER_USERNAME', 'admin');
/* ΠΠ°ΡΠΎΠ»Ρ Π±Π°Π·ΠΎΠ²ΠΎΠΉ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ HTTP */
define('SOLR_SERVER_PASSWORD', 'changeit');
/* ΠΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ HTTP-ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ */
/* ΠΡΠΎ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ Π² ΡΠ΅ΠΊΡΠ½Π΄Π°Ρ
, ΡΠ°Π·ΡΠ΅ΡΡΠ½Π½ΠΎΠ΅ Π΄Π»Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠΈ Π΄Π°Π½Π½ΡΡ
http. ΠΠ½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ - 30 ΡΠ΅ΠΊΡΠ½Π΄ */
define('SOLR_SERVER_TIMEOUT', 10);
/* ΠΠΌΡ ΡΠ°ΠΉΠ»Π° Π΄Π»Ρ Π·Π°ΠΊΡΡΡΠΎΠ³ΠΎ ΠΊΠ»ΡΡΠ° Π² ΡΠΎΡΠΌΠ°ΡΠ΅ PEM + Π·Π°ΠΊΡΡΡΡΠΉ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°Ρ (ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½Π΅Π½Ρ Π² ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠΌ ΠΏΠΎΡΡΠ΄ΠΊΠ΅) */
define('SOLR_SSL_CERT', 'certs/combo.pem');
/* ΠΠΌΡ ΡΠ°ΠΉΠ»Π° ΡΠΎΠ»ΡΠΊΠΎ Π΄Π»Ρ ΡΠ°ΡΡΠ½ΠΎΠ³ΠΎ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ° Π² ΡΠΎΡΠΌΠ°ΡΠ΅ PEM */
define('SOLR_SSL_CERT_ONLY', 'certs/solr.crt');
/* ΠΠΌΡ ΡΠ°ΠΉΠ»Π° Π΄Π»Ρ Π·Π°ΠΊΡΡΡΠΎΠ³ΠΎ ΠΊΠ»ΡΡΠ° Π² ΡΠΎΡΠΌΠ°ΡΠ΅ PEM */
define('SOLR_SSL_KEY', 'certs/solr.key');
/* ΠΠ°ΡΠΎΠ»Ρ Π΄Π»Ρ ΡΠ°ΠΉΠ»Π° Π·Π°ΠΊΡΡΡΠΎΠ³ΠΎ ΠΊΠ»ΡΡΠ° Π² ΡΠΎΡΠΌΠ°ΡΠ΅ PEM */
define('SOLR_SSL_KEYPASSWORD', 'StrongAndSecurePassword');
/* ΠΠΌΡ ΡΠ°ΠΉΠ»Π°, ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠ΅Π³ΠΎ ΠΎΠ΄ΠΈΠ½ ΠΈΠ»ΠΈ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠΎΠ² CA Π΄Π»Ρ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ ΠΎΠ΄Π½ΠΎΡΠ°Π½Π³ΠΎΠ²ΠΎΠ³ΠΎ ΡΠ·Π»Π° */
define('SOLR_SSL_CAINFO', 'certs/cacert.crt');
/* ΠΠΌΡ ΠΊΠ°ΡΠ°Π»ΠΎΠ³Π°, ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠ΅Π³ΠΎ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠΎΠ² CA Π΄Π»Ρ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ ΠΎΠ΄Π½ΠΎΡΠ°Π½Π³ΠΎΠ²ΠΎΠ³ΠΎ ΡΠ·Π»Π° */
define('SOLR_SSL_CAPATH', 'certs/');
?>ΠΡΠΈΠΌΠ΅Ρ #2 ΠΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° Π² ΠΈΠ½Π΄Π΅ΠΊΡ
<?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);
$doc = new SolrInputDocument();
$doc->addField('id', 334455);
$doc->addField('cat', 'Software');
$doc->addField('cat', 'Lucene');
$updateResponse = $client->addDocument($doc);
print_r($updateResponse->getResponse());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 446
)
)
ΠΡΠΈΠΌΠ΅Ρ #3 Π‘Π»ΠΈΡΠ½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠ³ΠΎ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° Ρ Π΄ΡΡΠ³ΠΈΠΌ
<?php
include "bootstrap.php";
$doc = new SolrDocument();
$second_doc = new SolrDocument();
$doc->addField('id', 1123);
$doc->features = "PHP Client Side";
$doc->features = "Fast development cycles";
$doc['cat'] = 'Software';
$doc['cat'] = 'Custom Search';
$doc->cat = 'Information Technology';
$second_doc->addField('cat', 'Lucene Search');
$second_doc->merge($doc, true);
print_r($second_doc->toArray());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
Array
(
[document_boost] => 0
[field_count] => 3
[fields] => Array
(
[0] => SolrDocumentField Object
(
[name] => cat
[boost] => 0
[values] => Array
(
[0] => Software
[1] => Custom Search
[2] => Information Technology
)
)
[1] => SolrDocumentField Object
(
[name] => id
[boost] => 0
[values] => Array
(
[0] => 1123
)
)
[2] => SolrDocumentField Object
(
[name] => features
[boost] => 0
[values] => Array
(
[0] => PHP Client Side
[1] => Fast development cycles
)
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #4 ΠΠΎΠΈΡΠΊ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΎΠ² - ΠΎΡΠ²Π΅ΡΡ SolrObject
<?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();
$query->setQuery('lucene');
$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);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 1
[params] => SolrObject Object
(
[wt] => xml
[rows] => 50
[start] => 0
[indent] => on
[q] => lucene
[fl] => cat,features,id,timestamp
[version] => 2.2
)
)
[response] => SolrObject Object
(
[numFound] => 3
[start] => 0
[docs] => Array
(
[0] => SolrObject Object
(
[cat] => Array
(
[0] => Software
[1] => Lucene
)
[id] => 334456
)
[1] => SolrObject Object
(
[cat] => Array
(
[0] => Software
[1] => Lucene
)
[id] => 334455
)
[2] => SolrObject Object
(
[cat] => Array
(
[0] => software
[1] => search
)
[features] => Array
(
[0] => Advanced Full-Text Search Capabilities using Lucene
[1] => Optimized for High Volume Web Traffic
[2] => Standards Based Open Interfaces - XML and HTTP
[3] => Comprehensive HTML Administration Interfaces
[4] => Scalability - Efficient Replication to other Solr Search Servers
[5] => Flexible and Adaptable with XML configuration and Schema
[6] => Good unicode support: hΓ©llo (hello with an accent over the e)
)
[id] => SOLR1000
[timestamp] => 2009-09-04T20:38:55.906
)
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #5 ΠΠΎΠΈΡΠΊ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΎΠ² - ΠΎΡΠ²Π΅ΡΡ SolrDocument
<?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();
$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);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 1
[params] => SolrObject Object
(
[wt] => xml
[rows] => 50
[start] => 0
[indent] => on
[q] => lucene
[fl] => cat,features,id,timestamp
[version] => 2.2
)
)
[response] => SolrObject Object
(
[numFound] => 3
[start] => 0
[docs] => Array
(
[0] => SolrDocument Object
(
[_hashtable_index:SolrDocument:private] => 19740
)
[1] => SolrDocument Object
(
[_hashtable_index:SolrDocument:private] => 25485
)
[2] => SolrDocument Object
(
[_hashtable_index:SolrDocument:private] => 25052
)
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #6 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Simple TermsComponent
<?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();
$query->setTerms(true);
$query->setTermsField('cat');
$updateResponse = $client->query($query);
print_r($updateResponse->getResponse());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 2
)
[terms] => SolrObject Object
(
[cat] => SolrObject Object
(
[electronics] => 14
[Lucene] => 4
[Software] => 4
[memory] => 3
[card] => 2
[connector] => 2
[drive] => 2
[graphics] => 2
[hard] => 2
[monitor] => 2
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #7 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Simple TermsComponent - ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΏΡΠ΅ΡΠΈΠΊΡΠ°
<?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();
$query->setTerms(true);
/* Return only terms starting with $prefix */
$prefix = 'c';
$query->setTermsField('cat')->setTermsPrefix($prefix);
$updateResponse = $client->query($query);
print_r($updateResponse->getResponse());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 1
)
[terms] => SolrObject Object
(
[cat] => SolrObject Object
(
[card] => 2
[connector] => 2
[camera] => 1
[copier] => 1
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #8 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Simple TermsComponent - ΡΠΊΠ°Π·Π°Π½ΠΈΠ΅ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠΉ ΡΠ°ΡΡΠΎΡΡ
<?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();
$query->setTerms(true);
/* ΠΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΡΠ΅ΡΠΌΠΈΠ½Ρ, Π½Π°ΡΠΈΠ½Π°ΡΡΠΈΠ΅ΡΡ Ρ $prefix */
$prefix = 'c';
/* ΠΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΡΠ΅ΡΠΌΠΈΠ½Ρ Ρ ΡΠ°ΡΡΠΎΡΠΎΠΉ 2 ΠΈΠ»ΠΈ Π±ΠΎΠ»Π΅Π΅ */
$min_frequency = 2;
$query->setTermsField('cat')->setTermsPrefix($prefix)->setTermsMinCount($min_frequency);
$updateResponse = $client->query($query);
print_r($updateResponse->getResponse());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 0
)
[terms] => SolrObject Object
(
[cat] => SolrObject Object
(
[card] => 2
[connector] => 2
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #9 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Simple Facet
<?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('*:*');
$query->setFacet(true);
$query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2);
$updateResponse = $client->query($query);
$response_array = $updateResponse->getResponse();
$facet_data = $response_array->facet_counts->facet_fields;
print_r($facet_data);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[cat] => SolrObject Object
(
[electronics] => 14
[memory] => 3
[Lucene] => 2
[Software] => 2
[card] => 2
[connector] => 2
[drive] => 2
[graphics] => 2
[hard] => 2
[monitor] => 2
[search] => 2
[software] => 2
)
[name] => SolrObject Object
(
[gb] => 6
[1] => 3
[184] => 3
[2] => 3
[3200] => 3
[400] => 3
[500] => 3
[ddr] => 3
[i] => 3
[ipod] => 3
[memori] => 3
[pc] => 3
[pin] => 3
[pod] => 3
[sdram] => 3
[system] => 3
[unbuff] => 3
[canon] => 2
[corsair] => 2
[drive] => 2
[hard] => 2
[mb] => 2
[n] => 2
[power] => 2
[retail] => 2
[video] => 2
[x] => 2
)
)
ΠΡΠΈΠΌΠ΅Ρ #10 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Simple Facet - Ρ Π½Π΅ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΠΌ ΠΏΠ΅ΡΠ΅ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ΠΌ ΠΏΠΎΠ»Ρ Π΄Π»Ρ mincount
<?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('*:*');
$query->setFacet(true);
$query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2)->setFacetMinCount(4, 'name');
$updateResponse = $client->query($query);
$response_array = $updateResponse->getResponse();
$facet_data = $response_array->facet_counts->facet_fields;
print_r($facet_data);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[cat] => SolrObject Object
(
[electronics] => 14
[memory] => 3
[Lucene] => 2
[Software] => 2
[card] => 2
[connector] => 2
[drive] => 2
[graphics] => 2
[hard] => 2
[monitor] => 2
[search] => 2
[software] => 2
)
[name] => SolrObject Object
(
[gb] => 6
)
)
ΠΡΠΈΠΌΠ΅Ρ #11 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Facet Date
<?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('*:*');
$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);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[manufacturedate_dt] => SolrObject Object
(
[2006-02-13T00:00:00Z] => 9
[2007-02-13T00:00:00Z] => 0
[2008-02-13T00:00:00Z] => 0
[2009-02-13T00:00:00Z] => 0
[2010-02-13T00:00:00Z] => 0
[2011-02-13T00:00:00Z] => 0
[gap] => +1YEAR
[start] => 2006-02-13T00:00:00Z
[end] => 2012-02-13T00:00:00Z
[before] => 2
)
)
ΠΡΠΈΠΌΠ΅Ρ #12 ΠΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΊ ΡΠ΅ΡΠ²Π΅ΡΡ Ρ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠΎΠΉ SSL
<?php
include "bootstrap.php";
$options = array
(
'hostname' => SOLR_SERVER_HOSTNAME,
'login' => SOLR_SERVER_USERNAME,
'password' => SOLR_SERVER_PASSWORD,
'port' => SOLR_SERVER_PORT,
'timeout' => SOLR_SERVER_TIMEOUT,
'secure' => SOLR_SECURE,
'ssl_cert' => SOLR_SSL_CERT_ONLY,
'ssl_key' => SOLR_SSL_KEY,
'ssl_keypassword' => SOLR_SSL_KEYPASSWORD,
'ssl_cainfo' => SOLR_SSL_CAINFO,
);
$client = new SolrClient($options);
$query = new SolrQuery('*:*');
$query->setFacet(true);
$query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2)->setFacetMinCount(4, 'name');
$updateResponse = $client->query($query);
$response_array = $updateResponse->getResponse();
$facet_data = $response_array->facet_counts->facet_fields;
print_r($facet_data);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[cat] => SolrObject Object
(
[electronics] => 14
[memory] => 3
[Lucene] => 2
[Software] => 2
[card] => 2
[connector] => 2
[drive] => 2
[graphics] => 2
[hard] => 2
[monitor] => 2
[search] => 2
[software] => 2
)
[name] => SolrObject Object
(
[gb] => 6
)
)
ΠΡΠΈΠΌΠ΅Ρ #13 Π‘Π²ΠΎΡΠ°ΡΠΈΠ²Π°Π½ΠΈΠ΅ SolrQuery
<?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('*:*');
$collapseFunction = new SolrCollapseFunction('manu_id_s');
$collapseFunction
->setSize(2)
->setNullPolicy(SolrCollapseFunction::NULLPOLICY_IGNORE);
$query
->collapse($collapseFunction)
->setRows(4);
$queryResponse = $client->query($query);
$response = $queryResponse->getResponse();
print_r($response);
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[responseHeader] => SolrObject Object
(
[status] => 0
[QTime] => 1
[params] => SolrObject Object
(
[q] => *:*
[indent] => on
[fq] => {!collapse field=manu_id_s size=2 nullPolicy=ignore}
[rows] => 4
[version] => 2.2
[wt] => xml
)
)
[response] => SolrObject Object
(
[numFound] => 14
[start] => 0
[docs] => Array
(
[0] => SolrObject Object
(
[id] => SP2514N
[name] => Array
(
[0] => Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133
)
[manu] => Array
(
[0] => Samsung Electronics Co. Ltd.
)
[manu_id_s] => samsung
[cat] => Array
(
[0] => electronics
[1] => hard drive
)
[features] => Array
(
[0] => 7200RPM, 8MB cache, IDE Ultra ATA-133
[1] => NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor
)
[price] => Array
(
[0] => 92
)
[popularity] => Array
(
[0] => 6
)
[inStock] => Array
(
[0] => 1
)
[manufacturedate_dt] => 2006-02-13T15:26:37Z
[store] => Array
(
[0] => 35.0752,-97.032
)
[_version_] => 1510294336412057600
)
[1] => SolrObject Object
(
[id] => 6H500F0
[name] => Array
(
[0] => Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300
)
[manu] => Array
(
[0] => Maxtor Corp.
)
[manu_id_s] => maxtor
[cat] => Array
(
[0] => electronics
[1] => hard drive
)
[features] => Array
(
[0] => SATA 3.0Gb/s, NCQ
[1] => 8.5ms seek
[2] => 16MB cache
)
[price] => Array
(
[0] => 350
)
[popularity] => Array
(
[0] => 6
)
[inStock] => Array
(
[0] => 1
)
[store] => Array
(
[0] => 45.17614,-93.87341
)
[manufacturedate_dt] => 2006-02-13T15:26:37Z
[_version_] => 1510294336449806336
)
[2] => SolrObject Object
(
[id] => F8V7067-APL-KIT
[name] => Array
(
[0] => Belkin Mobile Power Cord for iPod w/ Dock
)
[manu] => Array
(
[0] => Belkin
)
[manu_id_s] => belkin
[cat] => Array
(
[0] => electronics
[1] => connector
)
[features] => Array
(
[0] => car power adapter, white
)
[weight] => Array
(
[0] => 4
)
[price] => Array
(
[0] => 19.95
)
[popularity] => Array
(
[0] => 1
)
[inStock] => Array
(
[0] =>
)
[store] => Array
(
[0] => 45.18014,-93.87741
)
[manufacturedate_dt] => 2005-08-01T16:30:25Z
[_version_] => 1510294336458194944
)
[3] => SolrObject Object
(
[id] => MA147LL/A
[name] => Array
(
[0] => Apple 60 GB iPod with Video Playback Black
)
[manu] => Array
(
[0] => Apple Computer Inc.
)
[manu_id_s] => apple
[cat] => Array
(
[0] => electronics
[1] => music
)
[features] => Array
(
[0] => iTunes, Podcasts, Audiobooks
[1] => Stores up to 15,000 songs, 25,000 photos, or 150 hours of video
[2] => 2.5-inch, 320x240 color TFT LCD display with LED backlight
[3] => Up to 20 hours of battery life
[4] => Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video
[5] => Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication
)
[includes] => Array
(
[0] => earbud headphones, USB cable
)
[weight] => Array
(
[0] => 5.5
)
[price] => Array
(
[0] => 399
)
[popularity] => Array
(
[0] => 10
)
[inStock] => Array
(
[0] => 1
)
[store] => Array
(
[0] => 37.7752,-100.0232
)
[manufacturedate_dt] => 2005-10-12T08:00:00Z
[_version_] => 1510294336562003968
)
)
)
)
ΠΡΠΈΠΌΠ΅Ρ #14 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Solr Real Time Get (RTG) SolrClient::getById()
<?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);
$response = $client->getById('GB18030TEST');
print_r($response->getResponse());
?>ΠΡΠ²ΠΎΠ΄ ΠΏΡΠΈΠ²Π΅Π΄ΡΠ½Π½ΠΎΠ³ΠΎ ΠΏΡΠΈΠΌΠ΅ΡΠ° Π±ΡΠ΄Π΅Ρ ΠΏΠΎΡ ΠΎΠΆ Π½Π°:
SolrObject Object
(
[doc] => SolrObject Object
(
[id] => GB18030TEST
[name] => Array
(
[0] => Test with some GB18030 encoded characters
)
[features] => Array
(
[0] => No accents here
[1] => θΏζ―δΈδΈͺεθ½
[2] => This is a feature (translated)
[3] => θΏδ»½ζδ»Άζ―εΎζε
ζ³½
[4] => This document is very shiny (translated)
)
[price] => Array
(
[0] => 0
)
[inStock] => Array
(
[0] => 1
)
[_version_] => 1510294336239042560
)
)
If you like to access a different RequestHander than '/select' you can change it via http://php.net/manual/en/solrclient.setservlet.phpIf you are using Solr's multicore feature, you can access the cores via the path parameter in the $options array.
E.g.
<?php
$options = array(...., 'path' => 'solr/core0', ...);
?>As of solr 4.0 the waitFlush parameter is removed.
Source
http://wiki.apache.org/solr/UpdateXmlMessages
$client->commit() throws an error
[SolrClientException]
Unsuccessful update request. Response Code 400. <?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">400</int>
<int name="QTime">1</int>
</lst>
<lst name="error">
<str name="msg">Unknown commit parameter 'waitFlush'</str>
<int name="code">400</int>
</lst>
</response>As of solr 4.0 the waitFlush parameter is removed.
If you're using the solr 4.0 or later version (and you have to),when you do this
<?php $client->commit(); ?>
you will get a solr error like this:
"Unknown commit parameter 'waitFlush'."
If you insist on using this PHP Solr extension and solr 4.0 or later version,you can edit the extension's source (version 1.0.2) php_solr_client.c.
for the SolrClient's optimize method:
at line 1490 :
zend_bool waitFlush = 1, waitSearcher = 1;
after edited:
zend_bool waitSearcher = 1;
at line 1493:
char *waitFlushValue, *waitSearcherValue;
after edited:
zend_bool waitSearcher = 1;
at line 1502:
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbb", &maxSegments, &maxSegmentsLen, &waitFlush, &waitSearcher) == FAILURE) {
after editd:
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &maxSegments, &maxSegmentsLen, &waitSearcher) == FAILURE) {
remove the line 1509 and 1515.
And do the same edit for the SolrClient's commit method at line 1561,1564,1573 and remove the line 1580,1586
The final step, compile the code and install it.
Good luck!In case someone would like to use this solrClient with solr v.4.0 and higher i've prepared my own commit function
class solr {
public function delete($query ) {
$this->_client->deleteByQuery($query);
$this->commit();
}
public function commit() {
$solrConfig= // array with solr host, port, path to collection (/solr/my_collection),
$solrAddress = $solrConfig['hostname'] . ':' . $solrConfig['port'] . $solrConfig['path'];
$output = array();
$response = exec('curl ' . $solrAddress . '/update?commit=true', $output);
return $output;
}
}if your path to solr is something other than: /solr
you should add this to the bootstrap file above:
define('SOLR_SERVER_PATH', 'my-solr-url');
and then a corresponding entry to the options array in your client php code like:
'path' => SOLR_SERVER_PATH
I couldn't find this is in the documentation and had to peek at the source to figure it out.If you're testing these examples on a fresh install of solr, you will need to run a commit statement after you add documents to receive results when searching.
For example, add this:
<?php $client->commit(); ?>
to example 3 to be able to get any results when doing a search using example 5.The documentation in the example section doesn't mention that you need to commit once you've added doc(s).
So in short it would be something like:
$client = new SolrClient(array('hostname' => '127.0.0.1', 'port' => 8080));
$doc = new SolrInputDocument();
$doc->addField('id', 12345);
$doc->addField('name', 'some person');
$result = $client->addDocument($doc);
/* you are not done yet, you need to commit */
$client->commit();
Now if you query you should see your doc =]