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
fec0e17c
Commit
fec0e17c
authored
10 years ago
by
Martynas Sudintas
Browse files
Options
Downloads
Patches
Plain Diff
Highlight implemented friendly builder
parent
61dd80ec
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
Highlight/Field.php
+20
-13
20 additions, 13 deletions
Highlight/Field.php
Highlight/Highlight.php
+18
-61
18 additions, 61 deletions
Highlight/Highlight.php
with
38 additions
and
74 deletions
Highlight/Field.php
+
20
−
13
View file @
fec0e17c
...
...
@@ -12,11 +12,12 @@
namespace
ONGR\ElasticsearchBundle\DSL\Highlight
;
use
ONGR\ElasticsearchBundle\DSL\BuilderInterface
;
use
ONGR\ElasticsearchBundle\DSL\FriendlyBuilderInterface
;
/**
* This class holds data for highlighting field.
*/
class
Field
class
Field
implements
FriendlyBuilderInterface
{
const
TYPE_PLAIN
=
'plain'
;
const
TYPE_POSTINGS
=
'postings'
;
...
...
@@ -25,42 +26,42 @@ class Field
/**
* @var string Field name.
*/
pr
otec
te
d
$name
;
pr
iva
te
$name
;
/**
* @var string Highlighter type. By default 'plain'.
*/
pr
otec
te
d
$type
;
pr
iva
te
$type
;
/**
* @var int Size of the highlighted fragment in characters. By default 100.
*/
pr
otec
te
d
$fragmentSize
;
pr
iva
te
$fragmentSize
;
/**
* @var int Maximum number of fragments to return. By default 5.
*/
pr
otec
te
d
$numberOfFragments
;
pr
iva
te
$numberOfFragments
;
/**
* @var array Combine matches on multiple fields to highlight a single field.
*/
pr
otec
te
d
$matchedFields
;
pr
iva
te
$matchedFields
;
/**
* @var BuilderInterface Query to highlight.
*/
pr
otec
te
d
$highlightQuery
;
pr
iva
te
$highlightQuery
;
/**
* @var int Show part of string even if there are no matches to highlight. Defaults to 0.
*/
pr
otec
te
d
$noMatchSize
;
pr
iva
te
$noMatchSize
;
/**
* @var bool Highlight fields based on the source.
*/
pr
otec
te
d
$forceSource
;
pr
iva
te
$forceSource
;
/**
* Creates a highlight for a field.
...
...
@@ -74,7 +75,7 @@ class Field
}
/**
*
@return string
*
{@inheritdoc}
*/
public
function
getName
()
{
...
...
@@ -183,9 +184,7 @@ class Field
}
/**
* Returns an array of field parameters.
*
* @return array
* {@inheritdoc}
*/
public
function
toArray
()
{
...
...
@@ -201,4 +200,12 @@ class Field
]
);
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
$this
->
type
;
}
}
This diff is collapsed.
Click to expand it.
Highlight/Highlight.php
+
18
−
61
View file @
fec0e17c
...
...
@@ -11,115 +11,72 @@
namespace
ONGR\ElasticsearchBundle\DSL\Highlight
;
use
ONGR\ElasticsearchBundle\DSL\FriendlyBuilderBag
;
use
ONGR\ElasticsearchBundle\DSL\FriendlyBuilderInterface
;
/**
* Data holder for highlight api.
*/
class
Highlight
class
Highlight
extends
FriendlyBuilderBag
{
const
TYPE_PLAIN
=
'plain'
;
const
TYPE_POSTINGS
=
'postings'
;
const
TYPE_FVH
=
'fvh'
;
/**
* @var array Holds fields to highlight.
*/
protected
$fields
=
[];
/**
* @var array Holds html tag name and class that highlight will be put in (default 'em' tag).
*/
pr
otec
te
d
$tags
=
[];
pr
iva
te
$tags
=
[];
/**
* @var string Holds tag schema name. 'styled' is the only option yet.
*/
pr
otec
te
d
$tagsSchema
=
null
;
pr
iva
te
$tagsSchema
=
null
;
/**
* @var string Fragments sort type.
*/
pr
otec
te
d
$order
=
null
;
pr
iva
te
$order
=
null
;
/**
* @var string Highlighter type. By default plain.
*/
pr
otec
te
d
$type
=
null
;
pr
iva
te
$type
=
null
;
/**
* @var int Size of the highlighted fragment in characters. By default 100.
*/
pr
otec
te
d
$fragmentSize
=
null
;
pr
iva
te
$fragmentSize
=
null
;
/**
* @var int Maximum number of fragments to return. By default 5.
*/
pr
otec
te
d
$numberOfFragments
=
null
;
pr
iva
te
$numberOfFragments
=
null
;
/**
* Adds field to highlight.
*
* @param Field $field
* {@inheritdoc}
*
* @return Highlight
*/
public
function
add
Field
(
Field
$field
)
public
function
add
(
FriendlyBuilderInterface
$builder
)
{
if
(
!
$this
->
hasField
(
$field
->
getName
()))
{
$this
->
fields
[]
=
$field
;
}
parent
::
add
(
$builder
);
return
$this
;
}
/**
* Checks if field already will be highlighted.
*
* @param string $fieldName
*
* @return bool
*/
public
function
hasField
(
$fieldName
)
{
/** @var Field $field */
foreach
(
$this
->
fields
as
$field
)
{
if
(
$field
->
getName
()
==
$fieldName
)
{
return
true
;
}
}
return
false
;
}
/**
* Removes field from highlighting.
*
* @param string $fieldName
* {@inheritdoc}
*
* @return Highlight
*/
public
function
removeField
(
$fieldName
)
public
function
set
(
array
$builders
)
{
/** @var Field $field */
foreach
(
$this
->
fields
as
$key
=>
$field
)
{
if
(
$field
->
getName
()
==
$fieldName
)
{
unset
(
$this
->
fields
[
$key
]);
break
;
}
}
parent
::
set
(
$builders
);
return
$this
;
}
/**
* Returns all fields to highlight.
*
* @return array
*/
public
function
getFields
()
{
return
$this
->
fields
;
}
/**
* Sets html tag and its class used in highlighting.
*
...
...
@@ -240,8 +197,8 @@ class Highlight
}
}
/** @var Fie
ld
$field */
foreach
(
$this
->
getFields
()
as
$field
)
{
/** @var F
r
ie
ndlyBuilderInterface
$field */
foreach
(
$this
->
all
()
as
$field
)
{
$highlight
[
'fields'
][
$field
->
getName
()]
=
$field
->
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