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
f8bc9a16
Commit
f8bc9a16
authored
8 years ago
by
Mantas
Browse files
Options
Downloads
Patches
Plain Diff
added general Suggest class
parent
67559d5f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Suggest/Suggest.php
+171
-0
171 additions, 0 deletions
src/Suggest/Suggest.php
with
171 additions
and
0 deletions
src/Suggest/Suggest.php
0 → 100644
+
171
−
0
View file @
f8bc9a16
<?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\Suggest
;
use
ONGR\ElasticsearchDSL\BuilderInterface
;
use
ONGR\ElasticsearchDSL\ParametersTrait
;
use
Symfony\Component\Serializer\Exception\InvalidArgumentException
;
class
Suggest
implements
BuilderInterface
{
use
ParametersTrait
;
const
TERM
=
'term'
;
const
COMPLETION
=
'completion'
;
const
PHRASE
=
'phrase'
;
const
CONTEXT
=
'completion'
;
/**
* @var string
*/
private
$name
;
/**
* @var string
*/
private
$type
;
/**
* @var string
*/
private
$field
;
/**
* @var string
*/
private
$text
;
/**
* TermSuggest constructor.
* @param string $name
* @param string $field
* @param string $type
* @param string $text
* @param array $parameters
*/
public
function
__construct
(
$name
,
$field
,
$type
,
$text
,
$parameters
=
[])
{
$this
->
setName
(
$name
);
$this
->
validateType
(
$type
);
$this
->
setField
(
$field
);
$this
->
setType
(
$type
);
$this
->
setText
(
$text
);
$this
->
setParameters
(
$parameters
);
}
/**
* Returns element type.
*
* @return string
*/
public
function
getType
()
{
return
$this
->
type
;
}
/**
* @param string $type
*/
public
function
setType
(
$type
)
{
$this
->
type
=
$type
;
}
/**
* @return string
*/
public
function
getText
()
{
return
$this
->
text
;
}
/**
* @param string $text
*/
public
function
setText
(
$text
)
{
$this
->
text
=
$text
;
}
/**
* @return string
*/
public
function
getField
()
{
return
$this
->
field
;
}
/**
* @param string $field
*/
public
function
setField
(
$field
)
{
$this
->
field
=
$field
;
}
/**
* @param string $name
*/
public
function
setName
(
$name
)
{
$this
->
name
=
$name
;
}
/**
* Returns suggest name
*
* @return string
*/
public
function
getName
()
{
return
$this
->
name
;
}
/**
* Checks if the type is valid
*
* @param string $type
*
* @return bool
*
* @throws InvalidArgumentException
*/
private
function
validateType
(
$type
)
{
if
(
in_array
(
$type
,
[
self
::
COMPLETION
,
self
::
CONTEXT
,
self
::
PHRASE
,
self
::
TERM
]))
{
return
true
;
}
throw
new
InvalidArgumentException
(
'You must provide a valid type to the Suggest()'
);
}
/**
* {@inheritdoc}
*/
public
function
toArray
()
{
$output
=
[
$this
->
getName
()
=>
[
'text'
=>
$this
->
getText
(),
$this
->
getType
()
=>
$this
->
processArray
([
'field'
=>
$this
->
getField
()]),
]
];
return
$output
;
}
}
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