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
e4ecd8a5
Commit
e4ecd8a5
authored
9 years ago
by
Martynas Sudintas
Browse files
Options
Downloads
Patches
Plain Diff
implemented search endpoints into actual search class
parent
705508af
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Query/QueryAwareTrait.php
+0
-138
0 additions, 138 deletions
Query/QueryAwareTrait.php
Search.php
+369
-299
369 additions, 299 deletions
Search.php
with
369 additions
and
437 deletions
Query/QueryAwareTrait.php
deleted
100644 → 0
+
0
−
138
View file @
705508af
<?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\Bool\Bool
;
use
ONGR\ElasticsearchBundle\DSL\BuilderInterface
;
/**
* Provides query container functionality to any class.
*/
trait
QueryAwareTrait
{
/**
* @var BuilderInterface[]
*/
private
$queries
=
[];
/**
* @var \ONGR\ElasticsearchBundle\DSL\Bool\Bool
*/
private
$boolQuery
;
/**
* @param BuilderInterface $query
* @param string $boolType
*
* @return $this
*/
public
function
addQuery
(
BuilderInterface
$query
,
$boolType
=
Bool
::
MUST
)
{
if
(
$boolType
!==
Bool
::
MUST
||
$this
->
boolQuery
!==
null
)
{
$this
->
getBoolQuery
()
->
addToBool
(
$query
,
$boolType
);
}
else
{
$this
->
queries
[
$query
->
getType
()]
=
$query
;
}
return
$this
;
}
/**
* Returns Bool query. Creates new instance if there is not initiated.
*
* @return \ONGR\ElasticsearchBundle\DSL\Bool\Bool
*/
public
function
getBoolQuery
()
{
if
(
!
$this
->
boolQuery
)
{
$this
->
boolQuery
=
new
Bool
();
}
return
$this
->
boolQuery
;
}
/**
* @param array $params Example values:
* - minimum_should_match => 1
* - boost => 1.
*/
public
function
setBoolQueryParameters
(
array
$params
)
{
$this
->
getBoolQuery
()
->
setParameters
(
$params
);
}
/**
* Checks if there is added specific query.
*
* @param string $type Query type.
*
* @return bool
*/
public
function
hasQuery
(
$type
)
{
return
array_key_exists
(
$type
,
$this
->
queries
);
}
/**
* Removes specific query.
*
* @param string $key
*/
public
function
removeQuery
(
$key
)
{
if
(
$this
->
hasQuery
(
$key
))
{
unset
(
$this
->
queries
[
$key
]);
}
}
/**
* Completely resets query.
*/
public
function
destroyQuery
()
{
$this
->
queries
=
[];
$this
->
boolQuery
=
null
;
}
/**
* Return all queries.
*
* @return array
*/
public
function
getQueries
()
{
return
$this
->
queries
;
}
/**
* Aggregates all queries to array.
*
* @return array
*/
public
function
processQueries
()
{
if
(
$this
->
boolQuery
||
count
(
$this
->
getQueries
())
>
1
)
{
$bool
=
$this
->
getBoolQuery
();
foreach
(
$this
->
getQueries
()
as
$query
)
{
$bool
->
addToBool
(
$query
);
}
return
[
'query'
=>
[
$bool
->
getType
()
=>
$bool
->
toArray
()]];
}
elseif
(
count
(
$this
->
getQueries
())
==
1
)
{
$query
=
array_values
(
$this
->
getQueries
())[
0
];
return
[
'query'
=>
[
$query
->
getType
()
=>
$query
->
toArray
()]];
}
return
[];
}
}
This diff is collapsed.
Click to expand it.
Search.php
+
369
−
299
View file @
e4ecd8a5
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