Skip to content
GitLab
Explore
Sign in
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
6c6cf06a
Unverified
Commit
6c6cf06a
authored
6 years ago
by
Simonas Šerlinskas
Browse files
Options
Downloads
Patches
Plain Diff
add field masking span query
parent
c6427d59
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Query/Span/FieldMaskingSpanQuery.php
+103
-0
103 additions, 0 deletions
src/Query/Span/FieldMaskingSpanQuery.php
tests/Unit/Query/Span/FieldMaskingSpanQueryTest.php
+59
-0
59 additions, 0 deletions
tests/Unit/Query/Span/FieldMaskingSpanQueryTest.php
with
162 additions
and
0 deletions
src/Query/Span/FieldMaskingSpanQuery.php
0 → 100644
+
103
−
0
View file @
6c6cf06a
<?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\Query\Span
;
use
ONGR\ElasticsearchDSL\ParametersTrait
;
/**
* Elasticsearch span within query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-field-masking-query.html
*/
class
FieldMaskingSpanQuery
implements
SpanQueryInterface
{
use
ParametersTrait
;
/**
* @var SpanQueryInterface
*/
private
$query
;
/**
* @var string
*/
private
$field
;
/**
* @param string $field
* @param SpanQueryInterface $query
*/
public
function
__construct
(
$field
,
SpanQueryInterface
$query
)
{
$this
->
setQuery
(
$query
);
$this
->
setField
(
$field
);
}
/**
* @return mixed
*/
public
function
getQuery
()
{
return
$this
->
query
;
}
/**
* @param mixed $query
* @return self
*/
public
function
setQuery
(
$query
)
{
$this
->
query
=
$query
;
return
$this
;
}
/**
* @return string
*/
public
function
getField
()
{
return
$this
->
field
;
}
/**
* @param string $field
* @return FieldMaskingSpanQuery
*/
public
function
setField
(
$field
)
{
$this
->
field
=
$field
;
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
toArray
()
{
$output
=
[
'query'
=>
$this
->
getQuery
()
->
toArray
(),
'field'
=>
$this
->
getField
(),
];
$output
=
$this
->
processArray
(
$output
);
return
[
$this
->
getType
()
=>
$output
];
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'field_masking_span'
;
}
}
This diff is collapsed.
Click to expand it.
tests/Unit/Query/Span/FieldMaskingSpanQueryTest.php
0 → 100644
+
59
−
0
View file @
6c6cf06a
<?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\Tests\Unit\Query\Span
;
use
ONGR\ElasticsearchDSL\Query\Span\FieldMaskingSpanQuery
;
use
ONGR\ElasticsearchDSL\Query\Span\SpanNearQuery
;
use
ONGR\ElasticsearchDSL\Query\Span\SpanTermQuery
;
/**
* Unit test for FieldMaskingSpanQuery.
*/
class
FieldMaskingSpanQueryTest
extends
\PHPUnit\Framework\TestCase
{
/**
* Tests for toArray().
*/
public
function
testToArray
()
{
$spanTermQuery
=
new
SpanTermQuery
(
'text'
,
'quick brown'
);
$spanTermQueryForMask
=
new
SpanTermQuery
(
'text.stems'
,
'fox'
);
$fieldMaskingSpanQuery
=
new
FieldMaskingSpanQuery
(
'text'
,
$spanTermQueryForMask
);
$spanNearQuery
=
new
SpanNearQuery
();
$spanNearQuery
->
addQuery
(
$spanTermQuery
);
$spanNearQuery
->
addQuery
(
$fieldMaskingSpanQuery
);
$spanNearQuery
->
setSlop
(
5
);
$spanNearQuery
->
addParameter
(
'in_order'
,
false
);
$result
=
[
'span_near'
=>
[
'clauses'
=>
[
[
'span_term'
=>
[
'text'
=>
'quick brown'
]
],
[
'field_masking_span'
=>
[
'query'
=>
[
'span_term'
=>
[
'text.stems'
=>
'fox'
]
],
'field'
=>
'text'
,
]
]
],
'slop'
=>
5
,
'in_order'
=>
false
,
],
];
$this
->
assertEquals
(
$result
,
$spanNearQuery
->
toArray
());
}
}
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