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
1a13f685
Commit
1a13f685
authored
8 years ago
by
Mantas Marcinkevičius
Browse files
Options
Downloads
Patches
Plain Diff
changed abstract inner hit to nested
parent
71ded9e7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/InnerHit/AbstractInnerHit.php
+0
-30
0 additions, 30 deletions
src/InnerHit/AbstractInnerHit.php
src/InnerHit/NestedInnerHit.php
+197
-0
197 additions, 0 deletions
src/InnerHit/NestedInnerHit.php
with
197 additions
and
30 deletions
src/InnerHit/AbstractInnerHit.php
deleted
100644 → 0
+
0
−
30
View file @
71ded9e7
<?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\ElasticsearchDSL\InnerHit
;
use
ONGR\ElasticsearchDSL\BuilderInterface
;
/**
* AbstractAggregation class.
*/
abstract
class
AbstractInnerHit
implements
BuilderInterface
{
/**
* {@inheritdoc}
*/
abstract
public
function
toArray
();
/**
* {@inheritdoc}
*/
abstract
public
function
getType
();
}
This diff is collapsed.
Click to expand it.
src/InnerHit/NestedInnerHit.php
0 → 100644
+
197
−
0
View file @
1a13f685
<?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\ElasticsearchDSL\InnerHit
;
use
ONGR\ElasticsearchDSL\BuilderBag
;
use
ONGR\ElasticsearchDSL\BuilderInterface
;
use
ONGR\ElasticsearchDSL\NameAwareTrait
;
use
ONGR\ElasticsearchDSL\ParametersTrait
;
/**
* Represents Elasticsearch top level nested inner hits.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
*/
class
NestedInnerHit
implements
BuilderInterface
{
use
ParametersTrait
;
use
NameAwareTrait
;
/**
* @var string
*/
private
$path
;
/**
* @var BuilderInterface
*/
private
$query
;
/**
* @var BuilderBag
*/
private
$innerHits
;
/**
* Inner hits container init.
*
* @param string $name
* @param string $path
* @param BuilderInterface $query
*/
public
function
__construct
(
$name
,
$path
,
BuilderInterface
$query
)
{
$this
->
setName
(
$name
);
$this
->
setPath
(
$path
);
$this
->
setQuery
(
$query
);
}
/**
* @return string
*/
public
function
getPath
()
{
return
$this
->
path
;
}
/**
* @param string $path
*/
public
function
setPath
(
$path
)
{
$this
->
path
=
$path
;
}
/**
* @return BuilderInterface
*/
public
function
getQuery
()
{
return
$this
->
query
;
}
/**
* @param BuilderInterface $query
*/
public
function
setQuery
(
BuilderInterface
$query
)
{
$this
->
query
=
$query
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'nested'
;
}
/**
* Adds a sub-innerHit.
*
* @param NestedInnerHit $innerHit
*/
public
function
addInnerHit
(
NestedInnerHit
$innerHit
)
{
if
(
!
$this
->
innerHits
)
{
$this
->
innerHits
=
new
BuilderBag
();
}
$this
->
innerHits
->
add
(
$innerHit
);
}
/**
* Returns all sub inner hits.
*
* @return BuilderInterface[]
*/
public
function
getInnerHits
()
{
if
(
$this
->
innerHits
)
{
return
$this
->
innerHits
->
all
();
}
else
{
return
[];
}
}
/**
* Returns sub inner hit.
* @param string $name inner hit name to return.
*
* @return NestedInnerHit|null
*/
public
function
getInnerHit
(
$name
)
{
if
(
$this
->
innerHits
&&
$this
->
innerHits
->
has
(
$name
))
{
return
$this
->
innerHits
->
get
(
$name
);
}
else
{
return
null
;
}
}
/**
* {@inheritdoc}
*/
public
function
toArray
()
{
$out
=
array_filter
(
[
'query'
=>
$this
->
getQuery
()
->
toArray
(),
'inner_hits'
=>
$this
->
collectNestedInnerHits
(),
]
);
$out
=
[
$this
->
getPathType
()
=>
[
$this
->
getPath
()
=>
$this
->
processArray
(
$out
),
],
];
return
$out
;
}
/**
* Returns 'path' for neted and 'type' for parent inner hits
*
* @return null|string
*/
private
function
getPathType
()
{
switch
(
$this
->
getType
())
{
case
'nested'
:
$type
=
'path'
;
break
;
case
'parent'
:
$type
=
'type'
;
break
;
default
:
$type
=
null
;
}
return
$type
;
}
/**
* Process all nested inner hits.
*
* @return array
*/
private
function
collectNestedInnerHits
()
{
$result
=
[];
/** @var NestedInnerHit $innerHit */
foreach
(
$this
->
getInnerHits
()
as
$innerHit
)
{
$result
[
$innerHit
->
getName
()]
=
$innerHit
->
toArray
();
}
return
$result
;
}
}
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