Copyright© 2008-2023 Sitevision AB, all rights reserved.
public interface SearchHit extends VelocityAccess.SearchHitConstants
A SearchHit
is a container for the search result returned from an Index as well
as for the representation of an internal hit as Node
.
Know your fields! Ensure to call the proper "getField" method when getting a field value!
Note that fields are of a specific type (String
, Boolean
, Float
,
Long
or Date
) and a field value can be multi-valued and/or highlighted.
Regardless of type - it is always possible to get a field value as String, but converting it to the "original" type
might be a difficult task for certain types (e.g. a Date
field).
This object is short lived in that sense that it is invalid after a specified timespan. Make sure it's handled correspondingly (i.e. do not cache it).
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_EXTERNAL
Indicates that the hit is an external resource
|
static int |
TYPE_INTERNAL
Indicates that the hit is an internal resource managed by the Sitevision server
|
Modifier and Type | Method and Description |
---|---|
boolean |
fieldContains(String aFieldName,
String aValue)
Checks if the value(-s) for a specified field contains a specific value.
|
boolean |
fieldEquals(String aFieldName,
String aValue)
Checks if the value(-s) for a specified field equals a specific value.
|
boolean |
fieldEqualsIgnoreCase(String aFieldName,
String aValue)
Checks if the value(-s) for a specified field equals a specific value, case-insensitively.
|
boolean |
fieldMatches(String aFieldName,
String aRegularExpression)
Checks if the value(-s) for a specified field matches a specified regular expression.
|
Boolean |
getBooleanField(String aFieldName)
The indexed content as Boolean for a specified field.
|
List<Boolean> |
getBooleanFields(String aFieldName)
The indexed contents as a list of Boolean values for a specified field.
|
String |
getClickTrackingCallback()
Returns a jQuery expression for tracking of clicks on this search hit.
|
String |
getClickTrackingUri()
Returns the uri for tracking of clicks on this search hit.
|
Date |
getDateField(String aFieldName)
The indexed content as Date for a specified field.
|
List<Date> |
getDateFields(String aFieldName)
The indexed contents as a list of Date values for a specified field.
|
String |
getField(String aFieldName)
The indexed content as string for a specified field.
|
String |
getField(String aFieldName,
boolean useMaxCharsField)
The indexed content as string for a specified field (with option to use first or largest field if multiple fields match).
|
String |
getField(String aFieldName,
boolean useMaxCharsField,
String aDefaultValue)
The indexed content as string for a specified field (with option to use first or largest field if multiple fields match),
or a default value if no such field exist.
|
String |
getField(String aFieldName,
String aDefaultValue)
The indexed content as string for a specified field, or a default value if no such field exist.
|
String |
getFieldEscaped(String aFieldName)
The indexed content as XML escaped string for a specified field.
|
String |
getFieldEscaped(String aFieldName,
boolean useMaxCharsField)
The indexed content as XML escaped string for a specified field (with option to use first or largest field if multiple fields match).
|
String |
getFieldEscaped(String aFieldName,
boolean useMaxCharsField,
String aDefaultValue)
The indexed content as XML escaped string for a specified field (with option to use first or largest field if multiple fields match),
or a default value if no such field exist.
|
String |
getFieldEscaped(String aFieldName,
String aDefaultValue)
The indexed content as XML escaped string for a specified field, or a default value if no such field exist.
|
Collection<String> |
getFieldNames()
The names of all fields available in this search hit.
|
List<String> |
getFields(String aFieldName)
The indexed content as a list of strings for a specified field.
|
List<String> |
getFieldsEscaped(String aFieldName)
The indexed content as a list of XML escaped strings for a specified field.
|
List<String> |
getFieldsTruncated(String aFieldName,
int maxContentLength)
The indexed content as a list of lenient truncated strings for a specified field.
|
List<String> |
getFieldsTruncated(String aFieldName,
int maxContentLength,
boolean useLenientTruncation)
The indexed content as a list of truncated (lenient or not) strings for a specified field.
|
String |
getFieldTruncated(String aFieldName,
boolean useMaxCharsField,
boolean useLenientTruncation,
int maxContentLength)
The indexed content as string for a specified field, truncated (lenient or not) to a max size and an option to use first
or largest field if multiple fields match.
|
String |
getFieldTruncated(String aFieldName,
int maxContentLength)
The indexed content as string for a specified field, truncated to a lenient max size.
|
Float |
getFloatField(String aFieldName)
The indexed content as Float for a specified field.
|
List<Float> |
getFloatFields(String aFieldName)
The indexed contents as a list of Float values for a specified field.
|
String |
getHighlightedField(String aFieldName,
int maxNonHighlightedLength)
The encoded and highlighted content of a highlighted field.
|
List<String> |
getHighlightedFields(String aFieldName,
int maxNonHighlightedLength)
The encoded and highlighted contents of a highlighted field.
|
Long |
getLongField(String aFieldName)
The indexed content as Long for a specified field.
|
List<Long> |
getLongFields(String aFieldName)
The indexed contents as a list of Long values for a specified field.
|
Node |
getNode()
Accesses the
Node corresponding to a TYPE_INTERNAL hit. |
float |
getScore()
The relative search score of the hit.
|
int |
getType()
The type of
SearchHit object. |
boolean |
isElevated()
Whether or not the search hit was elevated in the query result.
|
getTYPE_EXTERNAL, getTYPE_INTERNAL
static final int TYPE_INTERNAL
Indicates that the hit is an internal resource managed by the Sitevision server
static final int TYPE_EXTERNAL
Indicates that the hit is an external resource
boolean fieldContains(String aFieldName, String aValue)
Checks if the value(-s) for a specified field contains a specific value.
Convenience method to use when checking for a specific value. This method would typically be used when you are looking for a specific value in a multi-valued field. Typically metadata or a multi-valued default fields of the Sitevision standard/system index (e.g. path or svtype). Calling this method is more efficient than doing the contains check(-s) yourself (exemplified below):
boolean containsValue = false;
List<String> fieldValues = aSearchHit.getFields("aFieldName");
for (String fieldValue : fieldValues) {
if (fieldValue.contains("a specific value")) {
containsValue = true;
break;
}
}
aFieldName
- the name of the field.aValue
- the value to look for in the field value(-s).aFieldName
contains aValue
.
If the aFieldName
field is multi-valued, this method will return true
if any of the field values
contains aValue
, false
otherwise.
A null
or empty value for aFieldName
or aValue
will always return false
.fieldEquals(String, String)
,
fieldEqualsIgnoreCase(String, String)
,
fieldMatches(String, String)
boolean fieldEquals(String aFieldName, String aValue)
Checks if the value(-s) for a specified field equals a specific value.
Convenience method to use when checking for a specific value. This method would typically be used when you are looking for a specific value in a multi-valued field. Typically metadata or a multi-valued default fields of the Sitevision standard/system index (e.g. path or svtype). Calling this method is more efficient than doing the equals check(-s) yourself (exemplified below):
boolean equalsValue = false;
List<String> fieldValues = aSearchHit.getFields("aFieldName");
for (String fieldValue : fieldValues) {
if (fieldValue.equals("a specific value")) {
equalsValue = true;
break;
}
}
An example: Your Site has a multi-valued metadata named "category" that is indexed (the name of the stored, non-analyzed index field will be "metadata.category"). The predefined set of selectable values for this metadata is "Internal", "External", "Personal", "Recreation", "Classified" and "Other". The page editors can select none or any combination of the predefined values for any node that is indexed. When rendering the search hits, you want to treat all search hits representing nodes that includes the "Classified" value for the "category" metadata differently. Below is an example that only handles the highlighted "summary" field for "non-Classified" hits:
for (SearchHit searchHit : searchResult) {
...
if (!searchHit.fieldEquals("metadata.category", "Classfied")) {
String summary = searchHit.getHighlightedField("summary", 500);
...
}
...
}
aFieldName
- the name of the field.aValue
- the value to compare to the field value(-s).aFieldName
equals aValue
.
If the aFieldName
field is multi-valued, this method will return true
if any of the field values
equals aValue
, false
otherwise.
A null
or empty value for aFieldName
or aValue
will always return false
.fieldEqualsIgnoreCase(String, String)
,
fieldContains(String, String)
,
fieldMatches(String, String)
boolean fieldEqualsIgnoreCase(String aFieldName, String aValue)
Checks if the value(-s) for a specified field equals a specific value, case-insensitively.
Convenience method to use when checking for a specific value, case-insensitively. This method would typically be used when you are looking for a specific value in a multi-valued field. Typically metadata or a multi-valued default fields of the Sitevision standard/system index (e.g. path or svtype). Calling this method is more efficient than doing the case-insensitive equals check(-s) yourself (exemplified below):
boolean equalsValue = false;
List<String> fieldValues = aSearchHit.getFields("aFieldName");
for (String fieldValue : fieldValues) {
if (fieldValue.equalsIgnoreCase("a specific value")) {
equalsValue = true;
break;
}
}
Note! Always use the fieldEquals(String, String)
method instead when applicable!
aFieldName
- the name of the field.aValue
- the value to case-insensitively compare to the field value(-s).aFieldName
case-insensitively equals aValue
.
If the aFieldName
field is multi-valued, this method will return true
if any of the field values
case-insensitively equals aValue
, false
otherwise.
A null
or empty value for aFieldName
or aValue
will always return false
.fieldEquals(String, String)
,
fieldContains(String, String)
,
fieldMatches(String, String)
boolean fieldMatches(String aFieldName, String aRegularExpression) throws PatternSyntaxException
Checks if the value(-s) for a specified field matches a specified regular expression.
Convenience method to use when checking for a specific value using a regular expression. This method would typically be used when you are looking for a specific pattern in a multi-valued field. Typically metadata or a multi-valued default fields of the Sitevision standard/system index (e.g. path or svtype). Calling this method is more efficient than doing the matches check(-s) yourself (exemplified below):
String regularExpression = "[a-zA-Z]+"; // Chars 'a' to 'z' and 'A' to 'Z' one or more times...
boolean matchesValue = false;
List<String> fieldValues = aSearchHit.getFields("aFieldName");
for (String fieldValue : fieldValues) {
if (fieldValue.matches(regularExpression)) {
matchesValue = true;
break;
}
}
Note! This method creates, compiles and reuses java.util.regex.Pattern
instances to improve matching
performance for multiple values (typically when matching multi-valued field values). All such instances are cached in order to
boost performance for subsequent calls to this method with the same aRegularExpression
.
Tip! Regular expression syntax documentation is available via Oracle's java.util.regex.Pattern javadoc.
aFieldName
- the name of the field.aRegularExpression
- the regular expression to match to the field value(-s).aFieldName
matches a aRegularExpression
.
If the aFieldName
field is multi-valued, this method will return true
if
any of the field values matches aRegularExpression
, false
otherwise.
A null
or empty value for aFieldName
or aRegularExpression
will always return false
.PatternSyntaxException
- if the regular syntax expression of aRegularExpression
is invalid.fieldContains(String, String)
,
fieldEquals(String, String)
,
fieldEqualsIgnoreCase(String, String)
Node getNode()
Accesses the Node
corresponding to a TYPE_INTERNAL
hit. This
value will always be null for a TYPE_EXTERNAL
hit.
Node
or null
String getField(String aFieldName)
The indexed content as string for a specified field.
Note! This method returns the content as string for the first field that matches aFieldName
.
No considerations are made regarding the field's type. The field value will be treated as a string.
Calling this method is more efficient than calling SearchHit.getField(aFieldName, false)
but the result will be equivalent.
For a multi-valued field, you would typically use getFields(String)
instead.
aFieldName
- the name of the field.aFieldName
, or null
if no such field exist.getFieldEscaped(String)
,
getField(String, String)
,
getField(String, boolean)
,
getFields(String)
,
getBooleanField(String)
,
getDateField(String)
,
getFloatField(String)
,
getLongField(String)
String getFieldEscaped(String aFieldName)
The indexed content as XML escaped string for a specified field.
This is a convenience method for getField(String)
that also XML escapes the result
(see EndecUtil.escapeXML(String)
).
A String that should be included in the html output should typically always be XML escaped to be valid XHTML and avoid XSS problems.
This Velocity code:
#set ($endecUtil = $sitevisionUtils.endecUtil)
...
<p>
$endecUtil.escapeXML($searchHit.getField('title'))
</p>
would typically be replaced with this:
...
<p>
$!searchHit.getFieldEscaped('title')
</p>
This method can not be used to get field content of a highlighted field!
Use getHighlightedField(String, int)
instead to get the XML escaped content of a highlighted field.
aFieldName
- the name of the field.aFieldName
, or null
if no such field exist.getField(String)
String getField(String aFieldName, String aDefaultValue)
The indexed content as string for a specified field, or a default value if no such field exist.
Note! This is a convenience method for getField(String)
that enables you to avoid null
checks.
aFieldName
- the name of the field.aDefaultValue
- the default/fallback value.aFieldName
, or aDefaultValue
if no such field exist.getField(String)
,
getFieldEscaped(String, String)
String getFieldEscaped(String aFieldName, String aDefaultValue)
The indexed content as XML escaped string for a specified field, or a default value if no such field exist.
This is a convenience method for getField(String, String)
that also XML escapes the result
(see EndecUtil.escapeXML(String)
).
A String that should be included in the html output should typically always be XML escaped to be valid XHTML and avoid XSS problems.
This Velocity code:
#set ($endecUtil = $sitevisionUtils.endecUtil)
...
<p>
$endecUtil.escapeXML($searchHit.getField('title', ''))
</p>
would typically be replaced with this:
...
<p>
$searchHit.getFieldEscaped('title', '')
</p>
This method can not be used to get field content of a highlighted field!
Use getHighlightedField(String, int)
instead to get the XML escaped content of a highlighted field.
aFieldName
- the name of the field.aDefaultValue
- the default/fallback value.aFieldName
,
or aDefaultValue
if no such field exist.
Note that aDefaultValue
is not XML escaped by this method!getField(String, String)
String getField(String aFieldName, boolean useMaxCharsField)
The indexed content as string for a specified field (with option to use first or largest field if multiple fields match).
aFieldName
- The name of the field.useMaxCharsField
- whether the field that contains the most characters or the first field should be used if multiple fields match
(i.e. true
== use the matching field that contains most characters, false
== use first matching field).aFieldName
, or null
if no such field exist.getField(String)
,
getField(String, boolean, String)
,
getFieldEscaped(String, boolean)
String getFieldEscaped(String aFieldName, boolean useMaxCharsField)
The indexed content as XML escaped string for a specified field (with option to use first or largest field if multiple fields match).
This is a convenience method for getField(String, boolean)
that also XML escapes the result
(see EndecUtil.escapeXML(String)
).
A String that should be included in the html output should typically always be XML escaped to be valid XHTML and avoid XSS problems.
This Velocity code:
#set ($endecUtil = $sitevisionUtils.endecUtil)
...
<p>
$endecUtil.escapeXML($searchHit.getField('title', true))
</p>
would typically be replaced with this:
...
<p>
$!searchHit.getFieldEscaped('title', true)
</p>
This method can not be used to get field content of a highlighted field!
Use getHighlightedField(String, int)
instead to get the XML escaped content of a highlighted field.
aFieldName
- The name of the field.useMaxCharsField
- whether the field that contains the most characters or the first field should be used if multiple fields match
(i.e. true
== use the matching field that contains most characters, false
== use first matching field).aFieldName
, or null
if no such field exist.getField(String, boolean)
String getField(String aFieldName, boolean useMaxCharsField, String aDefaultValue)
The indexed content as string for a specified field (with option to use first or largest field if multiple fields match), or a default value if no such field exist.
Note! This is a convenience method for getField(String, boolean)
that enables you to avoid null
checks.
aFieldName
- The name of the field.useMaxCharsField
- whether the field that contains the most characters or the first field should be used if multiple fields match
(i.e. true
== use the matching field that contains most characters, false
== use first matching field).aDefaultValue
- the default/fallback value.aFieldName
, or aDefaultValue
if no such field exist.getField(String)
,
getField(String, boolean)
,
getFieldEscaped(String, boolean, String)
String getFieldEscaped(String aFieldName, boolean useMaxCharsField, String aDefaultValue)
The indexed content as XML escaped string for a specified field (with option to use first or largest field if multiple fields match), or a default value if no such field exist.
This is a convenience method for getField(String, boolean, String)
that also XML escapes the result
(see EndecUtil.escapeXML(String)
).
A String that should be included in the html output should typically always be XML escaped to be valid XHTML and avoid XSS problems.
This Velocity code:
#set ($endecUtil = $sitevisionUtils.endecUtil)
...
<p>
$endecUtil.escapeXML($searchHit.getField('title', true, ''))
</p>
would typically be replaced with this:
...
<p>
$searchHit.getFieldEscaped('title', true, '')
</p>
This method can not be used to get field content of a highlighted field!
Use getHighlightedField(String, int)
instead to get the XML escaped content of a highlighted field.
aFieldName
- The name of the field.useMaxCharsField
- whether the field that contains the most characters or the first field should be used if multiple fields match
(i.e. true
== use the matching field that contains most characters, false
== use first matching field).aDefaultValue
- the default/fallback value.aFieldName
, or aDefaultValue
if no such field exist.
Note that aDefaultValue
is not XML escaped by this method!getField(String, boolean, String)
List<String> getFields(String aFieldName)
The indexed content as a list of strings for a specified field.
This method would typically be used for multi-valued fields. For a single-valued String field, you would typically use
getField(String)
instead. No considerations are made regarding the field's type. The field values will be treated as strings.
Note! If the field is highlighted, use getHighlightedFields(String, int)
instead.
aFieldName
- the name of the field.aFieldName
, or an empty List
if no such fields exist.getFieldsTruncated(String, int)
List<String> getFieldsEscaped(String aFieldName)
The indexed content as a list of XML escaped strings for a specified field.
This is a convenience method for getFields(String)
that also XML escapes the result
(see EndecUtil.escapeXML(String)
).
A String that should be included in the html output should typically always be XML escaped to be valid XHTML and avoid XSS problems.
This method can not be used to get field content of a highlighted field!
Use getHighlightedFields(String, int)
instead to get the XML escaped content of a highlighted field.
aFieldName
- the name of the field.aFieldName
, or an empty List
if no such fields exist.getFields(String)
List<String> getFieldsTruncated(String aFieldName, int maxContentLength)
The indexed content as a list of lenient truncated strings for a specified field.
This method would typically be used for multi-valued fields. For a single-valued String field, you would typically use
getFieldTruncated(String, int)
instead. No considerations are made regarding the field's type.
The field values will be treated as strings.
Note! If the field is highlighted, use getHighlightedFields(String, int)
instead.
Calling this method is is equivalent to calling SearchHit.getFieldsTruncated(aFieldName, maxContentLength, true)
.
aFieldName
- the name of the field.maxContentLength
- max length of the content that should be returned. A value lower than 1 will be ignored
(i.e. content will not be truncated).aFieldName
truncated so it contains at most
maxContentLength
characters, or an empty List
if no such field exist.getFieldsTruncated(String, int, boolean)
List<String> getFieldsTruncated(String aFieldName, int maxContentLength, boolean useLenientTruncation)
The indexed content as a list of truncated (lenient or not) strings for a specified field.
This method would typically be used for multi-valued fields. For a single-valued String field, you would typically use
getFieldTruncated(String, int)
instead. No considerations are made regarding the field's type.
The field values will be treated as strings.
Note! If the field is highlighted, use getHighlightedFields(String, int)
instead.
aFieldName
- the name of the field.maxContentLength
- max length of the content that should be returned. A value lower than 1 will be ignored
(i.e. content will not be truncated).useLenientTruncation
- whether or not the truncation should be lenient.
A value of true
indicates that the truncation should be after the last complete word but less or equal to
maxContentLength
A value of false
indicates that the truncation should be absolute, i.e. truncation is made at maxContentLength
even if it cuts a word.aFieldName
truncated so it contains at most maxContentLength
characters,
or an empty List
if no such field exist.getFieldsTruncated(String, int)
Boolean getBooleanField(String aFieldName)
The indexed content as Boolean for a specified field.
Note! This method returns the content as Boolean for the first field that matches aFieldName
.
aFieldName
- the name of the field.aFieldName
,
or null
if no such field exist or if it's value can't be treated as a Boolean.getBooleanFields(String)
List<Boolean> getBooleanFields(String aFieldName)
The indexed contents as a list of Boolean values for a specified field.
This method would typically be used for multi-valued fields. For a single-valued field, you would typically use
getBooleanField(String)
instead.
aFieldName
- the name of the field.aFieldName
,
or an empty List
if no such field exist or no value can be treated as a Boolean.getBooleanField(String)
Date getDateField(String aFieldName)
The indexed content as Date for a specified field.
Note! This method returns the content as Date for the first field that matches aFieldName
.
aFieldName
- the name of the field.aFieldName
,
or null
if no such field exist or if it's value can't be treated as a Date.getDateFields(String)
List<Date> getDateFields(String aFieldName)
The indexed contents as a list of Date values for a specified field.
This method would typically be used for multi-valued Date fields. For a single-valued Date field, you would typically use
getDateField(String)
instead.
aFieldName
- the name of the field.aFieldName
,
or an empty List
if no such field exist or no value can be treated as a Date.getDateField(String)
Float getFloatField(String aFieldName)
The indexed content as Float for a specified field.
Note! This method returns the content as Float for the first field that matches aFieldName
.
aFieldName
- the name of the field.aFieldName
,
or null
if no such field exist or if it's value can't be treated as a Float.getFloatFields(String)
List<Float> getFloatFields(String aFieldName)
The indexed contents as a list of Float values for a specified field.
This method would typically be used for multi-valued Float fields. For a single-valued Float field, you would typically use
getFloatField(String)
instead.
aFieldName
- the name of the field.aFieldName
,
or an empty List
if no such field exist or no value can be treated as a Float.getFloatField(String)
Long getLongField(String aFieldName)
The indexed content as Long for a specified field.
Note! This method returns the content as Long for the first field that matches aFieldName
.
aFieldName
- the name of the field.aFieldName
,
or null
if no such field exist or if it's value can't be treated as a Long.getLongFields(String)
List<Long> getLongFields(String aFieldName)
The indexed contents as a list of Long values for a specified field.
This method would typically be used for multi-valued Long fields. For a single-valued Long field, you would typically use
getLongField(String)
instead.
aFieldName
- the name of the field.aFieldName
,
or an empty List
if no such field exist or no value can be treated as a Long.getLongField(String)
String getHighlightedField(String aFieldName, int maxNonHighlightedLength)
The encoded and highlighted content of a highlighted field.
Note! The result of this method is always escaped/encoded to XML entities so it won't interfere with the html elements that surround the possible "highlighted" fragments!
aFieldName
- the name of the highlighted field.maxNonHighlightedLength
- max length of the content that should be returned if no encoded highlighting result exists for given field.
A value lower than 1 will be ignored (i.e. content will not be truncated).maxNonHighlightedLength
,
or null
if no such field exist.getHighlightedFields(String, int)
List<String> getHighlightedFields(String aFieldName, int maxNonHighlightedLength)
The encoded and highlighted contents of a highlighted field.
This method would typically be used for multi-valued highlighted fields. For a single-valued highlighted field
(or if you only are interested in the largest highlighted value), you would typically use getHighlightedField(String, int)
instead.
No considerations are made regarding the field's type. The field values will be treated as strings.
Note! The items in the result of this method is always escaped/encoded to XML entities so they won't interfere with the html elements that surround the possible "highlighted" fragments!
aFieldName
- the name of the highlighted field.maxNonHighlightedLength
- max length of the content for each item if no encoded highlighting result exists for given field.
A value lower than 1 will be ignored (i.e. content will not be truncated).maxNonHighlightedLength
, or empty List
if no such field exist.getHighlightedField(String, int)
String getFieldTruncated(String aFieldName, int maxContentLength)
The indexed content as string for a specified field, truncated to a lenient max size.
Note! Calling this method is is equivalent to calling
SearchHit.getFieldTruncated(aFieldName, true, true, maxContentLength)
.
Note! If the field is highlighted, use getHighlightedField(String, int)
instead.
aFieldName
- the name of the field.maxContentLength
- max length of the content that should be returned. A value lower than 1 will be ignored
(i.e. content will not be truncated).aFieldName
truncated so it contains at most
maxContentLength
characters, or null
if no such field exist.getFieldTruncated(String, boolean, boolean, int)
String getFieldTruncated(String aFieldName, boolean useMaxCharsField, boolean useLenientTruncation, int maxContentLength)
The indexed content as string for a specified field, truncated (lenient or not) to a max size and an option to use first or largest field if multiple fields match.
Note! If the field is highlighted, use getHighlightedField(String, int)
instead.
aFieldName
- the name of the field.useMaxCharsField
- whether the field that contains the most characters or the first field should be used if multiple fields match
(i.e. true
== use the matching field that contains most characters, false
== use first matching field).useLenientTruncation
- whether or not the truncation should be lenient.
A value of true
indicates that the truncation should be after the last complete word but less or equal to
maxContentLength
A value of false
indicates that the truncation should be absolute, i.e. truncation is made at maxContentLength
even if it cuts a word.maxContentLength
- max length of the content that should be returned. A value lower than 1 will be ignored
(i.e. content will not be truncated).aFieldName
truncated so it contains at most
maxContentLength
characters, or null
if no such field exist.Collection<String> getFieldNames()
Potentially also includes the Solr pseudo fields "score" and "[elevated]".
float getScore()
The value ranges from 0 to 1 where 1 denotes the maximum score.
Note that the first hit does not necessarily has score 1, it is just the hit with the
highest relative score in the SearchResult
.
This method depends on availability of the Solr score pseudo field. Search queries without that field will always return 0,
Tip! Use this method to see the scores of your hits when debugging and tuning search field boost weights et al.
boolean isElevated()
This method depends on availability of the Solr [elevated] pseudo field. Search queries without that field will always return false, typically when custom fields (the Solr 'fl' param) is specified.
int getType()
The type of SearchHit
object.
SearchHit
. The value corresponds to any of the TYPE
fields
TYPE_INTERNAL
, TYPE_EXTERNAL
,TYPE_INTERNAL
,
TYPE_EXTERNAL
String getClickTrackingCallback()
Tracking search hits clicks is a helpful tool when analyzing if visitors seems to find interesting information in their search results. Though, if the search result isn't really inited by the user (i.e. an A-Z listing or such), adding a click tracking callback is probably not a good idea.
A click tracking callback would typically be applied as value for the "onclick" and "onkeypress" attributes of a search hit link.
When rendering links to search hits with the LinkRenderer
, apply the click tracking callback via
LinkRenderer.setOnclick(String)
String getClickTrackingUri()
Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2023 Sitevision AB, all rights reserved.