Source

SolrQueryBuilder / examples / index.php

Full commit
<?php
include('querystring.php');
include('param.php');

echo "--------- Solr Query Test ----------- <br />";

$Query = new Solr\QueryBuilder\Querystring();
$Query->addQuery(new Solr\QueryBuilder\Param('Emran-Ul-Hadi', 'name'));
echo '<b>simple query:</b> '. $Query ."<br />";

$Query->addQuery(new Solr\QueryBuilder\Param('0179483r50', 'phone'), 'phone');
$Query->addQuery(new Solr\QueryBuilder\Param('yes', 'active'));
echo '<b>miltiple fields query:</b> '. $Query ."<br />";

$Query->removeQuery('phone');
$Query->setOperator('AND', $Query::INTERNAL_SEPARATOR);
echo '<b>after remove phone and internal separator AND:</b> '. $Query ."<br />";

echo "<br /><br />--------- Sub-Solr Query Test ----------- <br />";
$subQuery = new Solr\QueryBuilder\Querystring();
$subQuery->addQuery(new Solr\QueryBuilder\Param('for-default-field'));
$subQuery->addQuery(new Solr\QueryBuilder\Param('diapers', 'item_type'));

echo '<b>sub query:</b> '. $subQuery ."<br />";

$subQuery->setOperator('AND');
$Query->addSubQuery($subQuery);

echo '<b>after adding sub-query:</b> '. $Query ."<br />";

echo "<br /><br />--------- Term grouping test ----------- <br />";
$langParam = new Solr\QueryBuilder\Param('en', 'lang');
$langParam->addTerm('bn-BD')->addTerm('fr');

$Query->addQuery($langParam, 'lang');
echo '<b>Added grouped field:</b> '. $Query ."<br />";

echo "<br /><br />--------- Term modifiers test ----------- <br />";
$category = new Solr\QueryBuilder\Param(null, 'category');
$category->addTerm('diapers', array('modifier' => '~'));
$category->addTerm('baby-oil', array('modifier' => '~', 'factor'=> 0.7));
$Query->addQuery($category, 'category');
echo '<b>Fuzzy Search:</b> '. $Query ."<br />";

$category->addTerm('electronics', array('operator' => '-'));
$category->addTerm('boy-cloths', array('operator' => '+', 'modifier' => '~', 'factor'=> 0.5));
echo '<b>Required/Restricted:</b> '. $Query ."<br />";

$category->addTerm('baby', array('modifier' => '^', 'factor'=> 3));
$category->addTerm('food', array('modifier' => '^', 'factor'=> 5));
echo '<b>Boost:</b> '. $Query ."<br />";

echo "<br /><br />--------- Range Query test ----------- <br />";
$Query->removeQuery('category');

$date = new Solr\QueryBuilder\Param(null, 'date');
$date->addRange(null, 'NOW');

$age = new Solr\QueryBuilder\Param(null, 'age');
$age->addRange(18, 60);

$Query->addQuery($date, 'date');
$Query->addQuery($age, 'age');
echo '<b>Range:</b> '. $Query ."<br />";