Copyright© 2008-2020 SiteVision AB, all rights reserved.
@Requireable(value="QueryStringUtil") public interface QueryStringUtil
An instance of the SiteVision class implementing this interface can be obtained via
SearchFactory.getQueryStringUtil()
.
See SearchFactory
for how to obtain
an instance of the SearchFactory
interface.
Modifier and Type | Method and Description |
---|---|
String |
getDateAsString(Date aDate)
Returns a date formatted according to the Solr date string representation.
|
String |
getFieldQuery(String aFieldName,
String aValueExpression)
Returns a field query that is properly grouped.
|
String |
removeQuerySyntaxChars(String aQueryString)
Removes query syntax characters from a query string and trims the result.
|
String |
splitCollectionToQueryParts(Collection<String> aStringsToSplit,
String aSplitExpression)
Transforms multiple strings with delimiters to a string that could be used in a field-grouped query expression.
|
String |
splitToQueryParts(String aStringToSplit,
String aSplitExpression)
Transforms a string with delimiters to a string that could be used in a field-grouped query expression.
|
String removeQuerySyntaxChars(String aQueryString)
Current syntax characters are:
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
"ma?nus" -> "manus"
"ma&&nus" -> "ma&nus"
and "ma||nus" -> "ma|nus"
"This is *so* funny!" -> "This is so funny"
Example: "(Site?Vision: *Enterprise)?" -> "SiteVision Enterprise"
aQueryString
- a non-null query anExpressionnull
if aQueryString
is null
String splitToQueryParts(String aStringToSplit, String aSplitExpression)
This is a convenience method when you want to query something based on items in a string that are delimited by some token. A typical example is a "keyword" metadata that contains multiple keywords delimited by a comma char.
This method splits the aStringToSplit
with the aSplitExpression
and each part is
then trimmed and appended to the resulting string, separated with a space. Parts that contains a space char
is quoted.
aStringToSplit | aSplitExpression | Returned |
---|---|---|
"one" | "," | one |
"one,two" | "," | one two |
"one, two" | "," | one two |
"one, two, three four" | "," | one two "three four" |
"one" | "aNonMatchingExpression" | one |
"one,two" | "aNonMatchingExpression" | one,two |
"one, two" | "aNonMatchingExpression" | "one, two" |
"one, two, three four" | "aNonMatchingExpression" | "one, two, three four" |
null | "," | null |
null | null | null |
"one" | null | one |
"one,two" | null | one,two |
"one, two" | null | one, two |
"one, two, three four" | null | one, two, three four |
aStringToSplit
- the string that should be transformedaSplitExpression
- the regular expression to split up aStringToSplit
in partsaStringToSplit
is null
, null
will always be returned.
if aSplitExpression
is null
, aStringToSplit
will always be returned.
if aSplitExpression
is a non-matching expression, a trimmed aStringToSplit
will
always be returned, and it will be quoted if aStringToSplit
contains a space char.String splitCollectionToQueryParts(Collection<String> aStringsToSplit, String aSplitExpression)
This is a convenience method that executes splitToQueryParts(String, String)
for a collection of strings
and appends each returned value to a combined result, separated with a space. Whitespace only or null
values will be ignored.
See splitToQueryParts(String, String)
how each string of the collection will be transformed.
aStringsToSplit
- a collection of stringsaSplitExpression
- the regular expression to split up the strings in the aStringsToSplit
collection in partssplitToQueryParts(String, String)
operation for all strings in aStringsToSplit
.
if aStringsToSplit
is null
or empty, null
will always be returned.splitToQueryParts(String, String)
String getFieldQuery(String aFieldName, String aValueExpression)
This method trims the aValueExpression
and analyzes the space-separated parts, quoted and unquoted.
The result will be a grouped field query if there are multiple parts in aValueExpression
and a
non-grouped field query if there are only one part in aValueExpression
.
Note that this is a convenience method only. Neither field or value will be syntactically checked in any way. The caller of this method is responsible for passing values that the query parser used later on will accept.
aFieldName | aValueExpression | Returned |
---|---|---|
content.analyzed |
sitevision |
content.analyzed:sitevision |
+content.analyzed |
sitevision* |
+content.analyzed:sitevision* |
-content.analyzed |
enterprise |
-content.analyzed:enterprise |
content.analyzed |
"sitevision enterprise" |
content.analyzed:"sitevision enterprise" |
content.analyzed |
sitevision enterprise |
content.analyzed:(sitevision enterprise) |
content.analyzed |
portal "sitevision enterprise" |
content.analyzed:(portal "sitevision enterprise") |
aFieldName
- the field expressionaValueExpression
- the value expressionnull
will be returned if aFieldName
or
aValueExpression
is null
or whitespace only.String getDateAsString(Date aDate)
All dates in Solr (Lucene) are stored using UTC (zulu time 'Z'). When a date is converted to a string that should be sent to Solr (for example as a part of a query) the timezone must be taken into consideration since no adjustments will be performed by the query parser.
aDate
- the dateSiteVision - 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-2020 SiteVision AB, all rights reserved.