Package io.goobi.viewer.model.search
Class SearchHelper
java.lang.Object
io.goobi.viewer.model.search.SearchHelper
Search utility class. Static methods only.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
Standard Solr query for all records and anchors.static final String
static final String
ConstantDEFAULT_DOCSTRCT_WHITELIST_FILTER_QUERY="(ISWORK:true OR ISANCHOR:true) AND NOT("{trunked}
static final String
static final String
ConstantFUZZY_SEARCH_TERM_TEMPLATE="String prefix, String suffix"
.static final String
ConstantFUZZY_SEARCH_TERM_TEMPLATE_WITH_BOOST="String prefix, String suffix"
.static final String
ConstantPARAM_NAME_FILTER_QUERY_SUFFIX="filterQuerySuffix"
static final Pattern
static final String
ConstantPLACEHOLDER_HIGHLIGHTING_END="##HLE##"
static final String
ConstantPLACEHOLDER_HIGHLIGHTING_START="##HLS##"
static final SearchFilter
ConstantSEARCH_FILTER_ALL
static final String
static final String
ConstantSEARCH_TERM_SPLIT_REGEX
static final int
ConstantSEARCH_TYPE_ADVANCED=1
static final int
ConstantSEARCH_TYPE_CALENDAR=3
static final int
ConstantSEARCH_TYPE_REGULAR=0
static final int
ConstantSEARCH_TYPE_TERMS=4
static final int
ConstantSEARCH_TYPE_TIMELINE=2
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
addFuzzySearchToken
(String term, int distance, String prefix, String suffix) static String
addFuzzySearchToken
(String term, String prefix, String suffix) Adds a fuzzy search token to the given term.static String
addProximitySearchToken
(String term, int distance) static String
applyHighlightingToPhrase
(String phrase, Set<String> terms) Adds highlighting markup for all given terms to the phrase.static String
boolifyField
(String fieldName) boolifyField.static String
buildExpandQueryFromFacets
(List<String> allFacetQueries, List<String> allowedFacetQueryRegexes) Constructs an expand query from given facet queries.static String
buildFinalQuery
(String rawQuery, boolean boostTopLevelDocstructs, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.static String
buildFinalQuery
(String rawQuery, boolean boostTopLevelDocstructs, javax.servlet.http.HttpServletRequest request, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.static String
buildTermQuery
(Collection<String> searchTerms) static String
buildTermQuery
(Collection<String> searchTerms, boolean addOperators) protected static boolean
checkCollectionInBlacklist
(String dc, Set<String> blacklist, String splittingChar) Matches given collection name against the given collection blacklist.static String
cleanUpSearchTerm
(String term) Removes illegal characters from an individual search term.collectAvailableTermFilters
(BrowsingMenuFieldConfig bmfc, String filterQuery, Locale locale) Generates starting character filters for term browsing, using facets.static boolean
if maxDistance <= 0, or either phrase or term is blank, simply returnStringUtils.contains(phrase, term)
.static String
defacetifyField
(String fieldName) defacetifyField.static void
exportSearchAsExcel
(org.apache.poi.xssf.streaming.SXSSFWorkbook wb, String finalQuery, String exportQuery, List<StringPair> sortFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, Locale locale, int proximitySearchDistance) exportSearchAsExcel.static int
extractSearchTermsFromQuery
(String query, String discriminatorValue) Parses the given Solr query for field values and returns them as a set of strings.static String
facetifyField
(String fieldName) facetifyField.facetifyList
(List<String> sourceList) facetifyList.static Map<String,
CollectionResult> findAllCollectionsFromField
(String luceneField, String groupingField, String filterQuery, boolean filterForWhitelist, boolean filterForBlacklist, String splittingChar) Returns a Map with hierarchical values from the given field and their respective record counts.static String
generateAdvancedExpandQuery
(SearchQueryGroup group, boolean allowFuzzySearch) Creates a Solr expand query string out of advanced search query item groups.protected static String
Generates a Solr query suffix that filters out values for the given field that are configured as blacklisted.static String
generateExpandQuery
(List<String> fields, Map<String, Set<String>> searchTerms, boolean phraseSearch, int proximitySearchDistance) Creates a Solr expand query string out of lists of fields and terms.generateQueryParams
(String termQuery) generateQueryParams.static String
Returns all suffixes relevant to search filtering.static String
getAllSuffixes
(javax.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.static String
getAllSuffixes
(javax.servlet.http.HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.static String
getAllSuffixes
(javax.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) static String
Returns all suffixes relevant to search filtering.static BrowseElement
getBrowseElement
(String query, int index, List<StringPair> sortFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, Locale locale, int proximitySearchDistance) Returns theBrowseElement
constructed from the search hit atindex
from the search hit list for the givenquery
.static String
Returns a Solr query suffix that filters out collections defined in the collection blacklist.static String
getDiscriminatorFieldFilterSuffix
(NavigationHelper nh, String discriminatorField) getDiscriminatorFieldFilterSuffix.getExpandQueryFieldList
(int searchType, SearchFilter searchFilter, SearchQueryGroup queryGroup, List<String> additionalFields) getExpandQueryFieldList.getExpandQueryParams
(String expandQuery) getFacetValues
(String query, String facetFieldName, int facetMinCount) Returns a list of values for a given facet field and the given query.getFacetValues
(String query, String facetFieldName, String facetPrefix, int facetMinCount, Map<String, String> params) Returns a list of values for a given facet field and the given query.static List<BrowseTerm>
getFilteredTerms
(BrowsingMenuFieldConfig bmfc, String startsWith, String filterQuery, int start, int rows, Comparator<BrowseTerm> comparator, String language) Returns a list of index terms for the given field name.static int
getFilteredTermsCount
(BrowsingMenuFieldConfig bmfc, String startsWith, String filterQuery, String language) static StringPair
getFirstRecordPiAndPageType
(String luceneField, String value, boolean filterForWhitelist, boolean filterForBlacklist, String splittingChar) getFirstRecordMetadataWithFieldValue.static HitType
getHitType
(org.apache.solr.common.SolrDocument doc) Return theHitType
matching theSolrConstants.DOCTYPE
of the given document.static int[]
getMinMaxYears
(String subQuery) getMinMaxYears.static String
static String
getPersonalFilterQuerySuffix
(List<LicenseType> licenseTypes, User user, String ipAddress, Optional<ClientApplication> client, String privilege) Constructs a personal search query filter suffix for the given user and IP address.static String
getQueryForAccessCondition
(String accessCondition, boolean escapeAccessCondition) static String[]
getWildcardsTokens
(String term) Separate leading and trailing wildcard token ('*') from the actual term and return an array of length 3 with the values [leadingWildCard, tokenWithoutWildcards, trailingWildcard] If leading/trailing wildcards are missing, the corresponding array entries are empty stringsstatic boolean
Determines whether the given string is a quoted search phrase, optionally with a proximity distance.static String
normalizeField
(String fieldName) static SearchQueryGroup
parseSearchQueryGroupFromQuery
(String query, String facetString, String template, String language) static List<StringPair>
parseSortString
(String sortString, NavigationHelper navigationHelper) parseSortString.static String
prepareQuery
(String query) prepareQuery.static String
prepareQuery
(String query, String docstructWhitelistFilterQuery) Puts non-empty queries into parentheses and replaces empty queries with a top level record-only query (for collection listing).static String
removeHighlightingPlaceholders
(String phrase) static String
static String
removeTruncation
(String value) Remove '*' at the start or end of the given valuestatic String
replaceHighlightingPlaceholders.searchAutosuggestion
(String suggest, List<IFacetItem> currentFacets) search method for auto suggestion First search in field "DEFAULT" and analyze values tokenized, check with startsWith Then search in field "TITLE" and check with containsstatic org.apache.solr.client.solrj.response.QueryResponse
searchCalendar
(String query, List<String> facetFields, int facetMinCount, boolean getFieldStatistics) searchCalendar.searchWithAggregation
(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, List<String> exportFields, String additionalMetadataListType, Locale locale, boolean keepSolrDoc, int proximitySearchDistance) Main search method for aggregated search.searchWithFulltext
(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, List<String> exportFields, Locale locale, boolean keepSolrDoc, int proximitySearchDistance) Main search method for flat search.searchWithFulltext
(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, List<String> exportFields, Locale locale, int proximitySearchDistance) Main search method for flat search.static String
sortifyField
(String fieldName) sortifyField.truncateFulltext
(Set<String> searchTerms, String inFulltext, int targetFragmentLength, boolean firstMatchOnly, boolean addFragmentIfNoMatches, int proximitySearchDistance) TODO This method might be quite expensive.static void
updateFilterQuerySuffix
(javax.servlet.http.HttpServletRequest request, String privilege) Updates the calling agent's session with a personalized filter sub-query.
-
Field Details
-
PARAM_NAME_FILTER_QUERY_SUFFIX
ConstantPARAM_NAME_FILTER_QUERY_SUFFIX="filterQuerySuffix"
- See Also:
-
SEARCH_TERM_SPLIT_REGEX
ConstantSEARCH_TERM_SPLIT_REGEX
- See Also:
-
PLACEHOLDER_HIGHLIGHTING_START
ConstantPLACEHOLDER_HIGHLIGHTING_START="##HLS##"
- See Also:
-
PLACEHOLDER_HIGHLIGHTING_END
ConstantPLACEHOLDER_HIGHLIGHTING_END="##HLE##"
- See Also:
-
SEARCH_TYPE_REGULAR
public static final int SEARCH_TYPE_REGULARConstantSEARCH_TYPE_REGULAR=0
- See Also:
-
SEARCH_TYPE_ADVANCED
public static final int SEARCH_TYPE_ADVANCEDConstantSEARCH_TYPE_ADVANCED=1
- See Also:
-
SEARCH_TYPE_TIMELINE
public static final int SEARCH_TYPE_TIMELINEConstantSEARCH_TYPE_TIMELINE=2
- See Also:
-
SEARCH_TYPE_CALENDAR
public static final int SEARCH_TYPE_CALENDARConstantSEARCH_TYPE_CALENDAR=3
- See Also:
-
SEARCH_TYPE_TERMS
public static final int SEARCH_TYPE_TERMSConstantSEARCH_TYPE_TERMS=4
- See Also:
-
SEARCH_FILTER_ALL
ConstantSEARCH_FILTER_ALL
-
SEARCH_FILTER_ALL_FIELD
- See Also:
-
TITLE_TERMS
- See Also:
-
AGGREGATION_QUERY_PREFIX
- See Also:
-
BOOSTING_QUERY_TEMPLATE
- See Also:
-
EMBEDDED_QUERY_TEMPLATE
- See Also:
-
ALL_RECORDS_QUERY
Standard Solr query for all records and anchors.- See Also:
-
DEFAULT_DOCSTRCT_WHITELIST_FILTER_QUERY
ConstantDEFAULT_DOCSTRCT_WHITELIST_FILTER_QUERY="(ISWORK:true OR ISANCHOR:true) AND NOT("{trunked}
- See Also:
-
FUZZY_SEARCH_TERM_TEMPLATE_WITH_BOOST
ConstantFUZZY_SEARCH_TERM_TEMPLATE_WITH_BOOST="String prefix, String suffix"
. {t} is the actual search term, {d} the maximal edit distance to search. {p} and {s} are prefix and suffix to be applied to the search term- See Also:
-
FUZZY_SEARCH_TERM_TEMPLATE
ConstantFUZZY_SEARCH_TERM_TEMPLATE="String prefix, String suffix"
. {t} is the actual search term, {d} the maximal edit distance to search.- See Also:
-
PATTERN_ALL_ITEMS
-
-
Method Details
-
searchWithFulltext
public static List<SearchHit> searchWithFulltext(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, throws PresentationException, IndexUnreachableException, DAOException, ViewerConfigurationExceptionSet<String>> searchTerms, List<String> exportFields, Locale locale, int proximitySearchDistance) Main search method for flat search.- Parameters:
query
-String
Solr search query. Merges full-text and metadata hits into their corresponding docstructs.first
-Integer
First row indexrows
-Integer
Number of rows to returnsortFields
- aList
object.resultFields
- aList
object.filterQueries
- aList
object.params
- aMap
object.searchTerms
- aMap
object.exportFields
- aList
object.locale
- aLocale
object.proximitySearchDistance
-- Returns:
- List of
StructElement
s containing the search hits. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.DAOException
- if any.ViewerConfigurationException
- if any.
-
searchWithFulltext
public static List<SearchHit> searchWithFulltext(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, throws PresentationException, IndexUnreachableException, DAOExceptionSet<String>> searchTerms, List<String> exportFields, Locale locale, boolean keepSolrDoc, int proximitySearchDistance) Main search method for flat search.- Parameters:
query
-String
Solr search query. Merges full-text and metadata hits into their corresponding docstructs.first
-Integer
vonrows
-Integer
bissortFields
- aList
object.resultFields
- aList
object.filterQueries
- aList
object.params
- aMap
object.searchTerms
- aMap
object.exportFields
- aList
object.locale
- aLocale
object.keepSolrDoc
-proximitySearchDistance
-- Returns:
- List of
StructElement
s containing the search hits. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.DAOException
- if any.
-
searchWithAggregation
public static List<SearchHit> searchWithAggregation(String query, int first, int rows, List<StringPair> sortFields, List<String> resultFields, List<String> filterQueries, Map<String, String> params, Map<String, throws PresentationException, IndexUnreachableException, DAOException, ViewerConfigurationExceptionSet<String>> searchTerms, List<String> exportFields, String additionalMetadataListType, Locale locale, boolean keepSolrDoc, int proximitySearchDistance) Main search method for aggregated search.- Parameters:
query
-String
Solr search query. Merges full-text and metadata hits into their corresponding docstructs.first
-Integer
First hit indexrows
-Integer
Number of hits to returnsortFields
- aList
object.resultFields
- aList
object.filterQueries
- aList
object.params
- aMap
object.searchTerms
- aMap
object.exportFields
- aList
object.additionalMetadataListType
- Optional addtional metadata list type, to be used on alternative search hit views, etc.locale
- aLocale
object.keepSolrDoc
-proximitySearchDistance
-- Returns:
- List of
StructElement
s containing the search hits. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.DAOException
- if any.ViewerConfigurationException
- if any.
-
getHitType
Return theHitType
matching theSolrConstants.DOCTYPE
of the given document. In case the document is of type 'UGC', return the type matchingSolrConstants.UGCTYPE
instead- Parameters:
doc
-- Returns:
HitType
for doc
-
getAllSuffixes
Returns all suffixes relevant to search filtering.- Returns:
- a
String
object.
-
getAllSuffixes
public static String getAllSuffixes(javax.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.- Parameters:
request
- aHttpServletRequest
object.addStaticQuerySuffix
- a boolean.addCollectionBlacklistSuffix
- a boolean.- Returns:
- Generated Solr query suffix
-
getAllSuffixes
public static String getAllSuffixes(javax.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) - Parameters:
request
- aHttpServletRequest
object.addStaticQuerySuffix
- a boolean.addCollectionBlacklistSuffix
- a boolean.privilege
- Privilege to check (Connector checks a different privilege)- Returns:
- Generated Solr query suffix
-
getAllSuffixes
public static String getAllSuffixes(javax.servlet.http.HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.- Parameters:
request
- aHttpServletRequest
object.addArchiveFilterSuffix
- a boolean.addCollectionBlacklistSuffix
- a boolean.privilege
- Privilege to check (Connector checks a different privilege)addStaticQuerySuffix
- if true, add the configured static query suffix to the query- Returns:
- Generated Solr query suffix
-
getAllSuffixesExceptCollectionBlacklist
Returns all suffixes relevant to search filtering.- Returns:
- a
String
object.
-
getBrowseElement
public static BrowseElement getBrowseElement(String query, int index, List<StringPair> sortFields, List<String> filterQueries, Map<String, String> params, Map<String, throws PresentationException, IndexUnreachableException, DAOException, ViewerConfigurationExceptionSet<String>> searchTerms, Locale locale, int proximitySearchDistance) Returns theBrowseElement
constructed from the search hit atindex
from the search hit list for the givenquery
.- Parameters:
query
- aString
object.index
- a int.sortFields
- aList
object.params
- aMap
object.searchTerms
- aMap
object.locale
- aLocale
object.proximitySearchDistance
-filterQueries
- aList
object.- Returns:
- a
BrowseElement
object. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.DAOException
- if any.ViewerConfigurationException
- if any.
-
getFirstRecordPiAndPageType
public static StringPair getFirstRecordPiAndPageType(String luceneField, String value, boolean filterForWhitelist, boolean filterForBlacklist, String splittingChar) throws IndexUnreachableException, PresentationException getFirstRecordMetadataWithFieldValue.
- Parameters:
luceneField
- aString
object.value
- aString
object.filterForWhitelist
- a boolean.filterForBlacklist
- a boolean.splittingChar
- aString
object.- Returns:
- StringPair containing the PI and the target page type of the first record.
- Throws:
IndexUnreachableException
- if any.PresentationException
- if any.
-
findAllCollectionsFromField
public static Map<String,CollectionResult> findAllCollectionsFromField(String luceneField, String groupingField, String filterQuery, boolean filterForWhitelist, boolean filterForBlacklist, String splittingChar) throws IndexUnreachableException Returns a Map with hierarchical values from the given field and their respective record counts. Results are filtered by AccessConditions available for current HttpRequest- Parameters:
luceneField
- the SOLR field over which to build the collections (typically "DC")groupingField
-filterQuery
- An addition solr-query to filer collections by.filterForWhitelist
- a boolean.filterForBlacklist
- a boolean.splittingChar
- Character used for separating collection hierarchy levels within a collection name (typically ".")- Returns:
- a
Map
object. - Throws:
IndexUnreachableException
- if any.
-
checkCollectionInBlacklist
protected static boolean checkCollectionInBlacklist(String dc, Set<String> blacklist, String splittingChar) Matches given collection name against the given collection blacklist. Also matches wildcards and child collections. -
searchCalendar
public static org.apache.solr.client.solrj.response.QueryResponse searchCalendar(String query, List<String> facetFields, int facetMinCount, boolean getFieldStatistics) throws PresentationException, IndexUnreachableException searchCalendar.
- Parameters:
query
- aString
object.facetFields
- aList
object.facetMinCount
- a int.getFieldStatistics
- a boolean.- Returns:
- a
QueryResponse
object. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
getMinMaxYears
public static int[] getMinMaxYears(String subQuery) throws PresentationException, IndexUnreachableException getMinMaxYears.
- Parameters:
subQuery
- aString
object.- Returns:
- int[]
- Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
searchAutosuggestion
public static List<String> searchAutosuggestion(String suggest, List<IFacetItem> currentFacets) throws IndexUnreachableException search method for auto suggestion- First search in field "DEFAULT" and analyze values tokenized, check with startsWith
- Then search in field "TITLE" and check with contains
- Parameters:
suggest
- the search stringcurrentFacets
- aList
object.- Returns:
- a
List
object. - Throws:
IndexUnreachableException
- if any.
-
getCollectionBlacklistFilterSuffix
Returns a Solr query suffix that filters out collections defined in the collection blacklist. -
generateCollectionBlacklistFilterSuffix
Generates a Solr query suffix that filters out values for the given field that are configured as blacklisted. This isn't an expensive method, so the suffix is generated anew upon every call and not persisted. -
updateFilterQuerySuffix
public static void updateFilterQuerySuffix(javax.servlet.http.HttpServletRequest request, String privilege) throws IndexUnreachableException, PresentationException, DAOException Updates the calling agent's session with a personalized filter sub-query.- Parameters:
request
- aHttpServletRequest
object.privilege
- Privilege to check (Connector checks a different privilege)- Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.
-
getPersonalFilterQuerySuffix
public static String getPersonalFilterQuerySuffix(List<LicenseType> licenseTypes, User user, String ipAddress, Optional<ClientApplication> client, String privilege) throws IndexUnreachableException, PresentationException, DAOException Constructs a personal search query filter suffix for the given user and IP address.- Parameters:
licenseTypes
-user
- aUser
object.ipAddress
- aString
object.client
-privilege
- Privilege to check (Connector checks a different privilege)- Returns:
- a
String
object. - Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.
-
getMovingWallQuery
- Returns:
- Solr query for the moving wall date range
-
truncateFulltext
public static List<String> truncateFulltext(Set<String> searchTerms, String inFulltext, int targetFragmentLength, boolean firstMatchOnly, boolean addFragmentIfNoMatches, int proximitySearchDistance) TODO This method might be quite expensive.- Parameters:
searchTerms
- aSet
object.inFulltext
- aString
object.targetFragmentLength
- Desired (approximate) length of the text fragment.firstMatchOnly
- If true, only the fragment for the first match will be returnedaddFragmentIfNoMatches
- If true, a fragment will be added even if no term was matchedproximitySearchDistance
-- Returns:
- a
List
object.
-
applyHighlightingToPhrase
Adds highlighting markup for all given terms to the phrase. -
contains
if maxDistance <= 0, or either phrase or term is blank, simply returnStringUtils.contains(phrase, term)
. Otherwise check if the phrase contains a word which has a Damerau-Levenshtein distance of at most maxDistance to the term- Parameters:
phrase
-term
-maxDistance
-- Returns:
- true if phrase contains term within maxDistance; false otherwise
-
replaceHighlightingPlaceholders
replaceHighlightingPlaceholders.
-
removeHighlightingPlaceholders
- Parameters:
phrase
-- Returns:
- phrase without highlighting placeholders
-
getFacetValues
public static List<String> getFacetValues(String query, String facetFieldName, int facetMinCount) throws PresentationException, IndexUnreachableException Returns a list of values for a given facet field and the given query.- Parameters:
query
- aString
object.facetFieldName
- aString
object.facetMinCount
- a int.- Returns:
- a
List
object. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
getFacetValues
public static List<String> getFacetValues(String query, String facetFieldName, String facetPrefix, int facetMinCount, Map<String, String> params) throws PresentationException, IndexUnreachableExceptionReturns a list of values for a given facet field and the given query.- Parameters:
query
- aString
object.facetFieldName
- aString
object.facetPrefix
- The facet field value must start with these characters. Ignored if null or blankfacetMinCount
- a int.params
-- Returns:
- a
List
object. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
getFilteredTermsCount
public static int getFilteredTermsCount(BrowsingMenuFieldConfig bmfc, String startsWith, String filterQuery, String language) throws PresentationException, IndexUnreachableException - Parameters:
bmfc
-startsWith
-filterQuery
-language
-- Returns:
- Number of found terms
- Throws:
PresentationException
IndexUnreachableException
-
collectAvailableTermFilters
public static List<String> collectAvailableTermFilters(BrowsingMenuFieldConfig bmfc, String filterQuery, Locale locale) throws PresentationException, IndexUnreachableException Generates starting character filters for term browsing, using facets.- Parameters:
bmfc
-filterQuery
-locale
-- Returns:
- List
- Throws:
PresentationException
IndexUnreachableException
-
getFilteredTerms
public static List<BrowseTerm> getFilteredTerms(BrowsingMenuFieldConfig bmfc, String startsWith, String filterQuery, int start, int rows, Comparator<BrowseTerm> comparator, String language) throws PresentationException, IndexUnreachableException Returns a list of index terms for the given field name. This method uses the slower doc search instead of term search, but can be filtered with a query.- Parameters:
bmfc
- aBrowsingMenuFieldConfig
object.startsWith
- aString
object.filterQuery
- aString
object.start
-rows
-comparator
- aComparator
object.language
- Language for language-specific fields- Returns:
- a
List
object. - Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
extractSearchTermsFromQuery
public static Map<String,Set<String>> extractSearchTermsFromQuery(String query, String discriminatorValue) Parses the given Solr query for field values and returns them as a set of strings. -
parseSearchQueryGroupFromQuery
public static SearchQueryGroup parseSearchQueryGroupFromQuery(String query, String facetString, String template, String language) - Parameters:
query
-facetString
-template
- Advanced search fields templatelanguage
-- Returns:
- Parsed
SearchQueryGroup
-
removeTruncation
Remove '*' at the start or end of the given value- Parameters:
value
-- Returns:
- value without truncation
-
generateQueryParams
generateQueryParams.
- Parameters:
termQuery
-- Returns:
- a
Map
object.
-
facetifyList
facetifyList.
-
facetifyField
facetifyField.
-
sortifyField
sortifyField.
-
boolifyField
boolifyField.
-
normalizeField
- Parameters:
fieldName
-- Returns:
- Normalized fieldName
-
defacetifyField
defacetifyField.
-
generateExpandQuery
public static String generateExpandQuery(List<String> fields, Map<String, Set<String>> searchTerms, boolean phraseSearch, int proximitySearchDistance) Creates a Solr expand query string out of lists of fields and terms. -
generateAdvancedExpandQuery
Creates a Solr expand query string out of advanced search query item groups.- Parameters:
group
-allowFuzzySearch
-- Returns:
- a
String
object.
-
getExpandQueryFieldList
public static List<String> getExpandQueryFieldList(int searchType, SearchFilter searchFilter, SearchQueryGroup queryGroup, List<String> additionalFields) getExpandQueryFieldList.
- Parameters:
searchType
- a int.searchFilter
- aSearchFilter
object.queryGroup
- aSearchQueryGroup
object.additionalFields
- Optinal additional fields to return- Returns:
- a
List
object.
-
prepareQuery
prepareQuery.
-
prepareQuery
Puts non-empty queries into parentheses and replaces empty queries with a top level record-only query (for collection listing). -
buildTermQuery
- Parameters:
searchTerms
-- Returns:
- Term query from searchTerms
-
buildTermQuery
- Parameters:
searchTerms
-addOperators
-- Returns:
- Term query from searchTerms
-
buildFinalQuery
public static String buildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.- Parameters:
rawQuery
- aString
object.boostTopLevelDocstructs
- If true, query elements for boosting will be addedaggregationType
-SearchAggregationType
- Returns:
- a
String
object. - Throws:
IndexUnreachableException
- if any.
-
buildFinalQuery
public static String buildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, javax.servlet.http.HttpServletRequest request, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.- Parameters:
rawQuery
- aString
object.boostTopLevelDocstructs
- If true, query elements for boosting will be addedrequest
-aggregationType
-SearchAggregationType
- Returns:
- a
String
object.
-
exportSearchAsExcel
public static void exportSearchAsExcel(org.apache.poi.xssf.streaming.SXSSFWorkbook wb, String finalQuery, String exportQuery, List<StringPair> sortFields, List<String> filterQueries, Map<String, String> params, Map<String, throws IndexUnreachableException, DAOException, PresentationException, ViewerConfigurationExceptionSet<String>> searchTerms, Locale locale, int proximitySearchDistance) exportSearchAsExcel.
- Parameters:
wb
-SXSSFWorkbook
to populatefinalQuery
- Complete query with suffixes.exportQuery
- Query constructed from the user's input, without any secret suffixes.sortFields
- aList
object.filterQueries
- aList
object.params
- aMap
object.searchTerms
- aMap
object.locale
- aLocale
object.proximitySearchDistance
-- Throws:
IndexUnreachableException
- if any.DAOException
- if any.PresentationException
- if any.ViewerConfigurationException
- if any.
-
getExpandQueryParams
- Parameters:
expandQuery
-- Returns:
- Map<String, String>
-
cleanUpSearchTerm
Removes illegal characters from an individual search term. Do not use on whole queries!- Parameters:
term
- The term to clean up.- Returns:
- Cleaned up term.
-
getQueryForAccessCondition
public static String getQueryForAccessCondition(String accessCondition, boolean escapeAccessCondition) - Parameters:
accessCondition
-escapeAccessCondition
-- Returns:
- Constructed Solr query
-
addFuzzySearchToken
Adds a fuzzy search token to the given term. The maximal Damerau-Levenshtein is calculated from term length- Parameters:
term
- the search termprefix
-suffix
-- Returns:
- the given term with a fuzzy search token appended
-
addFuzzySearchToken
- Parameters:
term
- the search term. Must be a single worddistance
- the maximum Damerau-Levenshtein distance to a matching word. Must be from 0 to 2, where 0 means no fuzzy searchprefix
-suffix
-- Returns:
- term with fuzzy search token
-
addProximitySearchToken
- Parameters:
term
-distance
-- Returns:
String
-
removeProximitySearchToken
- Parameters:
term
- Search term containing proximity search token- Returns:
- term without proximity search token
-
extractProximitySearchDistanceFromQuery
- Parameters:
query
-- Returns:
- Extracted search distance
-
isPhrase
Determines whether the given string is a quoted search phrase, optionally with a proximity distance.- Parameters:
s
- Search terms- Returns:
- true if phrase; false otherwise
-
getWildcardsTokens
Separate leading and trailing wildcard token ('*') from the actual term and return an array of length 3 with the values [leadingWildCard, tokenWithoutWildcards, trailingWildcard] If leading/trailing wildcards are missing, the corresponding array entries are empty strings- Parameters:
term
-- Returns:
- array of prefix, token, suffix
-
buildExpandQueryFromFacets
public static String buildExpandQueryFromFacets(List<String> allFacetQueries, List<String> allowedFacetQueryRegexes) Constructs an expand query from given facet queries. Constrains the query to DOCSTRCT doc types only.- Parameters:
allFacetQueries
-allowedFacetQueryRegexes
- Optional list containing regexes for allowed facet queries- Returns:
- Expand query
-