Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
b7fcaeca
Commit
b7fcaeca
authored
9 years ago
by
Martynas Sudintas
Browse files
Options
Downloads
Patches
Plain Diff
Implemented BoolQuery, FilterQuery. Deprecated Bool
parent
f054de56
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Bool/Bool.php
+8
-55
8 additions, 55 deletions
Bool/Bool.php
Filter/BoolFilter.php
+23
-0
23 additions, 0 deletions
Filter/BoolFilter.php
Query/BoolQuery.php
+81
-0
81 additions, 0 deletions
Query/BoolQuery.php
with
112 additions
and
55 deletions
Bool/Bool.php
+
8
−
55
View file @
b7fcaeca
...
...
@@ -13,33 +13,15 @@ namespace ONGR\ElasticsearchBundle\DSL\Bool;
use
ONGR\ElasticsearchBundle\DSL\BuilderInterface
;
use
ONGR\ElasticsearchBundle\DSL\ParametersTrait
;
use
ONGR\ElasticsearchBundle\DSL\Query\BoolQuery
;
/**
* Bool operator. Can be used for filters and queries.
*
* @deprecated Will be removed in 1.0. Use ONGR\ElasticsearchBundle\DSL\Query\BoolQuery.
*/
class
Bool
implem
en
t
s
B
uilderInterface
class
Bool
ext
en
d
s
B
oolQuery
{
use
ParametersTrait
;
const
MUST
=
'must'
;
const
MUST_NOT
=
'must_not'
;
const
SHOULD
=
'should'
;
/**
* @var array
*/
private
$container
=
[];
/**
* Checks if bool filter is relevant.
*
* @return bool
*/
public
function
isRelevant
()
{
return
(
bool
)
count
(
$this
->
container
);
}
/**
* Add BuilderInterface object to bool operator.
*
...
...
@@ -47,40 +29,11 @@ class Bool implements BuilderInterface
* @param string $type
*
* @throws \UnexpectedValueException
*
* @deprecated Will be removed in 1.0. Use ONGR\ElasticsearchBundle\DSL\Query\BoolQuery::add().
*/
public
function
addToBool
(
BuilderInterface
$bool
,
$type
=
self
::
MUST
)
{
$constants
=
(
new
\ReflectionObject
(
$this
))
->
getConstants
();
if
(
!
in_array
(
$type
,
$constants
))
{
throw
new
\UnexpectedValueException
(
sprintf
(
'The bool operator %s is not supported'
,
$type
));
}
$this
->
container
[
$type
][]
=
$bool
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'bool'
;
}
/**
* {@inheritdoc}
*/
public
function
toArray
()
public
function
addToBool
(
BuilderInterface
$bool
,
$type
=
BoolQuery
::
MUST
)
{
$output
=
$this
->
processArray
();
foreach
(
$this
->
container
as
$type
=>
$filters
)
{
/** @var BuilderInterface $bool */
foreach
(
$filters
as
$bool
)
{
$output
[
$type
][]
=
[
$bool
->
getType
()
=>
$bool
->
toArray
()];
}
}
return
$output
;
$this
->
add
(
$bool
,
$type
);
}
}
This diff is collapsed.
Click to expand it.
Filter/BoolFilter.php
0 → 100644
+
23
−
0
View file @
b7fcaeca
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
ONGR\ElasticsearchBundle\DSL\Filter
;
use
ONGR\ElasticsearchBundle\DSL\Query\BoolQuery
;
/**
* Represents Elasticsearch "bool" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
*/
class
BoolFilter
extends
BoolQuery
{
}
This diff is collapsed.
Click to expand it.
Query/BoolQuery.php
0 → 100644
+
81
−
0
View file @
b7fcaeca
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
ONGR\ElasticsearchBundle\DSL\Query
;
use
ONGR\ElasticsearchBundle\DSL\BuilderInterface
;
use
ONGR\ElasticsearchBundle\DSL\ParametersTrait
;
/**
* Represents Elasticsearch "bool" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
*/
class
BoolQuery
implements
BuilderInterface
{
use
ParametersTrait
;
const
MUST
=
'must'
;
const
MUST_NOT
=
'must_not'
;
const
SHOULD
=
'should'
;
/**
* @var array
*/
private
$container
=
[];
/**
* Checks if bool expression is relevant.
*
* @return bool
*/
public
function
isRelevant
()
{
return
(
bool
)
count
(
$this
->
container
);
}
/**
* Add BuilderInterface object to bool operator.
*
* @param BuilderInterface $builder Query or a filter to add to bool.
* @param string $type Bool type. Available: must, must_not, should.
*
* @return BoolQuery
*
* @throws \UnexpectedValueException
*/
public
function
add
(
BuilderInterface
$builder
,
$type
=
self
::
MUST
)
{
if
(
!
in_array
(
$type
,
(
new
\ReflectionObject
(
$this
))
->
getConstants
()))
{
throw
new
\UnexpectedValueException
(
sprintf
(
'The bool operator %s is not supported'
,
$type
));
}
$this
->
container
[
$type
][]
=
[
$builder
->
getType
()
=>
$builder
->
toArray
()];
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
toArray
()
{
return
$this
->
processArray
(
$this
->
container
);
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'bool'
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment