Source

SolrQueryBuilder / examples / index.php

Full commit
<?php

include('../classes/querystring.php');
include('../classes/field.php');

use Solr\QueryBuilder\Querystring;
use Solr\QueryBuilder\Field;

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

$Query = new Querystring();
$Query->addField(new Field('name', 'Anis uddin Ahmad'));
echo '<b>simple query:</b> '. $Query ."<br />";

$Query->addField(new Field('phone', '+880 173 0053053'), 'phone');
$Query->addField(new Field('active', 'yes'));
echo '<b>Multiple fields query:</b> '. $Query ."<br />";

$Query->removeField('phone');
$Query->setFieldSeparator('OR');
echo '<b>After removing phone and separator set to OR:</b> '. $Query ."<br />";

echo "<br /><br />--------- Solr SubQuery Test ----------- <br />";
$subQuery = new  Querystring();
$subQuery->addField(new Field(null, 'value for default field'));
$subQuery->addField(new Field('item_type', 'anything'));

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

$Query->addSubQuery($subQuery, 'test-sub-query');

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


$subQuery->setFieldSeparator('OR');
$Query->addSubQuery($subQuery, 'test-sub-query');
echo '<b>after changing operator to OR between subQuery fields:</b> '. $Query ."<br />";

echo "<br /><br />--------- Term grouping test ----------- <br />";
$Query->removeSubQuery('test-sub-query');

$langParam = new  Field('lang', 'en');
$langParam->addTerm('bn-BD')
        ->addTerm('fr');

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

echo "<br /><br />--------- Term modifiers test ----------- <br />";
$Query->removeField('lang')
      ->setFieldSeparator('AND');

$category = new  Field('category');
$category->addFuzzyTerm('diapers', 0.6);
$category->addFuzzyTerm('baby-oil', 0.7);
$Query->addField($category, 'category');
echo '<b>Fuzzy Search:</b> '. $Query ."<br />";

$category->addTerm('electronics', Field::OPERATOR_RESTRICTED);
$category->addTerm('boy-cloths', Field::OPERATOR_REQUIRED);
echo '<b>Required/Restricted:</b> '. $Query ."<br />";

$category->addBoostedTerm('baby', 3);
$category->addBoostedTerm('food', 5);
echo '<b>Boost:</b> '. $Query ."<br />";

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

$date = new  Field('date');
$date->setRange(null, 'NOW');

$age = new  Field('age');
$age->setRange(18, 60);

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