Copyright© 2008-2018 SiteVision AB, all rights reserved.
@Requireable(value="SearchUtil") public interface SearchUtil
Convenience interface for querying the default index.
Note! This interface contains convenience methods for basic search in the default index.
When more powerful search behaviour is needed - use Searcher
instead!
Actually, you can always use Searcher, but not always SearchUtil.
Examples of when you must use Searcher
instead is:
Query syntax note! Query strings should be expressed according to the Solr query syntax.
The syntax is basically the
Lucene query syntax
with some minor differences.
Also note that a general recommendation is to always use the prefix operators (+
/-
) instead of the
boolean keywords (AND/OR/NOT)
to avoid unexpected behaviour. For deeper understanding, see for example
Why Not AND, OR, And NOT?.
An instance of the SiteVision class implementing this interface can be obtained via Utils.getSearchUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Searcher
Modifier and Type | Method and Description |
---|---|
SearchResult |
search(String aQuery,
java.util.List<SearchSortField> sortFields,
int aStartAtHit,
int aMaxHitsToReturn)
Searches the default index using the multi-field ("edismax") parser.
|
SearchResult |
search(String aQuery,
String aFieldName,
java.util.List<SearchSortField> sortFields,
int aStartAtHit,
int aMaxHitsToReturn)
Searches the default index using the single-field ("standard") parser with a specified default field.
|
SearchResult search(String aQuery, java.util.List<SearchSortField> sortFields, int aStartAtHit, int aMaxHitsToReturn)
Searches the default index using the multi-field ("edismax") parser.
Here is a simple example written in server-side javascript:
var searchUtil = request.getAttribute("sitevision.utils").getSearchUtil();
var result = searchUtil.search("test*", null, 0, 10);
if (result.hasHits()) {
out.println("Approximate hit count: " + result.getApproximateCount() + "<br/>");
var hits = result.getHits();
while (hits.hasNext()) {
var hit = hits.next();
out.print("<a href=\"" + hit.getField('uri') + "\" title=\"\">");
out.print(hit.getField('title'));
out.print("</a>");
out.println("<br/>");
}
} else {
out.println("No hits for query = '" + result.getQuery() + "'<br/>");
}
aQuery
- The search query according to the Solr query syntaxsortFields
- A List
of SearchSortField
objects. May be null
.aStartAtHit
- number of leading hits to be skippedaMaxHitsToReturn
- maximum total number of hits to be returnedSearchResult
and is never null
SearchResult search(String aQuery, String aFieldName, java.util.List<SearchSortField> sortFields, int aStartAtHit, int aMaxHitsToReturn)
Searches the default index using the single-field ("standard") parser with a specified default field.
aQuery
- The search query according to the Solr query syntaxaFieldName
- name of the field that should be queriedsortFields
- A List
of SearchSortField
objects. May be null
.aStartAtHit
- number of leading hits to be skippedaMaxHitsToReturn
- maximum total number of hits to be returnedSearchResult
and is never null
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-2018 SiteVision AB, all rights reserved.