Commit 7dcb0b21 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/2.2.0'

parents a0b541ac cb45f8b7
.idea
build
phpunit.xml
......@@ -26,14 +26,14 @@ you could also write the switches here)
<antcall target="phpmd"/>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpdoc"/>
<antcall target="docblox"/>
</parallel>
</target>
<!-- Generate jdepend.xml and software metrics charts -->
<target name="pdepend">
<exec executable="pdepend">
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml libraru" />
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml library" />
</exec>
</target>
......@@ -59,9 +59,9 @@ you could also write the switches here)
</target>
<!-- Generate API documentation -->
<target name="phpdoc">
<exec executable="phpdoc">
<arg line="-s on -ue on -d library -t build/api -o HTML:frames:DOM/earthli -ti 'Solarium API Documentation'"/>
<target name="docblox">
<exec executable="docblox">
<arg line="run -d library -t build/api"/>
</exec>
</target>
......
......@@ -14,8 +14,10 @@ $ping = $client->createPing();
// execute the ping query
try{
$client->ping($ping);
$result = $client->ping($ping);
echo 'Ping query succesful';
echo '<br/><pre>';
var_dump($result->getData());
}catch(Solarium_Exception $e){
echo 'Ping query failed';
}
......
......@@ -10,12 +10,7 @@ $client = new Solarium_Client($config);
$query = $client->createSelect();
// create a filterquery
$fq = $query->createFilterQuery();
$fq->setKey('maxprice');
$fq->setQuery('price:[1 TO 300]');
// add it to the query
$query->addFilterQuery($fq);
$query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
// this executes the query and returns the result
$resultset = $client->select($query);
......
......@@ -13,12 +13,7 @@ $query = $client->createSelect();
$facetSet = $query->getFacetSet();
// create a facet field instance and set options
$facet = $facetSet->createFacetField();
$facet->setKey('stock');
$facet->setField('inStock');
// add the facet instance to the facetset
$facetSet->addFacet($facet);
$facetSet->createFacetField('stock')->setField('inStock');
// this executes the query and returns the result
$resultset = $client->select($query);
......
......@@ -13,12 +13,7 @@ $query = $client->createSelect();
$facetSet = $query->getFacetSet();
// create a facet query instance and set options
$facet = $facetSet->createFacetQuery();
$facet->setKey('stock');
$facet->setQuery('inStock: true');
// add the facet instance to the facetset
$facetSet->addFacet($facet);
$facetSet->createFacetQuery('stock')->setQuery('inStock: true');
// this executes the query and returns the result
$resultset = $client->select($query);
......
......@@ -13,16 +13,12 @@ $query = $client->createSelect();
$facetSet = $query->getFacetSet();
// create a facet query instance and set options
$facet = $facetSet->createFacetMultiQuery();
$facet->setKey('stock');
$facet = $facetSet->createFacetMultiQuery('stock');
$facet->createQuery('stock_pricecat1', 'inStock:true AND price:[1 TO 300]');
$facet->createQuery('nostock_pricecat1', 'inStock:false AND price:[1 TO 300]');
$facet->createQuery('stock_pricecat2', 'inStock:true AND price:[300 TO *]');
$facet->createQuery('nostock_pricecat2', 'inStock:false AND price:[300 TO *]');
// add the facet instance to the facetset
$facetSet->addFacet($facet);
// this executes the query and returns the result
$resultset = $client->select($query);
......
......@@ -13,16 +13,12 @@ $query = $client->createSelect();
$facetSet = $query->getFacetSet();
// create a facet field instance and set options
$facet = $facetSet->createFacetRange();
$facet->setKey('priceranges');
$facet = $facetSet->createFacetRange('priceranges');
$facet->setField('price');
$facet->setStart(1);
$facet->setGap(100);
$facet->setEnd(1000);
// add the facet instance to the facetset
$facetSet->addFacet($facet);
// this executes the query and returns the result
$resultset = $client->select($query);
......
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setQuery('memory');
// get highlighting component and apply settings
// highlights are applied to three fields with a different markup for each field
// much more per-field settings are available, see the manual for all options
$hl = $query->getHighlighting();
$hl->getField('name')->setSimplePrefix('<b>')->setSimplePostfix('</b>');
$hl->getField('cat')->setSimplePrefix('<u>')->setSimplePostfix('</u>');
$hl->getField('features')->setSimplePrefix('<i>')->setSimplePostfix('</i>');
// this executes the query and returns the result
$resultset = $client->select($query);
$highlighting = $resultset->getHighlighting();
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table><br/><b>Highlighting results:</b><br/>';
// highlighting results can be fetched by document id (the field defined as uniquekey in this schema)
$highlightedDoc = $highlighting->getResult($document->id);
if($highlightedDoc){
foreach($highlightedDoc as $field => $highlight) {
echo implode(' (...) ', $highlight) . '<br/>';
}
}
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
// add distributed search settings
// see http://wiki.apache.org/solr/DistributedSearch#Distributed_Search_Example for setting up two solr instances
$distributedSearch = $query->getDistributedSearch();
$distributedSearch->addShard('shard1', 'localhost:8983/solr');
$distributedSearch->addShard('shard2', 'localhost:7574/solr');
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setRows(0);
// add spellcheck settings
$spellcheck = $query->getSpellcheck();
$spellcheck->setQuery('delll ultrashar');
$spellcheck->setBuild(true);
$spellcheck->setCollate(true);
$spellcheck->setExtendedResults(true);
$spellcheck->setCollateExtendedResults(true);
// this executes the query and returns the result
$resultset = $client->select($query);
$spellcheckResult = $resultset->getSpellcheck();
echo '<h1>Correctly spelled?</h1>';
if ($spellcheckResult->getCorrectlySpelled()) {
echo 'yes';
}else{
echo 'no';
}
echo '<h1>Suggestions</h1>';
foreach($spellcheckResult as $suggestion) {
echo 'NumFound: '.$suggestion->getNumFound().'<br/>';
echo 'StartOffset: '.$suggestion->getStartOffset().'<br/>';
echo 'EndOffset: '.$suggestion->getEndOffset().'<br/>';
echo 'OriginalFrequency: '.$suggestion->getOriginalFrequency().'<br/>';
echo 'Frequency: '.$suggestion->getFrequency().'<br/>';
echo 'Word: '.$suggestion->getWord().'<br/>';
echo '<hr/>';
}
$collation = $spellcheckResult->getCollation();
echo '<h1>Collation</h1>';
echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
echo 'Corrections:<br/>';
foreach($collation->getCorrections() as $input => $correction) {
echo $input . ' => ' . $correction .'<br/>';
}
htmlFooter();
\ No newline at end of file
......@@ -11,16 +11,10 @@ $query = $client->createSelect();
$helper = $query->getHelper();
// add a filterquery on a price range, using the helper to generate the range
$fqPrice = $query->createFilterQuery();
$fqPrice->setKey('price');
$fqPrice->setQuery($helper->rangeQuery('price', 10, 300));
$query->addFilterQuery($fqPrice);
$query->createFilterQuery('price')->setQuery($helper->rangeQuery('price', 10, 300));
// add a filterquery to find products in a range of 5km, using the helper to generate the 'geofilt' filter
$fqRegion = $query->createFilterQuery();
$fqRegion->setKey('region');
$fqRegion->setQuery($helper->geofilt(45.15, -93.85, 'store', 5));
$query->addFilterQuery($fqRegion);
$query->createFilterQuery('region')->setQuery($helper->geofilt(45.15, -93.85, 'store', 5));
// this executes the query and returns the result
$resultset = $client->select($query);
......
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a morelikethis query instance
$query = $client->createMoreLikeThis();
$query->setQuery('id:SP2514N');
$query->setMltFields('manu,cat');
$query->setMinimumDocumentFrequency(1);
$query->setMinimumTermFrequency(1);
$query->createFilterQuery('stock')->setQuery('inStock:true');
$query->setInterestingTerms('details');
$query->setMatchInclude(true);
// this executes the query and returns the result
$resultset = $client->select($query);
echo 'Document used for matching:<br/><table>';
foreach($resultset->getMatch() AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table><hr/>';
// display the total number of MLT documents found by solr
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
echo '<b>Listing of matched docs:</b>';
// show MLT documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a morelikethis query instance
$query = $client->createMoreLikeThis();
$query->setQuery('electronics memory');
$query->setQueryStream(true);
$query->setMltFields('manu,cat');
$query->setMinimumDocumentFrequency(1);
$query->setMinimumTermFrequency(1);
$query->createFilterQuery('stock')->setQuery('inStock:true');
$query->setInterestingTerms('details');
$query->setMatchInclude(true);
// this executes the query and returns the result
$resultset = $client->select($query);
echo 'Document used for matching:<br/><table>';
foreach($resultset->getMatch() AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table><hr/>';
// display the total number of MLT documents found by solr
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
echo '<b>Listing of matched docs:</b>';
// show MLT documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get an analysis document query
$query = $client->createAnalysisDocument();
$query->setShowMatch(true);
$query->setQuery('ipod');
$doc = new Solarium_Document_ReadWrite(
array(
'id' => 'MA147LL',
'name' => 'Apple 60 GB iPod with Video Playback Black',
'manu' => 'Apple Computer Inc.',
'cat' => 'electronics',
'cat' => 'music',
'features' => 'iTunes, Podcasts, Audiobooks',
'features' => 'Stores up to 15,000 songs, 25,000 photos, or 150 hours of video',
'features' => '2.5-inch, 320x240 color TFT LCD display with LED backlight',
'features' => 'Up to 20 hours of battery life',
'features' => 'Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video',
'features' => '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' => 'earbud headphones, USB cable',
'weight' => 5.5,
'price' => 399.00,
'popularity' => 10,
'inStock' => true,
)
);
$query->addDocument($doc);
// this executes the query and returns the result
$result = $client->analyze($query);
// show the results
foreach ($result as $document) {
echo '<hr><h2>Document: ' . $document->getName() . '</h2>';
foreach ($document as $field) {
echo '<h3>Field: ' . $field->getName() . '</h3>';
$indexAnalysis = $field->getIndexAnalysis();
if (!empty($indexAnalysis)) {
echo '<h4>Index Analysis</h4>';
foreach ($indexAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
echo '-----------<br/>';
}
}
}
$queryAnalysis = $field->getQueryAnalysis();
if (!empty($queryAnalysis)) {
echo '<h4>Query Analysis</h4>';
foreach ($queryAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
echo '-----------<br/>';
}
}
}
}
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get an analysis document query
$query = $client->createAnalysisField();
$query->setShowMatch(true);
$query->setFieldName('cat,title');
$query->setFieldType('text_general');
$query->setFieldValue('Apple 60 GB iPod with Video Playback Black');
$query->setQuery('ipod');
// this executes the query and returns the result
$results = $client->analyze($query);
// show the results
foreach ($results as $result) {
echo '<hr><h2>Result list: ' . $result->getName() . '</h2>';
foreach ($result as $item) {
echo '<h3>Item: ' . $item->getName() . '</h3>';
$indexAnalysis = $item->getIndexAnalysis();
if (!empty($indexAnalysis)) {
echo '<h4>Index Analysis</h4>';
foreach ($indexAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
echo '-----------<br/>';
}
}
}
$queryAnalysis = $item->getQueryAnalysis();
if (!empty($queryAnalysis)) {
echo '<h4>Query Analysis</h4>';
foreach ($queryAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
echo '-----------<br/>';
}
}
}
}
}
htmlFooter();
\ No newline at end of file
......@@ -16,18 +16,11 @@ $query->setFields(array('id','name','price'));
$query->addSort('price', Solarium_Query_Select::SORT_ASC);
// create a filterquery using the API
$fq = $query->createFilterQuery();
$fq->setKey('maxprice');
$fq->setQuery('price:[1 TO 300]');
// and add it to the query
$query->addFilterQuery($fq);
$fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
// create a facet field instance and set options using the API
$facetSet = $query->getFacetSet();
$facet = $facetSet->createFacetField();
$facet->setKey('stock');
$facet->setField('inStock');
$facetSet->addFacet($facet);
$facet = $facetSet->createFacetField('stock')->setField('inStock');
// this executes the query and returns the result
$resultset = $client->select($query);
......
......@@ -19,10 +19,7 @@ class ProductQuery extends Solarium_Query_Select{
// create a facet field instance and set options
$facetSet = $this->getFacetSet();
$facet = $facetSet->createFacetField();
$facet->setKey('stock');
$facet->setField('inStock');
$facetSet->addFacet($facet);
$facetSet->createFacetField('stock')->setField('inStock');
}
}
......@@ -36,12 +33,7 @@ class ProductPriceLimitedQuery extends ProductQuery{
parent::_init();
// create a filterquery
$fq = $this->createFilterQuery();
$fq->setKey('maxprice');
$fq->setQuery('price:[1 TO 300]');
// and add it
$this->addFilterQuery($fq);
$this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
}
}
......
<?php
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// set the adapter to peclhttp
$client->setAdapter('Solarium_Client_Adapter_PeclHttp');
// get a select query instance
$query = $client->createSelect();
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
......@@ -26,38 +26,59 @@
<li><a href="1.3-basic-update.php">1.3 Basic update - add document</a></li>
</ul>
<li>2. Select query</li>
<li>2. Queries</li>
<ul style="list-style:none;">
<li><a href="2.1-query-params.php">2.1 Select query params</a></li>
<li><a href="2.2-custom-result-document.php">2.2 Custom result document</a></li>
<li><a href="2.3-filterquery.php">2.3 Filterquery</a></li>
<li>2.4 Components</li>
<li>2.1. Select query</li>
<ul style="list-style:none;">
<li>2.5.1 FacetSet</li>
<li><a href="2.1.1-query-params.php">2.1.1 Select query params</a></li>
<li><a href="2.1.2-custom-result-document.php">2.1.2 Custom result document</a></li>
<li><a href="2.1.3-filterquery.php">2.1.3 Filterquery</a></li>
<li>2.1.4 Components</li>
<ul style="list-style:none;">
<li><a href="2.5.1.1-facet-field.php">2.5.1.1 Facet field</a></li>
<li><a href="2.5.1.2-facet-query.php">2.5.1.2 Facet query</a></li>
<li><a href="2.5.1.3-facet-multiquery.php">2.5.1.3 Facet multiquery</a></li>
<li><a href="2.5.1.4-facet-range.php">2.5.1.4 Facet range</a></li>
<li>2.1.5.1 FacetSet</li>
<ul style="list-style:none;">
<li><a href="2.1.5.1.1-facet-field.php">2.1.5.1.1 Facet field</a></li>
<li><a href="2.1.5.1.2-facet-query.php">2.1.5.1.2 Facet query</a></li>
<li><a href="2.1.5.1.3-facet-multiquery.php">2.1.5.1.3 Facet multiquery</a></li>
<li><a href="2.1.5.1.4-facet-range.php">2.1.5.1.4 Facet range</a></li>
</ul>
<li><a href="2.1.5.2-morelikethis.php">2.1.5.2 MoreLikeThis</a></li>
<li><a href="2.1.5.3-highlighting.php">2.1.5.3 Highlighting</a></li>
<ul style="list-style:none;">
<li><a href="2.1.5.3.1-per-field-highlighting.php">2.1.5.3.1 Per-field highlighting options</a></li>
</ul>
<li><a href="2.5.2-morelikethis.php">2.5.2 MoreLikeThis</a></li>
<li><a href="2.5.3-highlighting.php">2.5.3 Highlighting</a></li>
<li><a href="2.5.4-dismax.php">2.5.4 Dismax</a></li>
<li><a href="2.5.5-edismax.php">2.5.5 Edismax</a></li>
<li><a href="2.5.6-grouping-by-field.php">2.5.5 Grouping by field</a></li>
<li><a href="2.5.7-grouping-by-query.php">2.5.6 Grouping by query</a></li>
<li><a href="2.1.5.4-dismax.php">2.1.5.4 Dismax</a></li>
<li><a href="2.1.5.5-edismax.php">2.1.5.5 Edismax</a></li>
<li><a href="2.1.5.6-grouping-by-field.php">2.1.5.6 Grouping by field</a></li>
<li><a href="2.1.5.7-grouping-by-query.php">2.1.5.7 Grouping by query</a></li>
<li><a href="2.1.5.8-distributed-search.php">2.1.5.8 Distributed search (sharding)</a></li>
<li><a href="2.1.5.9-spellcheck.php">2.1.5.9 Spellcheck</a></li>
</ul>
<li><a href="2.6-helper-functions.php">2.6 Helper functions</a></li>
<li><a href="2.7-query-reuse.php">2.7 Query re-use</a></li>
<li><a href="2.1.6-helper-functions.php">2.1.6 Helper functions</a></li>
<li><a href="2.1.7-query-reuse.php">2.1.7 Query re-use</a></li>
</ul>
<li>2.2. Update query</li>
<ul style="list-style:none;">
<li><a href="2.2.1-add-docs.php">2.2.1 Add docs</a></li>
<li><a href="2.2.2-delete-by-query.php">2.2.2 Delete by query</a></li>
<li><a href="2.2.3-delete-by-id.php">2.2.3 Delete by ID</a></li>
<li><a href="2.2.4-optimize.php">2.2.4 Optimize index</a></li>
<li><a href="2.2.5-rollback.php">2.2.5 Rollback</a></li>
</ul>
<li>3. Update query</li>
<li>2.3. MoreLikeThis query</li>
<ul style="list-style:none;">
<li><a href="3.1-add-docs.php">3.1 Add docs</a></li>
<li><a href="3.2-delete-by-query.php">3.2 Delete by query</a></li>
<li><a href="3.3-delete-by-id.php">3.3 Delete by ID</a></li>
<li><a href="3.4-optimize.php">3.4 Optimize index</a></li>
<li><a href="3.5-rollback.php">3.5 Rollback</a></li>
<li><a href="2.3.1-mlt-query.php">2.3.1 MoreLikeThis query</a></li>
<li><a href="2.3.2-mlt-stream.php">2.3.2 MoreLikeThis query input as stream</a></li>
</ul>
<li>2.4. Analysis queries</li>
<ul style="list-style:none;">
<li><a href="2.4.1-analysis-document.php">2.4.1 Analysis query for a document</a></li>
<li><a href="2.4.2-analysis-field.php">2.4.2 Analysis query for a field</a></li>
</ul>
</ul>
<li>4. Usage modes</li>
......@@ -80,7 +101,11 @@
<li>6. Miscellaneous</li>
<ul style="list-style:none;">
<li><a href="6.1-zend-http-adapter.php">6.1 Zend_Http adapter</a></li>
<li>6.1 Client adapters</li>
<ul style="list-style:none;">
<li><a href="6.1.1-zend-http-adapter.php">6.1 Zend_Http adapter</a></li>
<li><a href="6.1.2-pecl-http-adapter.php">6.2 Pecl_Http adapter</a></li>
</ul>
<li><a href="6.2-escaping.php">6.2 Escaping</a></li>
<li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li>
</ul>
......
......@@ -58,12 +58,35 @@ class Solarium_Client extends Solarium_Configurable
{
/**
* Querytype definitions
* Querytype select
*/
const QUERYTYPE_SELECT = 'select';
/**
* Querytype update
*/
const QUERYTYPE_UPDATE = 'update';
/**
* Querytype ping
*/
const QUERYTYPE_PING = 'ping';
/**
* Querytype morelikethis
*/
const QUERYTYPE_MORELIKETHIS = 'mlt';
/**
* Querytype analysis field
*/
const QUERYTYPE_ANALYSIS_FIELD = 'analysis-field';
/**
* Querytype analysis document
*/
const QUERYTYPE_ANALYSIS_DOCUMENT = 'analysis-document';
/**
* Default options
*
......@@ -94,6 +117,21 @@ class Solarium_Client extends Solarium_Configurable
'requestbuilder' => 'Solarium_Client_RequestBuilder_Ping',
'responseparser' => 'Solarium_Client_ResponseParser_Ping'
),
self::QUERYTYPE_MORELIKETHIS => array(
'query' => 'Solarium_Query_MoreLikeThis',
'requestbuilder' => 'Solarium_Client_RequestBuilder_MoreLikeThis',
'responseparser' => 'Solarium_Client_ResponseParser_MoreLikeThis'
),
self::QUERYTYPE_ANALYSIS_DOCUMENT => array(
'query' => 'Solarium_Query_Analysis_Document',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Analysis_Document',
'responseparser' => 'Solarium_Client_ResponseParser_Analysis_Document'
),
self::QUERYTYPE_ANALYSIS_FIELD => array(
'query' => 'Solarium_Query_Analysis_Field',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Analysis_Field',
'responseparser' => 'Solarium_Client_ResponseParser_Analysis_Field'
),
);
/**
......@@ -131,11 +169,6 @@ class Solarium_Client extends Solarium_Configurable
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'adapteroptions':
$this->_setOption('adapteroptions', $value);
$adapter = $this->getAdapter();
if ($adapter) $adapter->setOptions($value);
break;
case 'querytype':
$this->registerQueryTypes($value);
break;
......@@ -351,13 +384,24 @@ class Solarium_Client extends Solarium_Configurable
/**
* Remove a plugin instance
*
* @param string $key
* You can remove a plugin by passing the plugin key, or the plugin instance
*
* @param string|Solarium_Plugin_Abstract $plugin
* @return Solarium_Client Provides fluent interface
*/
public function removePlugin($key)
public function removePlugin($plugin)
{
if (isset($this->_plugins[$key])) {
if (is_object($plugin)) {
foreach ($this->_plugins as $key => $instance) {
if ($instance === $plugin) {
unset($this->_plugins[$key]);
break;
}
}
} else {
if (isset($this->_plugins[$plugin])) {
unset($this->_plugins[$plugin]);
}
}
return $this;
}
......@@ -538,6 +582,44 @@ class Solarium_Client extends Solarium_Configurable
return $this->execute($query);
}
/**
* Execute a MoreLikeThis query
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createMoreLikeThis();
* $result = $client->moreLikeThis($query);
* </code>
*
* @see Solarium_Query_MoreLikeThis
* @see Solarium_Result_MoreLikeThis
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param Solarium_Query_MoreLikeThis $query
* @return Solarium_Result_MoreLikeThis
*/
public function moreLikeThis($query)
{
return $this->execute($query);
}
/**
* Execute an analysis query
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param Solarium_Query_Analysis_Document|Solarium_Query_Analysis_Field $query
* @return Solarium_Result_Analysis_Document|Solarium_Result_Analysis_Field
*/
public function analyze($query)
{
return $this->execute($query);
}
/**
* Create a query instance
*
......@@ -575,6 +657,17 @@ class Solarium_Client extends Solarium_Configurable
return $this->createQuery(self::QUERYTYPE_SELECT, $options);
}
/**
* Create a MoreLikeThis query instance
*
* @param mixed $options
* @return Solarium_Query_MoreLikeThis
*/
public function createMoreLikeThis($options = null)
{
return $this->createQuery(self::QUERYTYPE_MORELIKETHIS, $options);
}
/**
* Create an update query instance
*
......@@ -597,5 +690,25 @@ class Solarium_Client extends Solarium_Configurable
return $this->createQuery(self::QUERYTYPE_PING, $options);
}
/**
* Create an analysis field query instance
*
* @param mixed $options
* @return Solarium_Query_Analysis_Field
*/
public function createAnalysisField($options = null)
{
return $this->createQuery(self::QUERYTYPE_ANALYSIS_FIELD, $options);
}
/**
* Create an analysis document query instance
*
* @param mixed $options
* @return Solarium_Query_Analysis_Document
*/
public function createAnalysisDocument($options = null)
{
return $this->createQuery(self::QUERYTYPE_ANALYSIS_DOCUMENT, $options);
}
}
<?php
/**
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Pecl HTTP adapter
*
* @author Gasol Wu <gasol.wu@gmail.com>
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_Adapter_PeclHttp extends Solarium_Client_Adapter
{
/**
* Initialization hook
*
* Checks the availability of pecl_http
*/
protected function _init()
{
// @codeCoverageIgnoreStart
if (!function_exists('http_get')) {
throw new Solarium_Exception('Pecl_http is not available, install it to use the PeclHttp adapter');
}
parent::_init();
// @codeCoverageIgnoreEnd
}
/**
* Execute a Solr request using the Pecl Http
*
* @param Solarium_Client_Request $request
* @return Solarium_Client_Response
*/
public function execute($request)
{
list($data, $headers) = $this->_getData($request);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
}
/**
* Execute request
*
* @param Solarium_Client_Request $request
* @return array
*/
protected function _getData($request)
{
// @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri();
$method = $request->getMethod();
$options = $this->_createOptions($request);
if ($method == Solarium_Client_Request::METHOD_POST) {
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
$httpResponse = http_post_data(
$uri, $request->getRawData(), $options
);
} else if ($method == Solarium_Client_Request::METHOD_GET) {
$httpResponse = http_get($uri, $options);
} else if ($method == Solarium_Client_Request::METHOD_HEAD) {
$httpResponse = http_head($uri, $options);
} else {
throw new Solarium_Exception("unsupported method: $method");
}
$headers = array();
$data = '';
if ($message = http_parse_message($httpResponse)) {
$data = $message->body;
if ($firstPositionOfCRLF = strpos($httpResponse, "\r\n\r\n")) {
$headersAsString = substr(
$httpResponse, 0, $firstPositionOfCRLF
);
$headers = explode("\n", $headersAsString);
}
}
return array($data, $headers);
// @codeCoverageIgnoreEnd
}
/**
* Create http request options from request.
*
* @link http://php.net/manual/en/http.request.options.php
*
* @param Solarium_Client_Request $request
* @return array
*/
protected function _createOptions($request)
{
// @codeCoverageIgnoreStart
$options = array(
'timeout' => $this->getTimeout()
);
foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine);
if ($header = trim($header)) {
$options['headers'][$header] = trim($value);
}
}
return $options;
// @codeCoverageIgnoreEnd
}
/**
* Check result of a request
*
* @throws Solarium_Client_HttpException
* @param string $data
* @param array $headers
* @return void
*/
public function check($data, $headers)
{
// if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible.
if (empty($data) && count($headers) == 0) {
throw new Solarium_Client_HttpException("HTTP request failed");
}
}
}
......@@ -154,6 +154,7 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter
$client->setMethod($request->getMethod());
$client->setUri($this->getBaseUri() . $request->getUri());
$client->setHeaders($request->getHeaders());
$client->setRawData($request->getRawData());
$response = $client->request();
......
......@@ -46,11 +46,19 @@ class Solarium_Client_Request extends Solarium_Configurable
{
/**
* Http request methods
* Request GET method
*/
const METHOD_GET = 'get';
const METHOD_POST = 'post';
const METHOD_HEAD = 'head';
const METHOD_GET = 'GET';
/**
* Request POST method
*/
const METHOD_POST = 'POST';
/**
* Request HEAD method
*/
const METHOD_HEAD = 'HEAD';
/**
* Default options
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build an analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis extends Solarium_Client_RequestBuilder
{
/**
* Build request for an analysis query
*
* @param Solarium_Query_Analysis $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->addParam('wt', 'json');
$request->addParam('analysis.query', $query->getQuery());
$request->addParam('analysis.showmatch', $query->getShowMatch());
return $request;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a document analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis_Document extends Solarium_Client_RequestBuilder_Analysis
{
/**
* Build request for an analysis document query
*
* @param Solarium_Query_Analysis_Document $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->setRawData($this->getRawData($query));
$request->setMethod(Solarium_Client_Request::METHOD_POST);
return $request;
}
/**
* Create the raw post data (xml)
*
* @param Solarium_Query_Analysis_Document $query
* @return string
*/
public function getRawData($query)
{
$xml = '<docs>';
foreach ($query->getDocuments() AS $doc) {
$xml .= '<doc>';
foreach ($doc->getFields() AS $name => $value) {
if (is_array($value)) {
foreach ($value AS $multival) {
$xml .= $this->_buildFieldXml($name, $multival);
}
} else {
$xml .= $this->_buildFieldXml($name, $value);
}
}
$xml .= '</doc>';
}
$xml .= '</docs>';
return $xml;
}
/**
* Build XML for a field
*
* @param string $name
* @param mixed $value
* @return string
*/
protected function _buildFieldXml($name, $value)
{
return '<field name="' . $name . '">' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8') . '</field>';
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a field analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis_Field extends Solarium_Client_RequestBuilder_Analysis
{
/**
* Build request for an analysis field query
*
* @param Solarium_Query_Analysis_Field $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->addParam('analysis.fieldvalue', $query->getFieldValue());
$request->addParam('analysis.fieldname', $query->getFieldName());
$request->addParam('analysis.fieldtype', $query->getFieldType());
return $request;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer.
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a MoreLikeThis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_MoreLikeThis
extends Solarium_Client_RequestBuilder_Select
{
/**
* Build request for a MoreLikeThis query
*
* @param Solarium_Query_MoreLikeThis $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
// add mlt params to request
$request->addParam('mlt.interestingTerms', $query->getInterestingTerms());
$request->addParam('mlt.match.include', $query->getMatchInclude());
$request->addParam('mlt.match.offset', $query->getStart());
$request->addParam('mlt.fl', $query->getMltFields());
$request->addParam('mlt.mintf', $query->getMinimumTermFrequency());
$request->addParam('mlt.mindf', $query->getMinimumDocumentFrequency());
$request->addParam('mlt.minwl', $query->getMinimumWordLength());
$request->addParam('mlt.maxwl', $query->getMaximumWordLength());
$request->addParam('mlt.maxqt', $query->getMaximumQueryTerms());
$request->addParam('mlt.maxntp', $query->getMaximumNumberOfTokens());
$request->addParam('mlt.boost', $query->getBoost());
$request->addParam('mlt.qf', $query->getQueryFields());
// convert query to stream if necessary
if (true === $query->getQueryStream()) {
$request->removeParam('q');
$request->setRawData($query->getQuery());
$request->setMethod(Solarium_Client_Request::METHOD_POST);
$request->addHeader('Content-Type: text/plain; charset=utf-8');
}
return $request;
}
}
......@@ -55,7 +55,8 @@ class Solarium_Client_RequestBuilder_Ping extends Solarium_Client_RequestBuilder
{
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->setMethod(Solarium_Client_Request::METHOD_HEAD);
$request->setMethod(Solarium_Client_Request::METHOD_GET);
$request->addParam('wt', 'json');
return $request;
}
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component distributedsearch to the request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Select_Component_DistributedSearch
{
/**
* Add request settings for DistributedSearch
*
* @param Solarium_Query_Select_Component_DistributedSearch $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public function build($component, $request)
{
// add shard fields to request
$shards = array_values($component->getShards());
if (count($shards)) {
$request->addParam('shards', implode(',', $shards));
}
$request->addParam('shards.qt', $component->getShardRequestHandler());
return $request;
}
}
\ No newline at end of file
......@@ -52,12 +52,13 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public function build($component, $request)
public function build(Solarium_Query_Select_Component_Highlighting $component, Solarium_Client_Request $request)
{
// enable highlighting
$request->addParam('hl', 'true');
$request->addParam('hl.fl', $component->getFields());
// set global highlighting params
$request->addParam('hl.fl', implode(',', array_keys($component->getFields())));
$request->addParam('hl.snippets', $component->getSnippets());
$request->addParam('hl.fragsize', $component->getFragSize());
$request->addParam('hl.mergeContiguous', $component->getMergeContiguous());
......@@ -78,6 +79,33 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
$request->addParam('hl.regex.pattern', $component->getRegexPattern());
$request->addParam('hl.regex.maxAnalyzedChars', $component->getRegexMaxAnalyzedChars());
// set per-field highlighting params
foreach ($component->getFields() as $field) {
$this->_addFieldParams($field, $request);
}
return $request;
}
/**
* Add per-field override options to the request
*
* @param Solarium_Query_Select_Component_Highlighting_Field $field
* @param Solarium_Client_Request $request
* @return void
*/
protected function _addFieldParams($field, $request)
{
$prefix = 'f.' . $field->getName() . '.hl.';
$request->addParam($prefix.'snippets', $field->getSnippets());
$request->addParam($prefix.'fragsize', $field->getFragSize());
$request->addParam($prefix.'mergeContiguous', $field->getMergeContiguous());
$request->addParam($prefix.'alternateField', $field->getAlternateField());
$request->addParam($prefix.'formatter', $field->getFormatter());
$request->addParam($prefix.'simple.pre', $field->getSimplePrefix());
$request->addParam($prefix.'simple.post', $field->getSimplePostfix());
$request->addParam($prefix.'fragmenter', $field->getFragmenter());
$request->addParam($prefix.'useFastVectorHighlighter', $field->getUseFastVectorHighlighter());
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component Spellcheck to the request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Select_Component_Spellcheck
{
/**
* Add request settings for Spellcheck
*
* @param Solarium_Query_Select_Component_Spellcheck $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public function build($component, $request)
{
// enable spellcheck
$request->addParam('spellcheck', 'true');
$request->addParam('spellcheck.q', $component->getQuery());
$request->addParam('spellcheck.build', $component->getBuild());
$request->addParam('spellcheck.reload', $component->getReload());
$request->addParam('spellcheck.dictionary', $component->getDictionary());
$request->addParam('spellcheck.count', $component->getCount());
$request->addParam('spellcheck.onlyMorePopular', $component->getOnlyMorePopular());
$request->addParam('spellcheck.extendedResults', $component->getExtendedResults());
$request->addParam('spellcheck.collate', $component->getCollate());
$request->addParam('spellcheck.maxCollations', $component->getMaxCollations());
$request->addParam('spellcheck.maxCollationTries', $component->getMaxCollationTries());
$request->addParam('spellcheck.maxCollationEvaluations', $component->getMaxCollationEvaluations());
$request->addParam('spellcheck.collateExtendedResults', $component->getCollateExtendedResults());
$request->addParam('spellcheck.accuracy', $component->getAccuracy());
return $request;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse document analysis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Analysis_Document extends Solarium_Client_ResponseParser_Analysis_Field
{
/**
* Parse implementation
*
* @param array $data
* @return array
*/
protected function _parseAnalysis($data)
{
$documents = array();
foreach ($data as $documentKey => $documentData) {
$fields = $this->_parseTypes($documentData);
$documents[] = new Solarium_Result_Analysis_List($documentKey, $fields);
}
return $documents;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse document analysis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Analysis_Field extends Solarium_Client_ResponseParser
{
/**
* Parse response data
*
* @param Solarium_Result $result
* @return array
*/
public function parse($result)
{
$data = $result->getData();
if (isset($data['analysis'])) {
$items = $this->_parseAnalysis($data['analysis']);
} else {
$items = array();
}
return array(
'status' => $data['responseHeader']['status'],
'queryTime' => $data['responseHeader']['QTime'],
'items' => $items
);
}
/**
* Parser
*
* @param array $data
* @return array
*/
protected function _parseAnalysis($data)
{
$types = array();
foreach ($data as $documentKey => $documentData) {
$fields = $this->_parseTypes($documentData);
$types[] = new Solarium_Result_Analysis_List($documentKey, $fields);
}
return $types;
}
/**
* Parse analysis types and items
*
* @param array $typeData
* @return array
*/
protected function _parseTypes($typeData)
{
$results = array();
foreach ($typeData as $fieldKey => $fieldData) {
$types = array();
foreach ($fieldData as $typeKey => $typeData) {
// fix for extra level for key fields
if (count($typeData) == 1) {
$typeData = current($typeData);
}
$counter = 0;
$classes = array();
while (isset($typeData[$counter]) && isset($typeData[$counter+1])) {
$class = $typeData[$counter];
$analysis = $typeData[$counter+1];
$items = array();
foreach ($analysis AS $itemData) {
$items[] = new Solarium_Result_Analysis_Item($itemData);
}
$classes[] = new Solarium_Result_Analysis_List($class, $items);
$counter += 2;
}
$types[] = new Solarium_Result_Analysis_List($typeKey, $classes);
}
$results[] = new Solarium_Result_Analysis_Types($fieldKey, $types);
}
return $results;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse MoreLikeThis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_MoreLikeThis extends Solarium_Client_ResponseParser_Select
{
/**
* Get result data for the response
*
* @param Solarium_Result_MoreLikeThis $result
* @return array
*/
public function parse($result)
{
$data = $result->getData();
$query = $result->getQuery();
$parseResult = parent::parse($result);
if (isset($data['interestingTerms']) && 'none' != $query->getInterestingTerms()) {
$terms = $data['interestingTerms'];
if ('details' == $query->getInterestingTerms()) {
$tempTerms = array();
for ($i = 0; $i < count($terms); $i += 2) {
$tempTerms[$terms[$i]] = $terms[$i + 1];
}
$terms = $tempTerms;
}
$parseResult['interestingTerms'] = $terms;
}
if (isset($data['match']['docs'][0]) && true == $query->getMatchInclude()) {
$matchData = $data['match']['docs'][0];
$documentClass = $query->getOption('documentclass');
$fields = (array)$matchData;
$parseResult['match'] = new $documentClass($fields);
}
return $parseResult;
}
}
......@@ -171,12 +171,18 @@ class Solarium_Client_ResponseParser_Select_Component_FacetSet
if (isset($data['facet_counts']['facet_ranges'][$key])) {
$data = $data['facet_counts']['facet_ranges'][$key];
$before = (isset($data['before'])) ? $data['before'] : null;
$after = (isset($data['after'])) ? $data['after'] : null;
$between = (isset($data['between'])) ? $data['between'] : null;
return new Solarium_Result_Select_Facet_Range($data['counts'], $before, $after, $between);
$offset = 0;
$counts = array();
while(isset($data['counts'][$offset]) && isset($data['counts'][$offset+1])) {
$counts[$data['counts'][$offset]] = $data['counts'][$offset+1];
$offset += 2;
}
return new Solarium_Result_Select_Facet_Range($counts, $before, $after, $between);
}
}
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse select component Highlighting result from the data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Select_Component_Spellcheck
{
/**
* Parse result data into result objects
*
* @param Solarium_Query_Select $query
* @param Solarium_Query_Select_Component_Spellcheck $spellcheck
* @param array $data
* @return Solarium_Result_Select_Spellcheck|null
*/
public function parse($query, $spellcheck, $data)
{
$results = array();
if (
isset($data['spellcheck']['suggestions']) &&
is_array($data['spellcheck']['suggestions']) &&
count($data['spellcheck']['suggestions']) > 0
) {
$spellcheckResults = $data['spellcheck']['suggestions'];
$suggestions = array();
$correctlySpelled = null;
$collation = null;
$index = 0;
while (isset($spellcheckResults[$index]) && isset($spellcheckResults[$index+1])) {
$key = $spellcheckResults[$index];
$value = $spellcheckResults[$index+1];
switch ($key) {
case 'correctlySpelled':
$correctlySpelled = $value;
break;
case 'collation':
$collation = $this->_parseCollation($value);
break;
default:
$suggestions[] = $this->_parseSuggestion($key, $value);
}
$index +=2;
}
return new Solarium_Result_Select_Spellcheck($suggestions, $collation, $correctlySpelled);
} else {
return null;
}
}
/**
* Parse collation data into a result object
*
* @param array $values
* @return Solarium_Result_Select_Spellcheck_Collation
*/
protected function _parseCollation($values)
{
if (is_string($values)) {
return new Solarium_Result_Select_Spellcheck_Collation($values, null, array());
} else {
$query = null;
$hits = null;
$correctionResult = null;
$index = 0;
while (isset($values[$index]) && isset($values[$index+1])) {
$key = $values[$index];
$value = $values[$index+1];
switch ($key) {
case 'collationQuery':
$query = $value;
break;
case 'hits':
$hits = $value;
break;
case 'misspellingsAndCorrections':
$correctionResult = $value;
break;
}
$index +=2;
}
$corrections = array();
if ($correctionResult !== null) {
$index = 0;
while (isset($correctionResult[$index]) && isset($correctionResult[$index+1])) {
$input = $correctionResult[$index];
$correction = $correctionResult[$index+1];
$corrections[$input] = $correction;
$index += 2;
}
}
return new Solarium_Result_Select_Spellcheck_Collation($query, $hits, $corrections);
}
}
/**
* Parse suggestion data into a result object
*
* @param string $key
* @param array $value
* @return Solarium_Result_Select_Spellcheck_Suggestion
*/
protected function _parseSuggestion($key, $value)
{
$numFound = (isset($value['numFound'])) ? $value['numFound'] : null;
$startOffset = (isset($value['startOffset'])) ? $value['startOffset'] : null;
$endOffset = (isset($value['endOffset'])) ? $value['endOffset'] : null;
$originalFrequency = (isset($value['origFreq'])) ? $value['origFreq'] : null;
if (is_string($value['suggestion'][0])) {
$word = $value['suggestion'][0];
$frequency = null;
} else {
$word = $value['suggestion'][0]['word'];
$frequency = $value['suggestion'][0]['freq'];
}
return new Solarium_Result_Select_Spellcheck_Suggestion(
$numFound, $startOffset, $endOffset, $originalFrequency, $word, $frequency
);
}
}
\ No newline at end of file
......@@ -169,7 +169,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
/**
* preCreateQuery hook
*
* @param string $query
* @param string $type
* @param mixed $options
* @return void|Solarium_Query
*/
......@@ -180,7 +180,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
/**
* postCreateQuery hook
*
* @param string $query
* @param string $type
* @param mixed $options
* @param Solarium_Query
* @return void
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Base class for Analysis queries
*
* @package Solarium
* @subpackage Query
*/
abstract class Solarium_Query_Analysis extends Solarium_Query
{
/**
* Set the query string
*
* When present, the text that will be analyzed. The analysis will mimic the query-time analysis.
*
* @param string $query
* @param array $bind Optional bind values for placeholders in the query string
* @return Solarium_Query_Analysis Provides fluent interface
*/
public function setQuery($query, $bind = null)
{
if (!is_null($bind)) {
$query = $this->getHelper()->assemble($query, $bind);
}
return $this->_setOption('query', trim($query));
}
/**
* Get the query string
*
* @return string
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set the showmatch option
*
* @param boolean $show
* @return Solarium_Query_Analysis Provides fluent interface
*/
public function setShowMatch($show)
{
return $this->_setOption('showmatch', $show);
}
/**
* Get the showmatch option
*
* @return mixed
*/
public function getShowMatch()
{
return $this->getOption('showmatch');
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Analysis document query
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Analysis_Document extends Solarium_Query_Analysis
{
/**
* Documents to analyze
*
* @var array
*/
protected $_documents = array();
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'analysis/document',
'resultclass' => 'Solarium_Result_Analysis_Document',
);
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_ANALYSIS_DOCUMENT;
}
/**
* Add a single document
*
* @param object $document
* @return Solarium_Query_Analysis_Document Provides fluent interface
*/
public function addDocument($document)
{
$this->_documents[] = $document;
return $this;
}
/**
* Add multiple documents
*
* @param array $documents
* @return Solarium_Query_Analysis_Document fluent interface
*/
public function addDocuments($documents)
{
$this->_documents = array_merge($this->_documents, $documents);
return $this;
}
/**
* Get all documents
*
* @return array
*/
public function getDocuments()
{
return $this->_documents;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Analysis document query
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Analysis_Field extends Solarium_Query_Analysis
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'analysis/field',
'resultclass' => 'Solarium_Result_Analysis_Field',
);
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_ANALYSIS_FIELD;
}
/**
* Set the field value option
*
* The text that will be analyzed. The analysis will mimic the index-time analysis.
*
* @param string $value
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldValue($value)
{
return $this->_setOption('fieldvalue', $value);
}
/**
* Get the field value option
*
* @return string
*/
public function getFieldValue()
{
return $this->getOption('fieldvalue');
}
/**
* Set the field type option
*
* When present, the text will be analyzed based on the specified type
*
* @param string $type
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldType($type)
{
return $this->_setOption('fieldtype', $type);
}
/**
* Get the fieldtype option
*
* @return string
*/
public function getFieldType()
{
return $this->getOption('fieldtype');
}
/**
* Set the field name option
*
* When present, the text will be analyzed based on the type of this field name
*
* @param string $name
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldName($name)
{
return $this->_setOption('fieldname', $name);
}
/**
* Get the fieldname option
*
* @return string
*/
public function getFieldName()
{
return $this->getOption('fieldname');
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -50,20 +50,50 @@ class Solarium_Query_Select extends Solarium_Query
{
/**
* Solr sort modes
* Solr sort mode descending
*/
const SORT_DESC = 'desc';
/**
* Solr sort mode ascending
*/
const SORT_ASC = 'asc';
/**
* Query components
* Query component facetset
*/
const COMPONENT_FACETSET = 'facetset';
/**
* Query component dismax
*/
const COMPONENT_DISMAX = 'dismax';
/**
* Query component morelikethis
*/
const COMPONENT_MORELIKETHIS = 'morelikethis';
/**
* Query component highlighting
*/
const COMPONENT_HIGHLIGHTING = 'highlighting';
/**
* Query component spellcheck
*/
const COMPONENT_SPELLCHECK = 'spellcheck';
/**
* Query component grouping
*/
const COMPONENT_GROUPING = 'grouping';
/**
* Query component distributed search
*/
const COMPONENT_DISTRIBUTEDSEARCH = 'distributedsearch';
/**
* Get type for this query
*
......@@ -120,6 +150,16 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_Grouping',
'responseparser' => 'Solarium_Client_ResponseParser_Select_Component_Grouping',
),
self::COMPONENT_SPELLCHECK => array(
'component' => 'Solarium_Query_Select_Component_Spellcheck',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_Spellcheck',
'responseparser' => 'Solarium_Client_ResponseParser_Select_Component_Spellcheck',
),
self::COMPONENT_DISTRIBUTEDSEARCH => array(
'component' => 'Solarium_Query_Select_Component_DistributedSearch',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Select_Component_DistributedSearch',
'responseparser' => null,
),
);
/**
......@@ -476,12 +516,30 @@ class Solarium_Query_Select extends Solarium_Query
/**
* Create a filterquery instance
*
* If you supply a string as the first arguments ($options) it will be used as the key for the filterquery
* and it will be added to this query.
* If you supply an options array/object that contains a key the filterquery will also be added to the query.
*
* When no key is supplied the filterquery cannot be added, in that case you will need to add it manually
* after setting the key, by using the addFilterQuery method.
*
* @param mixed $options
* @return Solarium_Query_Select_FilterQuery
*/
public function createFilterQuery($options = null)
{
return new Solarium_Query_Select_FilterQuery($options);
if (is_string($options)) {
$fq = new Solarium_Query_Select_FilterQuery;
$fq->setKey($options);
} else {
$fq = new Solarium_Query_Select_FilterQuery($options);
}
if ($fq->getKey() !== null) {
$this->addFilterQuery($fq);
}
return $fq;
}
/**
......@@ -506,11 +564,16 @@ class Solarium_Query_Select extends Solarium_Query
}
if (array_key_exists($key, $this->_filterQueries)) {
throw new Solarium_Exception('A filterquery must have a unique key'
. ' value within a query');
if ($this->_filterQueries[$key] === $filterQuery) {
//double add calls for the same FQ are ignored
//@todo add trigger_error with a notice?
} else {
throw new Solarium_Exception('A filterquery must have a unique key value within a query');
}
} else {
$this->_filterQueries[$key] = $filterQuery;
}
return $this;
}
......@@ -561,15 +624,21 @@ class Solarium_Query_Select extends Solarium_Query
}
/**
* Remove a single filterquery by key
* Remove a single filterquery
*
* @param string $key
* You can remove a filterquery by passing it's key, or by passing the filterquery instance
*
* @param string|Solarium_Query_Select_FilterQuery $filterQuery
* @return Solarium_Query_Select Provides fluent interface
*/
public function removeFilterQuery($key)
public function removeFilterQuery($filterQuery)
{
if (isset($this->_filterQueries[$key])) {
unset($this->_filterQueries[$key]);
if (is_object($filterQuery)) {
$filterQuery = $filterQuery->getKey();
}
if (isset($this->_filterQueries[$filterQuery])) {
unset($this->_filterQueries[$filterQuery]);
}
return $this;
......@@ -688,13 +757,24 @@ class Solarium_Query_Select extends Solarium_Query
/**
* Remove a component instance
*
* @param string $key
* You can remove a component by passing it's key or the component instance
*
* @param string|Solarium_Query_Select_Component $component
* @return Solarium_Query_Select Provides fluent interface
*/
public function removeComponent($key)
public function removeComponent($component)
{
if (isset($this->_components[$key])) {
if (is_object($component)) {
foreach ($this->_components as $key => $instance) {
if ($instance === $component) {
unset($this->_components[$key]);
break;
}
}
} else {
if (isset($this->_components[$component])) {
unset($this->_components[$component]);
}
}
return $this;
}
......@@ -773,4 +853,28 @@ class Solarium_Query_Select extends Solarium_Query
return $this->getComponent(Solarium_Query_Select::COMPONENT_GROUPING, true);
}
/**
* Get a spellcheck component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_Spellcheck
*/
public function getSpellcheck()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_SPELLCHECK, true);
}
/**
* Get a DistributedSearch component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_DistributedSearch
*/
public function getDistributedSearch()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_DISTRIBUTEDSEARCH, true);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Distributed Search (sharding) component
*
* @link http://wiki.apache.org/solr/DistributedSearch
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_DistributedSearch extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = Solarium_Query_Select::COMPONENT_DISTRIBUTEDSEARCH;
/**
* Request to be distributed across all shards in the list
*
* @var array
*/
protected $_shards = array();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'shards':
$this->setShards($value);
break;
}
}
}
/**
* Add a shard
*
* @param string $key unique string
* @param string $shard The syntax is host:port/base_url
* @return Solarium_Query_Select Provides fluent interface
* @link http://wiki.apache.org/solr/DistributedSearch
*/
public function addShard($key, $shard)
{
$this->_shards[$key] = $shard;
return $this;
}
/**
* Add multiple shards
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createSelect();
* $distributedSearch = $query->getDistributedSearch();
* $distributedSearch->addShards(array(
* 'core0' => 'localhost:8983/solr/core0',
* 'core1' => 'localhost:8983/solr/core1'
* ));
* $result = $client->select($query);
* </code>
* @param array $shards
* @return Solarium_Query_Select Provides fluent interface
*/
public function addShards(array $shards)
{
foreach ($shards as $key => $shard) {
$this->addShard($key, $shard);
}
return $this;
}
/**
* Remove a shard
*
* @param string $key
* @return Solarium_Query_Select Provides fluent interface
*/
public function removeShard($key)
{
if (isset($this->_shards[$key])) {
unset($this->_shards[$key]);
}
return $this;
}
/**
* Remove all shards
*
* @return Solarium_Query_Select Provides fluent interface
*/
public function clearShards()
{
$this->_shards = array();
return $this;
}
/**
* Set multiple shards
*
* This overwrites any existing shards
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createSelect();
* $distributedSearch = $query->getDistributedSearch();
* $distributedSearch->setShards(array(
* 'core0' => 'localhost:8983/solr/core0',
* 'core1' => 'localhost:8983/solr/core1'
* ));
* $result = $client->select($query);
* </code>
*
* @param array $shards Associative array of shards
* @return Solarium_Query_Select Provides fluent interface
*/
public function setShards(array $shards)
{
$this->clearShards();
$this->addShards($shards);
return $this;
}
/**
* Get a list of the shards
*
* @return array
*/
public function getShards()
{
return $this->_shards;
}
/**
* A sharded request will go to the standard request handler
* (not necessarily the original); this can be overridden via shards.qt
*
* @param string
* @return Solarium_Query_Select Provides fluent interface
*/
public function setShardRequestHandler($handler)
{
$this->_setOption('shardhandler', $handler);
return $this;
}
/**
* Get a shard request handler (shards.qt)
*
* @param string
* @return Solarium_Query_Select Provides fluent interface
*/
public function getShardRequestHandler()
{
return $this->getOption('shardhandler');
}
}
\ No newline at end of file
......@@ -110,9 +110,9 @@ abstract class Solarium_Query_Select_Component_Facet extends Solarium_Configurab
* @param string $tag
* @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/
public function addExclude($exclude)
public function addExclude($tag)
{
$this->_excludes[$exclude] = true;
$this->_excludes[$tag] = true;
return $this;
}
......
......@@ -48,15 +48,23 @@ class Solarium_Query_Select_Component_Facet_Field extends Solarium_Query_Select_
{
/**
* Facet sort types
* Facet sort type index
*/
const SORT_INDEX = 'index';
/**
* Facet sort type count
*/
const SORT_COUNT = 'count';
/**
* Facet methods
* Facet method enum
*/
const METHOD_ENUM = 'enum';
/**
* Facet method fc
*/
const METHOD_FC = 'fc';
/**
......@@ -81,7 +89,7 @@ class Solarium_Query_Select_Component_Facet_Field extends Solarium_Query_Select_
/**
* Set the field name
*
* @param string $query
* @param string $field
* @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/
public function setField($field)
......@@ -188,7 +196,7 @@ class Solarium_Query_Select_Component_Facet_Field extends Solarium_Query_Select_
/**
* Set the facet mincount
*
* @param int $mincount
* @param int $minCount
* @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface
*/
public function setMinCount($minCount)
......
......@@ -191,15 +191,21 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
}
/**
* Remove a single facetquery by key
* Remove a single facetquery
*
* @param string $key
* You can remove a facetquery by passing it's key or the facetquery instance
*
* @param string|Solarium_Query_Select_Component_Facet_Query $query
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public function removeQuery($key)
public function removeQuery($query)
{
if (isset($this->_facetQueries[$key])) {
unset($this->_facetQueries[$key]);
if (is_object($query)) {
$query = $query->getKey();
}
if (isset($this->_facetQueries[$query])) {
unset($this->_facetQueries[$query]);
}
return $this;
......@@ -242,13 +248,13 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
* @param string $tag
* @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/
public function addExclude($exclude)
public function addExclude($tag)
{
foreach ($this->_facetQueries AS $facetQuery) {
$facetQuery->addExclude($exclude);
$facetQuery->addExclude($tag);
}
return parent::addExclude($exclude);
return parent::addExclude($tag);
}
/**
......
......@@ -48,21 +48,53 @@ class Solarium_Query_Select_Component_Facet_Range extends Solarium_Query_Select_
{
/**
* Values for the 'other' option
* Value for the 'other' option
*/
const OTHER_BEFORE = 'before';
/**
* Value for the 'other' option
*/
const OTHER_AFTER = 'after';
/**
* Value for the 'other' option
*/
const OTHER_BETWEEN = 'between';
/**
* Value for the 'other' option
*/
const OTHER_ALL = 'all';
/**
* Value for the 'other' option
*/
const OTHER_NONE = 'none';
/**
* Values for the 'include' option
* Value for the 'include' option
*/
const INCLUDE_LOWER = 'lower';
/**
* Value for the 'include' option
*/
const INCLUDE_UPPER = 'upper';
/**
* Value for the 'include' option
*/
const INCLUDE_EDGE = 'edge';
/**
* Value for the 'include' option
*/
const INCLUDE_OUTER = 'outer';
/**
* Value for the 'include' option
*/
const INCLUDE_ALL = 'all';
/**
......@@ -102,7 +134,7 @@ class Solarium_Query_Select_Component_Facet_Range extends Solarium_Query_Select_
/**
* Set the field name
*
* @param string $query
* @param string $field
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public function setField($field)
......
......@@ -48,11 +48,23 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
{
/**
* Facet type keys
* Facet type field
*/
const FACET_FIELD = 'field';
/**
* Facet type query
*/
const FACET_QUERY = 'query';
/**
* Facet type multiquery
*/
const FACET_MULTIQUERY = 'multiquery';
/**
* Facet type range
*/
const FACET_RANGE = 'range';
/**
......@@ -191,7 +203,7 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
*
* This is a global value for all facets in this facetset
*
* @param int $mincount
* @param int $minCount
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public function setMinCount($minCount)
......@@ -245,7 +257,7 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
public function addFacet($facet)
{
if (is_array($facet)) {
$facet = $this->createFacet($facet['type'], $facet);
$facet = $this->createFacet($facet['type'], $facet, false);
}
$key = $facet->getKey();
......@@ -255,11 +267,16 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
}
if (array_key_exists($key, $this->_facets)) {
throw new Solarium_Exception('A facet must have a unique key value'
. ' within a query');
if ($this->_facets[$key] === $facet) {
//double add calls for the same facet are ignored
//@todo add trigger_error with a notice?
} else {
throw new Solarium_Exception('A facet must have a unique key value within a query');
}
} else {
$this->_facets[$key] = $facet;
}
return $this;
}
......@@ -310,15 +327,21 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
}
/**
* Remove a single facet by key
* Remove a single facet
*
* @param string $key
* You can remove a facet by passing it's key or the facet instance
*
* @param string|Solarium_Query_Select_Component_Facet $facet
* @return Solarium_Query Provides fluent interface
*/
public function removeFacet($key)
public function removeFacet($facet)
{
if (isset($this->_facets[$key])) {
unset($this->_facets[$key]);
if (is_object($facet)) {
$facet = $facet->getKey();
}
if (isset($this->_facets[$facet])) {
unset($this->_facets[$facet]);
}
return $this;
......@@ -349,11 +372,21 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
}
/**
* Create a facet instance
*
* If you supply a string as the first arguments ($options) it will be used as the key for the facet
* and it will be added to this query.
* If you supply an options array/object that contains a key the facet will also be added to the query.
*
* When no key is supplied the facet cannot be added, in that case you will need to add it manually
* after setting the key, by using the addFacet method.
*
* @param string $type
* @param array|object|null $options
* @param boolean $add
* @return Solarium_Query_Select_Component_Facet
*/
public function createFacet($type, $options = null)
public function createFacet($type, $options = null, $add = true)
{
$type = strtolower($type);
......@@ -362,7 +395,19 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
}
$class = $this->_facetTypes[$type];
return new $class($options);
if (is_string($options)) {
$facet = new $class;
$facet->setKey($options);
} else {
$facet = new $class($options);
}
if ($add && $facet->getKey() !== null) {
$this->addFacet($facet);
}
return $facet;
}
/**
......
......@@ -53,9 +53,13 @@ class Solarium_Query_Select_Component_Grouping extends Solarium_Query_Select_Com
{
/**
* Values for format option
* Value for format grouped
*/
const FORMAT_GROUPED = 'grouped';
/**
* Value for format simple
*/
const FORMAT_SIMPLE = 'simple';
/**
......
......@@ -47,9 +47,13 @@
class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select_Component
{
/**
* Values for fragmenter option
* Value for fragmenter option gap
*/
const FRAGMENTER_GAP = 'gap';
/**
* Value for fragmenter option regex
*/
const FRAGMENTER_REGEX = 'regex';
/**
......@@ -60,28 +64,151 @@ class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select
protected $_type = Solarium_Query_Select::COMPONENT_HIGHLIGHTING;
/**
* Set fields option
* Array of fields for highlighting
*
* Fields to generate highlighted snippets for
* @var array
*/
protected $_fields = array();
/**
* Initialize options
*
* The field option needs setup work
*
* Separate multiple fields with commas.
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'field':
$this->addFields($value);
break;
}
}
}
/**
* Get a field options object
*
* @param string $fields
* @param string $name
* @param boolean $autocreate
* @return Solarium_Query_Select_Component_Highlighting_Field
*/
public function getField($name, $autocreate = true)
{
if (isset($this->_fields[$name])) {
return $this->_fields[$name];
} else if ($autocreate) {
$this->addField($name);
return $this->_fields[$name];
} else {
return null;
}
}
/**
* Add a field for highlighting
*
* @param string|array|Solarium_Query_Select_Component_Highlighting_Field $field
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setFields($fields)
public function addField($field)
{
return $this->_setOption('fields', $fields);
// autocreate object for string input
if (is_string($field)) {
$field = new Solarium_Query_Select_Component_Highlighting_Field(array('name' => $field));
} else if (is_array($field)) {
$field = new Solarium_Query_Select_Component_Highlighting_Field($field);
}
// validate field
if ($field->getName() === null) {
throw new Solarium_Exception('To add a highlighting field it needs to have at least a "name" setting');
}
$this->_fields[$field->getName()] = $field;
return $this;
}
/**
* Get fields option
* Add multiple fields for highlighting
*
* @return string|null
* @param string|array $fields can be an array of object instances or a string with comma
* separated fieldnames
*
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function addFields($fields)
{
if (is_string($fields)) {
$fields = explode(',', $fields);
$fields = array_map('trim', $fields);
}
foreach ($fields AS $key => $field) {
// in case of a config array without key: add key to config
if (is_array($field) && !isset($field['name'])) {
$field['name'] = $key;
}
$this->addField($field);
}
return $this;
}
/**
* Remove a highlighting field
*
* @param string $field
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function removeField($field)
{
if (isset($this->_fields[$field])) {
unset($this->_fields[$field]);
}
return $this;
}
/**
* Remove all fields
*
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function clearFields()
{
$this->_fields = array();
return $this;
}
/**
* Get the list of fields
*
* @return array
*/
public function getFields()
{
return $this->getOption('fields');
return $this->_fields;
}
/**
* Set multiple fields
*
* This overwrites any existing fields
*
* @param array $fields
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setFields($fields)
{
$this->clearFields();
$this->addFields($fields);
return $this;
}
/**
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Highlighting per-field settings
*
* @link http://wiki.apache.org/solr/HighlightingParameters
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Highlighting_Field extends Solarium_Query_Select_Component
{
/**
* Value for fragmenter option gap
*/
const FRAGMENTER_GAP = 'gap';
/**
* Value for fragmenter option regex
*/
const FRAGMENTER_REGEX = 'regex';
/**
* Get name option
*
* @return string|null
*/
public function getName()
{
return $this->getOption('name');
}
/**
* Set name option
*
* @param string $name
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setName($name)
{
return $this->_setOption('name', $name);
}
/**
* Set snippets option
*
* Maximum number of snippets per field
*
* @param int $maximum
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setSnippets($maximum)
{
return $this->_setOption('snippets', $maximum);
}
/**
* Get snippets option
*
* @return int|null
*/
public function getSnippets()
{
return $this->getOption('snippets');
}
/**
* Set fragsize option
*
* The size, in characters, of fragments to consider for highlighting
*
* @param int $size
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setFragSize($size)
{
return $this->_setOption('fragsize', $size);
}
/**
* Get fragsize option
*
* @return int|null
*/
public function getFragSize()
{
return $this->getOption('fragsize');
}
/**
* Set mergeContiguous option
*
* Collapse contiguous fragments into a single fragment
*
* @param boolean $merge
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setMergeContiguous($merge)
{
return $this->_setOption('mergecontiguous', $merge);
}
/**
* Get mergeContiguous option
*
* @return boolean|null
*/
public function getMergeContiguous()
{
return $this->getOption('mergecontiguous');
}
/**
* Set alternatefield option
*
* @param string $field
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setAlternateField($field)
{
return $this->_setOption('alternatefield', $field);
}
/**
* Get alternatefield option
*
* @return string|null
*/
public function getAlternateField()
{
return $this->getOption('alternatefield');
}
/**
* Set formatter option
*
* @param string $formatter
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setFormatter($formatter = 'simple')
{
return $this->_setOption('formatter', $formatter);
}
/**
* Get formatter option
*
* @return string|null
*/
public function getFormatter()
{
return $this->getOption('formatter');
}
/**
* Set simple prefix option
*
* Solr option h1.simple.pre
*
* @param string $prefix
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setSimplePrefix($prefix)
{
return $this->_setOption('simpleprefix', $prefix);
}
/**
* Get simple prefix option
*
* Solr option hl.simple.pre
*
* @return string|null
*/
public function getSimplePrefix()
{
return $this->getOption('simpleprefix');
}
/**
* Set simple postfix option
*
* Solr option h1.simple.post
*
* @param string $postfix
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setSimplePostfix($postfix)
{
return $this->_setOption('simplepostfix', $postfix);
}
/**
* Get simple postfix option
*
* Solr option hl.simple.post
*
* @return string|null
*/
public function getSimplePostfix()
{
return $this->getOption('simplepostfix');
}
/**
* Set fragmenter option
*
* Use one of the constants as value.
*
* @param string $fragmenter
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setFragmenter($fragmenter)
{
return $this->_setOption('fragmenter', $fragmenter);
}
/**
* Get fragmenter option
*
* @return string|null
*/
public function getFragmenter()
{
return $this->getOption('fragmenter');
}
/**
* Set useFastVectorHighlighter option
*
* @param boolean $use
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setUseFastVectorHighlighter($use)
{
return $this->_setOption('usefastvectorhighlighter', $use);
}
/**
* Get useFastVectorHighlighter option
*
* @return boolean|null
*/
public function getUseFastVectorHighlighter()
{
return $this->getOption('usefastvectorhighlighter');
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Spellcheck component
*
* @link http://wiki.apache.org/solr/SpellCheckComponent
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Select_Component_Spellcheck extends Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected $_type = Solarium_Query_Select::COMPONENT_SPELLCHECK;
/**
* Set query option
*
* Query to spellcheck
*
* @param string $query
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setQuery($query)
{
return $this->_setOption('query', $query);
}
/**
* Get query option
*
* @return string|null
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set build option
*
* Build the spellcheck?
*
* @param boolean $build
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setBuild($build)
{
return $this->_setOption('build', $build);
}
/**
* Get build option
*
* @return boolean|null
*/
public function getBuild()
{
return $this->getOption('build');
}
/**
* Set reload option
*
* Reload the dictionary?
*
* @param boolean $reload
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setReload($reload)
{
return $this->_setOption('reload', $reload);
}
/**
* Get fragsize option
*
* @return boolean|null
*/
public function getReload()
{
return $this->getOption('reload');
}
/**
* Set dictionary option
*
* The name of the dictionary to use
*
* @param string $dictionary
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setDictionary($dictionary)
{
return $this->_setOption('dictionary', $dictionary);
}
/**
* Get dictionary option
*
* @return string|null
*/
public function getDictionary()
{
return $this->getOption('dictionary');
}
/**
* Set count option
*
* The maximum number of suggestions to return
*
* @param int $count
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setCount($count)
{
return $this->_setOption('count', $count);
}
/**
* Get count option
*
* @return int|null
*/
public function getCount()
{
return $this->getOption('count');
}
/**
* Set onlyMorePopular option
*
* Only return suggestions that result in more hits for the query than the existing query
*
* @param boolean $onlyMorePopular
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setOnlyMorePopular($onlyMorePopular)
{
return $this->_setOption('onlymorepopular', $onlyMorePopular);
}
/**
* Get onlyMorePopular option
*
* @return boolean|null
*/
public function getOnlyMorePopular()
{
return $this->getOption('onlymorepopular');
}
/**
* Set extendedResults option
*
* @param boolean $extendedResults
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setExtendedResults($extendedResults)
{
return $this->_setOption('extendedresults', $extendedResults);
}
/**
* Get extendedResults option
*
* @return boolean|null
*/
public function getExtendedResults()
{
return $this->getOption('extendedresults');
}
/**
* Set collate option
*
* @param boolean $collate
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setCollate($collate)
{
return $this->_setOption('collate', $collate);
}
/**
* Get collate option
*
* @return boolean|null
*/
public function getCollate()
{
return $this->getOption('collate');
}
/**
* Set maxCollations option
*
* @param int $maxCollations
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setMaxCollations($maxCollations)
{
return $this->_setOption('maxcollations', $maxCollations);
}
/**
* Get maxCollations option
*
* @return int|null
*/
public function getMaxCollations()
{
return $this->getOption('maxcollations');
}
/**
* Set maxCollationTries option
*
* @param string $maxCollationTries
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setMaxCollationTries($maxCollationTries)
{
return $this->_setOption('maxcollationtries', $maxCollationTries);
}
/**
* Get maxCollationTries option
*
* @return string|null
*/
public function getMaxCollationTries()
{
return $this->getOption('maxcollationtries');
}
/**
* Set maxCollationEvaluations option
*
* @param int $maxCollationEvaluations
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setMaxCollationEvaluations($maxCollationEvaluations)
{
return $this->_setOption('maxcollationevaluations', $maxCollationEvaluations);
}
/**
* Get maxCollationEvaluations option
*
* @return int|null
*/
public function getMaxCollationEvaluations()
{
return $this->getOption('maxcollationevaluations');
}
/**
* Set collateExtendedResults option
*
* @param string $collateExtendedResults
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setCollateExtendedResults($collateExtendedResults)
{
return $this->_setOption('collateextendedresults', $collateExtendedResults);
}
/**
* Get collateExtendedResults option
*
* @return string|null
*/
public function getCollateExtendedResults()
{
return $this->getOption('collateextendedresults');
}
/**
* Set accuracy option
*
* @param float $accuracy
* @return Solarium_Query_Select_Component_Spellcheck Provides fluent interface
*/
public function setAccuracy($accuracy)
{
return $this->_setOption('accuracy', $accuracy);
}
/**
* Get accuracy option
*
* @return float|null
*/
public function getAccuracy()
{
return $this->getOption('accuracy');
}
}
\ No newline at end of file
......@@ -50,12 +50,28 @@ class Solarium_Query_Update extends Solarium_Query
{
/**
* Update command type names
* Update command add
*/
const COMMAND_ADD = 'add';
/**
* Update command delete
*/
const COMMAND_DELETE = 'delete';
/**
* Update command commit
*/
const COMMAND_COMMIT = 'commit';
/**
* Update command rollback
*/
const COMMAND_ROLLBACK = 'rollback';
/**
* Update command optimize
*/
const COMMAND_OPTIMIZE = 'optimize';
/**
......@@ -181,16 +197,28 @@ class Solarium_Query_Update extends Solarium_Query
}
/**
* Remove a command by key
* Remove a command
*
* @param string $key
* You can remove a command by passing it's key or by passing the command instance
*
* @param string|Solarium_Query_Update_Command $command
* @return Solarium_Query_Update Provides fluent interface
*/
public function remove($key)
public function remove($command)
{
if (isset($this->_commands[$key])) {
if (is_object($command)) {
foreach ($this->_commands as $key => $instance) {
if ($instance === $command) {
unset($this->_commands[$key]);
break;
}
}
} else {
if (isset($this->_commands[$command])) {
unset($this->_commands[$command]);
}
}
return $this;
}
......@@ -230,7 +258,6 @@ class Solarium_Query_Update extends Solarium_Query
* If you need more control, like choosing a key for the command you need to
* create you own command instance and use the add method.
*
* @param string $key
* @param array $queries
* @return Solarium_Query_Update Provides fluent interface
*/
......@@ -265,7 +292,7 @@ class Solarium_Query_Update extends Solarium_Query
* If you need more control, like choosing a key for the command you need to
* create you own command instance and use the add method.
*
* @param array $id
* @param array $ids
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDeleteByIds($ids)
......@@ -287,10 +314,10 @@ class Solarium_Query_Update extends Solarium_Query
* @param int $commitWithin
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDocument($document, $override = null,
public function addDocument($document, $overwrite = null,
$commitWithin = null)
{
return $this->addDocuments(array($document), $override, $commitWithin);
return $this->addDocuments(array($document), $overwrite, $commitWithin);
}
/**
......
......@@ -114,7 +114,7 @@ class Solarium_Query_Update_Command_Delete extends Solarium_Query_Update_Command
/**
* Add multiple IDs to the delete command
*
* @param array $id
* @param array $ids
* @return Solarium_Query_Update_Command_Delete Provides fluent interface
*/
public function addIds($ids)
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis document query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Document extends Solarium_Result_QueryType
implements IteratorAggregate, Countable
{
/**
* Document instances array
*
* @var array
*/
protected $_items;
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/**
* Get all documents
*
* @return array
*/
public function getDocuments()
{
$this->_parseResponse();
return $this->_items;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_items);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_items);
}
/**
* Get a document by uniquekey value
*
* @param string $key
* @return Solarium_Result_Analysis_List|null
*/
public function getDocument($key)
{
$this->_parseResponse();
if (isset($this->_items[$key])) {
return $this->_items[$key];
} else {
return null;
}
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis field query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Field extends Solarium_Result_QueryType
implements IteratorAggregate, Countable
{
/**
* List instances array
*
* @var array
*/
protected $_items;
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/**
* Get all lists
*
* @return array
*/
public function getLists()
{
$this->_parseResponse();
return $this->_items;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_items);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_items);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis item
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Item
{
/**
* @var string
*/
protected $_text;
/**
* @var string
*/
protected $_rawText;
/**
* @var int
*/
protected $_start;
/**
* @var int
*/
protected $_end;
/**
* @var int
*/
protected $_position;
/**
* @var array
*/
protected $_positionHistory;
/**
* @var string
*/
protected $_type;
/**
* @var boolean
*/
protected $_match = false;
/**
* Constructor
*
* @param array $analysis
*/
public function __construct($analysis)
{
$this->_text = $analysis['text'];
$this->_start = $analysis['start'];
$this->_end = $analysis['end'];
$this->_position = $analysis['position'];
$this->_positionHistory = $analysis['positionHistory'];
$this->_type = $analysis['type'];
if (isset($analysis['raw_text'])) {
$this->_rawText = $analysis['raw_text'];
}
if (isset($analysis['match'])) {
$this->_match = $analysis['match'];
}
}
/**
* Get text value
*
* @return string
*/
public function getText()
{
return $this->_text;
}
/**
* Get raw text value
*
* This values is not available in all cases
*
* @return string
*/
public function getRawText()
{
return $this->_rawText;
}
/**
* Get start value
*
* @return int
*/
public function getStart()
{
return $this->_start;
}
/**
* Get end value
*
* @return int
*/
public function getEnd()
{
return $this->_end;
}
/**
* Get postion value
*
* @return int
*/
public function getPosition()
{
return $this->_position;
}
/**
* Get position history value
*
* @return array
*/
public function getPositionHistory()
{
return $this->_positionHistory;
}
/**
* Get type value
*
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* Get match value
*
* @return boolean
*/
public function getMatch()
{
return $this->_match;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -45,7 +45,7 @@
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Ping
class Solarium_Result_Ping extends Solarium_Result
{
/**
......
......@@ -257,4 +257,16 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_FACETSET);
}
/**
* Get spellcheck component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Spellcheck
*/
public function getSpellcheck()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_SPELLCHECK);
}
}
\ No newline at end of file
......@@ -58,7 +58,7 @@ class Solarium_Result_Select_Facet_Query
/**
* Constructor
*
* @param array $values
* @param mixed $value
* @return void
*/
public function __construct($value)
......
......@@ -77,6 +77,9 @@ class Solarium_Result_Select_Facet_Range extends Solarium_Result_Select_Facet_Fi
* Constructor
*
* @param array $values
* @param int $before
* @param int $after
* @param int $between
* @return void
*/
public function __construct($values, $before, $after, $between)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment