Skip to content

Commit

Permalink
Updated examples to use 2.2.0 features and fixed some small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
basdenooijer committed Oct 13, 2011
1 parent 1b7f248 commit d020e83
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 58 deletions.
7 changes: 1 addition & 6 deletions examples/2.1.3-filterquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
$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);
Expand Down
7 changes: 1 addition & 6 deletions examples/2.1.5.1.1-facet-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
$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);
Expand Down
7 changes: 1 addition & 6 deletions examples/2.1.5.1.2-facet-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
$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);
Expand Down
6 changes: 1 addition & 5 deletions examples/2.1.5.1.3-facet-multiquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
$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);

Expand Down
6 changes: 1 addition & 5 deletions examples/2.1.5.1.4-facet-range.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
$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);

Expand Down
3 changes: 1 addition & 2 deletions examples/2.1.5.9-spellcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
$query = $client->createSelect();
$query->setRows(0);

// add distributed search settings
// see http://wiki.apache.org/solr/DistributedSearch#Distributed_Search_Example for setting up two solr instances
// add spellcheck settings
$spellcheck = $query->getSpellcheck();
$spellcheck->setQuery('delll ultrashar');
$spellcheck->setBuild(true);
Expand Down
12 changes: 3 additions & 9 deletions examples/2.1.6-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
$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);
Expand All @@ -38,7 +32,7 @@
{
// 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>';
}

Expand Down
11 changes: 2 additions & 9 deletions examples/4.1-api-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@
$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);
Expand Down
12 changes: 2 additions & 10 deletions examples/4.3-extending-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ protected function _init()

// 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');
}

}
Expand All @@ -36,12 +33,7 @@ protected function _init()
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]');
}

}
Expand Down

0 comments on commit d020e83

Please sign in to comment.