PHP code example of mongerinc / search-request
1. Go to this page and download the library: Download mongerinc/search-request library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mongerinc / search-request example snippets
$request = new SearchRequest;
//or
$request = SearchRequest::create();
//or call any method statically
$request = SearchRequest::where('something', true);
$request->select(['field1', 'field2']);
$request->addSelect('field1')->addSelect('field2');
$request->getSelects();
$request->sort('field', 'asc');
$request->addSort('field', 'asc')->addSort('otherField', 'desc');
$sort = $request->getSort();
$databaseQuery->orderBy($sort->getField(), $sort->getDirection());
$request->groupBy('field')->groupBy('anotherField');
$request->groupBy(['field', 'anotherField']);
$request->getGroups();
$request->page(5)->limit(40);
$limit = $request->getLimit();
$page = $request->getPage();
$databaseQuery->take($limit)->skip(($page - 1) * $limit);
$request = $request->unlimited();
if (!$request->isUnlimited())
$databaseQuery->take($request->getLimit())->skip($request->getSkip());
$request->where('someField', '>=', 5.45)
->where('isFun', true); //assumed to be an equality
$request->where{Word}($field, $value)
->orWhere{Word}($field, $value)
->whereNot{Word}($field, $value)
->orWhereNot{Word}($field, $value);
//example:
$request->whereLike($field, $value)
->orWhereLike($field, $value)
->whereNotLike($field, $value)
->orWhereNotLike($field, $value);
foreach ($request->getFilters() as $filter)
{
$databaseQuery->where($filter->getField(), $filter->getOperator(), $filter->getValue());
}
$request->where('foo', true);
$request->where('foo', '>', 5);
$request->getFilterValue('foo'); //true
$request->getFilters()->getFilterValue('foo'); //true
$request->where('goodTimes', true)
->where(function($filterSet)
{
$filterSet->where('profit', '>', 1000)
->orWhere('revenue', '>', 1000000);
});
$request->where('foo', 1)->where('moo', 2)->where('goo', 3);
$request->removeFilters('foo')->removeFilters(['moo', 'goo']);
$facet = $request->facet('someField');
$request->addFacets(['someField', 'someOtherField']);
$request->getFacet('someField');
$request->getFacets();
$facet->isCountSorting(); //bool
$facet->isValueSorting(); //bool
$facet->getSortDirection(); //'asc' or 'desc'
$facet->sortByCount();
$facet->sortByValue();
$facet->setSortDirection('asc');
$facet->getMinimumCount(); //1
$facet->setMinimumCount(5);
$facet->shouldExcludeOwnFilters(); //true
$facet->excludeOwnFilters();
$facet->
$facet->getPage();
$facet->getLimit();
$facet->getSkip();
$facet->page(5)->limit(100);
$facet->nextPage();
[
...
'category' => [
'id' => $product->category_id,
'name' => $product->category_name,
],
...
]
//abstract layer code
$request->where('category.name', 'Foo');
//then later in the repository
$request->substituteField('category.name', 'category_name');
$request->substituteFields(
['category.name' => 'category_name'],
['category.id' => 'category_id'],
);
sql
...WHERE goodTimes = true AND (profit > 1000 OR revenue > 1000000)