PHP code example of shabushabu / laravel-paradedb-search
1. Go to this page and download the library: Download shabushabu/laravel-paradedb-search 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/ */
shabushabu / laravel-paradedb-search example snippets
use ShabuShabu\ParadeDB\Expressions\JsonB;
Product::query()
->where('id', '@@@', new JsonB([
'fuzzy_term' => [
'field' => 'description',
'value' => 'shoez'
]
]))
->get();
use ShabuShabu\ParadeDB\Expressions\All;
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Boolean;
Product::query()
->where('id', '@@@', new Boolean(
should: new All(),
mustNot: new Term('description', 'shoes')
))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Exists;
use ShabuShabu\ParadeDB\Expressions\Boolean;
Product::query()
->where('id', '@@@', new Boolean(
must: [
new Term('description', 'shoes'),
new Exists('rating')
],
))
->limit(5)
->get();
use ShabuShabu\ParadeDB\Expressions\Blank;
Product::query()
->where('id', '@@@', new Blank())
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Boost;
use ShabuShabu\ParadeDB\Expressions\Boolean;
Product::query()
->where('id', '@@@', new Boolean(
should: [
new Term('description', 'shoes'),
new Boost(new Term('description', 'running'), 2.0)
]
))
->get();
use ShabuShabu\ParadeDB\Expressions\All;
use ShabuShabu\ParadeDB\Expressions\Score;
use ShabuShabu\ParadeDB\Expressions\Boolean;
use ShabuShabu\ParadeDB\Expressions\ConstScore;
Product::query()
->selectWithScore()
->where('id', '@@@', new Boolean(
should: [
new ConstScore(new Term('description', 'shoes'), 1.0),
new Term('description', 'running'),
]
))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Score;
use ShabuShabu\ParadeDB\Expressions\DisjunctionMax;
Product::query()
->select(['*', new Score()])
->where('id', '@@@', new DisjunctionMax([
new Term('description', 'shoes'),
new Term('description', 'running'),
]))
->get();
use ShabuShabu\ParadeDB\TantivyQL\Query;
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Score;
use ShabuShabu\ParadeDB\Expressions\DisjunctionMax;
Product::query()
->select(['*', new Score()])
->where('id', '@@@', DisjunctionMax::query()
->add(Query::string()->where('description', 'shoes'))
->add('description:running')
->tieBreaker(1.2)
)
->get();
use ShabuShabu\ParadeDB\TantivyQL\Query;
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Score;
use ShabuShabu\ParadeDB\Expressions\DisjunctionMax;
Product::query()
->select(['*', new Score()])
->where('id', '@@@', DisjunctionMax::query()
->add(Query::string()->where('description', 'shoes'))
->add('description:running', when: false)
)
->get();
use ShabuShabu\ParadeDB\Expressions\FuzzyTerm;
Product::query()
->where('id', '@@@', new FuzzyTerm('description', 'shoez'))
->get();
use ShabuShabu\ParadeDB\Expressions\FuzzyPhrase;
Product::query()
->where('id', '@@@', new FuzzyPhrase('description', 'ruining shoez'))
->get();
use ShabuShabu\ParadeDB\Expressions\Parse;
Product::query()
->where('id', '@@@', new Parse('description:"running shoes" OR category:footwear'))
->get();
use ShabuShabu\ParadeDB\TantivyQL\Query;
use ShabuShabu\ParadeDB\Expressions\Parse;
Product::query()
->where('id', '@@@', new Parse(
Query::string()
->where('description', 'running shoes')
->orWhere('category', 'footwear')
))
->get();
use ShabuShabu\ParadeDB\Expressions\ParseWithField;
Product::query()
->where('id', '@@@', new ParseWithField(
field: 'description',
query: 'speaker bluetooth',
conjunctionMode: true,
))
->get();
use ShabuShabu\ParadeDB\Expressions\Snippet;
Product::query()
->select(['id', new Snippet('description')])
->where('description', '@@@', 'shoes')
->limit(5)
->get();
use ShabuShabu\ParadeDB\Expressions\Phrase;
Product::query()
->where('id', '@@@', new Phrase(
field: 'description',
phrases: ['sleek', 'shoes'],
slop: 1,
))
->get();
use ShabuShabu\ParadeDB\Expressions\PhrasePrefix;
Product::query()
->where('id', '@@@', new PhrasePrefix('description', ['running', 'sh']))
->get();
use ShabuShabu\ParadeDB\Expressions\Range;
use ShabuShabu\ParadeDB\Expressions\Ranges\Int4;
use ShabuShabu\ParadeDB\Expressions\Ranges\Bounds;
Product::query()
->where('id', '@@@', new Range('rating', new Int4(1, 3, Bounds::
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Boolean;
use ShabuShabu\ParadeDB\Expressions\RangeTerm;
Product::query()
->where('id', '@@@', new Boolean(
must: [
new RangeTerm('weight_range', 1),
new Term('category', 'footwear')
]
))
->get();
use ShabuShabu\ParadeDB\Expressions\RangeTerm;
use ShabuShabu\ParadeDB\Expressions\Ranges\Int4;
use ShabuShabu\ParadeDB\Expressions\Ranges\Relation;
Product::query()
->where('id', '@@@', new RangeTerm(
field: 'weight_range',
term: new Int4(10, 12),
relation: Relation::intersects,
))
->get();
use ShabuShabu\ParadeDB\Expressions\Regex;
Product::query()
->where('id', '@@@', new Regex('description', '(plush|leather)'))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
Product::query()
->where('id', '@@@', new Term('rating', 4))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\TermSet;
Product::query()
->where('id', '@@@', new TermSet([
new Term('description', 'shoes'),
new Term('description', 'running'),
]))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Boolean;
use ShabuShabu\ParadeDB\Expressions\FuzzyTerm;
use ShabuShabu\ParadeDB\Expressions\Ranges\Int4;
use ShabuShabu\ParadeDB\Expressions\Ranges\Bounds;
Product::query()
->where('id', '@@@', new Boolean(
should: new Term('description', 'headphones'),
must: [
new Term('category', 'electronics'),
new FuzzyTerm('description', 'bluetooht'),
],
mustNot: new Range('rating', new Int4(null, 2, Bounds::excludeAll)),
))
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Operators\FullText;
use ShabuShabu\ParadeDB\Expressions\Boolean;
use ShabuShabu\ParadeDB\Expressions\FuzzyTerm;
use ShabuShabu\ParadeDB\Expressions\Ranges\Int4;
use ShabuShabu\ParadeDB\Expressions\Ranges\Bounds;
Product::query()
->where('id', FullText::search->value, Boolean::query()
->should(new Term('description', 'headphones'))
->must(new Term('category', 'electronics'))
->must(new FuzzyTerm('description', 'bluetooht'))
->mustNot(new Range('rating', new Int4(null, 2, Bounds::excludeAll)))
)
->get();
use ShabuShabu\ParadeDB\Expressions\Term;
use ShabuShabu\ParadeDB\Expressions\Boolean;
use ShabuShabu\ParadeDB\Expressions\FuzzyTerm;
use ShabuShabu\ParadeDB\Expressions\Ranges\Int4;
use ShabuShabu\ParadeDB\Expressions\Ranges\Bounds;
$when = false;
Product::query()
->where('id', '@@@', Boolean::query()
->should(new Term('description', 'headphones'))
->must(new Term('category', 'electronics'))
->must(new FuzzyTerm('description', 'bluetooht'), $when)
->mustNot(new Range('rating', new Int4(null, 2, Bounds::excludeAll)))
)
->get();