Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
ab585d41
Commit
ab585d41
authored
Sep 26, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added per-field highlighting example
parent
b9a315fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
examples/2.1.5.3.1-per-field-highlighting.php
examples/2.1.5.3.1-per-field-highlighting.php
+53
-0
examples/index.html
examples/index.html
+5
-1
No files found.
examples/2.1.5.3.1-per-field-highlighting.php
0 → 100644
View file @
ab585d41
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
$query
->
setQuery
(
'memory'
);
// get highlighting component and apply settings
// highlights are applied to three fields with a different markup for each field
// much more per-field settings are available, see the manual for all options
$hl
=
$query
->
getHighlighting
();
$hl
->
getField
(
'name'
)
->
setSimplePrefix
(
'<b>'
)
->
setSimplePostfix
(
'</b>'
);
$hl
->
getField
(
'cat'
)
->
setSimplePrefix
(
'<u>'
)
->
setSimplePostfix
(
'</u>'
);
$hl
->
getField
(
'features'
)
->
setSimplePrefix
(
'<i>'
)
->
setSimplePostfix
(
'</i>'
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
$highlighting
=
$resultset
->
getHighlighting
();
// display the total number of documents found by solr
echo
'NumFound: '
.
$resultset
->
getNumFound
();
// show documents using the resultset iterator
foreach
(
$resultset
as
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table><br/><b>Highlighting results:</b><br/>'
;
// highlighting results can be fetched by document id (the field defined as uniquekey in this schema)
$highlightedDoc
=
$highlighting
->
getResult
(
$document
->
id
);
if
(
$highlightedDoc
){
foreach
(
$highlightedDoc
as
$field
=>
$highlight
)
{
echo
implode
(
' (...) '
,
$highlight
)
.
'<br/>'
;
}
}
}
htmlFooter
();
\ No newline at end of file
examples/index.html
View file @
ab585d41
...
...
@@ -44,6 +44,10 @@
</ul>
<li><a
href=
"2.1.5.2-morelikethis.php"
>
2.1.5.2 MoreLikeThis
</a></li>
<li><a
href=
"2.1.5.3-highlighting.php"
>
2.1.5.3 Highlighting
</a></li>
<ul
style=
"list-style:none;"
>
<li><a
href=
"2.1.5.3.1-per-field-highlighting.php"
>
2.1.5.3.1 Per-field highlighting options
</a></li>
</ul>
<li><a
href=
"2.1.5.4-dismax.php"
>
2.1.5.4 Dismax
</a></li>
<li><a
href=
"2.1.5.5-edismax.php"
>
2.1.5.5 Edismax
</a></li>
<li><a
href=
"2.1.5.6-grouping-by-field.php"
>
2.1.5.5 Grouping by field
</a></li>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment