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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringStandard Solr query for all records and anchors.static final Stringstatic final StringConstantDEFAULT_DOCSTRCT_WHITELIST_FILTER_QUERY="(ISWORK:true OR ISANCHOR:true) AND NOT("{trunked}.static final Stringstatic final StringConstantFUZZY_SEARCH_TERM_TEMPLATE="String prefix, String suffix".static final StringConstantFUZZY_SEARCH_TERM_TEMPLATE_WITH_BOOST="String prefix, String suffix".static final StringConstantPARAM_NAME_FILTER_QUERY_SUFFIX="filterQuerySuffix".static final Patternstatic final StringConstantPLACEHOLDER_HIGHLIGHTING_END="##HLE##".static final StringConstantPLACEHOLDER_HIGHLIGHTING_START="##HLS##".static final StringConstant that matches strings enclosed by double quotes (and optional replacement tags @).static final SearchFilterConstantSEARCH_FILTER_ALL.static final Stringstatic final StringConstantSEARCH_TERM_SPLIT_REGEX.static final StringRegex for splitting search values (including colons).static final intConstantSEARCH_TYPE_ADVANCED=1.static final intConstantSEARCH_TYPE_CALENDAR=3.static final intConstantSEARCH_TYPE_REGULAR=0.static final intConstantSEARCH_TYPE_TERMS=4.static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddFuzzySearchToken(String term, int distance, String prefix, String suffix) static StringaddFuzzySearchToken(String term, String prefix, String suffix) Adds a fuzzy search token to the given term.static StringaddProximitySearchToken(String term, int distance) static StringapplyHighlightingToPhrase(String phrase, Set<String> terms) Adds highlighting markup for all given terms to the phrase.static StringboolifyField(String fieldName) boolifyField.static StringbuildExpandQueryFromFacets(List<String> allFacetQueries, List<String> allowedFacetQueryRegexes) Constructs an expand query from given facet queries.static StringbuildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.static StringbuildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, HttpServletRequest request, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.static StringbuildTermQuery(Collection<String> searchTerms) static StringbuildTermQuery(Collection<String> searchTerms, boolean addOperators) protected static booleancheckCollectionInBlacklist(String dc, Set<String> blacklist, String splittingChar) Matches given collection name against the given collection blacklist.static StringcleanUpSearchTerm(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 booleanif maxDistance <= 0, or either phrase or term is blank, simply returnStringUtils.contains(phrase, term).static StringdefacetifyField(String fieldName) defacetifyField.static voidexportSearchAsExcel(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 intextractSearchTermsFromQuery(String query, String discriminatorValue) Parses the given Solr query for field values and returns them as a set of strings.static StringfacetifyField(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 StringgenerateAdvancedExpandQuery(SearchQueryGroup group, boolean allowFuzzySearch) Creates a Solr expand query string out of advanced search query item groups.protected static StringGenerates a Solr query suffix that filters out values for the given field that are configured as blacklisted.static StringgenerateExpandQuery(List<String> fields, Map<String, Set<String>> searchTerms, int proximitySearchDistance) Creates a Solr expand query string out of lists of fields and terms.generateQueryParams(String termQuery) generateQueryParams.static StringReturns all suffixes relevant to search filtering.static StringgetAllSuffixes(HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.static StringgetAllSuffixes(HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.static StringgetAllSuffixes(HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) static StringReturns all suffixes relevant to search filtering.static BrowseElementgetBrowseElement(String query, int index, List<StringPair> sortFields, List<String> filterQueries, Map<String, String> params, Map<String, Set<String>> searchTerms, Locale locale, int proximitySearchDistance) Returns theBrowseElementconstructed from the search hit atindexfrom the search hit list for the givenquery.static StringReturns a Solr query suffix that filters out collections defined in the collection blacklist.static StringgetDiscriminatorFieldFilterSuffix(NavigationHelper nh, String discriminatorField) getDiscriminatorFieldFilterSuffix.getExpandQueryFieldList(int searchType, SearchFilter searchFilter, SearchQueryGroup queryGroup, List<String> additionalFields) getExpandQueryFieldList.getExpandQueryParams(String expandQuery) getExpandQueryParams(String expandQuery, Integer maxHits) 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 intgetFilteredTermsCount(BrowsingMenuFieldConfig bmfc, String startsWith, String filterQuery, String language) static StringPairgetFirstRecordPiAndPageType(String luceneField, String value, boolean filterForWhitelist, boolean filterForBlacklist, String splittingChar) getFirstRecordMetadataWithFieldValue.static HitTypegetHitType(org.apache.solr.common.SolrDocument doc) Return theHitTypematching theSolrConstants.DOCTYPEof the given document.static int[]getMinMaxYears(String subQuery) getMinMaxYears.static Stringstatic StringgetPersonalFilterQuerySuffix(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 StringgetQueryForAccessCondition(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 strings.static booleanDetermines whether the given string is a quoted search phrase, optionally with a proximity distance.static StringnormalizeField(String fieldName) static SearchQueryGroupparseSearchQueryGroupFromQuery(String query, String facetString, String template, String language) static List<StringPair> parseSortString(String sortString, NavigationHelper navigationHelper) parseSortString.static StringprepareQuery(String query) prepareQuery.static StringprepareQuery(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 StringremoveHighlightingPlaceholders(String phrase) static Stringstatic StringremoveTruncation(String value) Removes '*' at the start or end of the given value.static StringreplaceHighlightingPlaceholders.searchAutosuggestion(String suggest, List<IFacetItem> currentFacets) Search method for auto suggestion.static org.apache.solr.client.solrj.response.QueryResponsesearchCalendar(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.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, User user) 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, boolean keepSolrDoc, int proximitySearchDistance, User user) 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 StringsortifyField(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 StringunquoteValue(String value, boolean containsEscapedDoubleQuotes) Removes outer double quotes from the given value.static voidupdateFilterQuerySuffix(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_QUERY_SPLIT_REGEX
ConstantSEARCH_TERM_SPLIT_REGEX.- See Also:
-
SEARCH_TERM_SPLIT_REGEX
Regex for splitting search values (including colons).- 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_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:
-
REGEX_QUOTATION_MARKS
Constant that matches strings enclosed by double quotes (and optional replacement tags @). May contain escaped double quotes.- 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- Solr search query; merges full-text and metadata hits into their corresponding docstructsfirst- index of the first result (pagination)rows- number of results to returnsortFields- list of sort field/direction pairsresultFields- Solr field names to include in resultsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightingexportFields- field names to include in export metadatalocale- language locale for translationproximitySearchDistance- word distance for proximity search- Returns:
- List of
StructElements 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- Solr search query; merges full-text and metadata hits into their corresponding docstructsfirst- index of the first result (pagination)rows- number of results to returnsortFields- list of sort field/direction pairsresultFields- Solr field names to include in resultsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightingexportFields- field names to include in export metadatalocale- language locale for translationkeepSolrDoc- if true, the raw Solr document is retained in the search hitproximitySearchDistance- word distance for proximity search- Returns:
- List of
StructElements containing the search hits. - Throws:
PresentationException- if any.IndexUnreachableException- if any.DAOException- 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, User user) Main search method for flat search.- Parameters:
query- Solr search query; merges full-text and metadata hits into their corresponding docstructsfirst- index of the first result (pagination)rows- number of results to returnsortFields- list of sort field/direction pairsresultFields- Solr field names to include in resultsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightingexportFields- field names to include in export metadatalocale- language locale for translationkeepSolrDoc- if true, the raw Solr document is retained in the search hitproximitySearchDistance- word distance for proximity searchuser- The user performing the search. Used for calculating thumbnail access conditions. If null, it is fetched from the jsfContext if one exists- Returns:
- List of
StructElements 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- Solr search query; merges full-text and metadata hits into their corresponding docstructsfirst- index of the first result (pagination)rows- number of results to returnsortFields- list of sort field/direction pairsresultFields- Solr field names to include in resultsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightingexportFields- field names to include in export metadataadditionalMetadataListType- Optional addtional metadata list type, to be used on alternative search hit views, etc.locale- language locale for translationkeepSolrDoc- if true, the raw Solr document is retained in the search hitproximitySearchDistance- word distance for proximity search- Returns:
- List of
StructElements containing the search hits. - Throws:
PresentationException- if any.IndexUnreachableException- if any.DAOException- if any.ViewerConfigurationException- 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, User user) Main search method for aggregated search.- Parameters:
query- Solr search query; merges full-text and metadata hits into their corresponding docstructsfirst- index of the first result (pagination)rows- number of results to returnsortFields- list of sort field/direction pairsresultFields- Solr field names to include in resultsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightingexportFields- field names to include in export metadataadditionalMetadataListType- Optional addtional metadata list type, to be used on alternative search hit views, etc.locale- language locale for translationkeepSolrDoc- if true, the raw Solr document is retained in the search hitproximitySearchDistance- word distance for proximity searchuser- The user performing the search. Used for calculating thumbnail access conditions. If null, it is fetched from the jsfContext if one exists- Returns:
- List of
StructElements containing the search hits. - Throws:
PresentationException- if any.IndexUnreachableException- if any.DAOException- if any.ViewerConfigurationException- if any.
-
getHitType
Return theHitTypematching theSolrConstants.DOCTYPEof the given document. In case the document is of type 'UGC', return the type matchingSolrConstants.UGCTYPEinstead- Parameters:
doc- Solr document to determine the hit type for- Returns:
HitTypefor doc
-
getAllSuffixes
Returns all suffixes relevant to search filtering.- Returns:
- generated Solr query suffix string
-
getAllSuffixes
public static String getAllSuffixes(HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.- Parameters:
request- current HTTP servlet requestaddStaticQuerySuffix- if true, append the configured static query suffixaddCollectionBlacklistSuffix- if true, append collection blacklist filter- Returns:
- Generated Solr query suffix
-
getAllSuffixes
public static String getAllSuffixes(HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) - Parameters:
request- current HTTP servlet requestaddStaticQuerySuffix- if true, append the configured static query suffixaddCollectionBlacklistSuffix- if true, append collection blacklist filterprivilege- Privilege to check (Connector checks a different privilege)- Returns:
- Generated Solr query suffix
-
getAllSuffixes
public static String getAllSuffixes(HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.- Parameters:
request- current HTTP servlet requestaddArchiveFilterSuffix- if true, append a filter excluding archive documentsaddStaticQuerySuffix- if true, add the configured static query suffix to the queryaddCollectionBlacklistSuffix- if true, append collection blacklist filterprivilege- Privilege to check (Connector checks a different privilege)- Returns:
- Generated Solr query suffix
-
getAllSuffixesExceptCollectionBlacklist
Returns all suffixes relevant to search filtering.- Returns:
- generated Solr query suffix string without the collection blacklist filter
-
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 theBrowseElementconstructed from the search hit atindexfrom the search hit list for the givenquery.- Parameters:
query- Solr search query stringindex- zero-based index of the desired hit in the result listsortFields- list of sort field/direction pairsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightinglocale- language locale for translationproximitySearchDistance- word distance for proximity search- Returns:
- the BrowseElement for the search result at the given index, or null if no results are found
- 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- Solr field name to search invalue- field value to matchfilterForWhitelist- if true, restrict results to whitelisted document structuresfilterForBlacklist- if true, exclude blacklisted collection valuessplittingChar- character used to separate hierarchy levels in collection values- 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- optional Solr field used to group collection resultsfilterQuery- An addition solr-query to filer collections by.filterForWhitelist- if true, restrict results to whitelisted document structuresfilterForBlacklist- if true, exclude blacklisted collection valuessplittingChar- Character used for separating collection hierarchy levels within a collection name (typically ".")- Returns:
- map of collection names to their aggregated result counts
- 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.- Parameters:
dc- collection name to checkblacklist- set of blacklisted collection name patternssplittingChar- character used to separate hierarchy levels in collection names- Returns:
- true if dc matches any entry in the blacklist; false otherwise
-
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- Solr search query stringfacetFields- list of field names to facet onfacetMinCount- minimum document count for a facet value to be includedgetFieldStatistics- if true, request field statistics in the response- Returns:
- Solr query response with facets and optional statistics
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getMinMaxYears
public static int[] getMinMaxYears(String subQuery) throws PresentationException, IndexUnreachableException getMinMaxYears.- Parameters:
subQuery- optional additional Solr query to filter results- 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 string to suggest completions forcurrentFacets- active facet items used to narrow the suggestion scope- Returns:
- list of matching suggestion strings
- Throws:
IndexUnreachableException- if any.
-
getCollectionBlacklistFilterSuffix
Returns a Solr query suffix that filters out collections defined in the collection blacklist.- Parameters:
field- Solr field name whose blacklisted values should be filtered- Returns:
- Solr query suffix excluding blacklisted values
-
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.- Parameters:
field- Solr field name whose blacklisted values should be filtered- Returns:
- Solr query suffix excluding blacklisted values for the given field
-
updateFilterQuerySuffix
public static void updateFilterQuerySuffix(HttpServletRequest request, String privilege) throws IndexUnreachableException, PresentationException, DAOException Updates the calling agent's session with a personalized filter sub-query.- Parameters:
request- current HTTP servlet request whose session is updatedprivilege- 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- list of all configured license types to evaluateuser- the currently authenticated user, or null for anonymous accessipAddress- IP address of the requesting clientclient- optional client application making the requestprivilege- Privilege to check (Connector checks a different privilege)- Returns:
- Solr query suffix restricting results to records the user may access
- 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- set of terms to find and highlight in the full-textinFulltext- complete full-text string to extract fragments fromtargetFragmentLength- 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- word distance for proximity search- Returns:
- list of text fragments with highlighted search term occurrences
-
applyHighlightingToPhrase
Adds highlighting markup for all given terms to the phrase.- Parameters:
phrase- text to apply highlighting toterms- set of search terms to highlight within the phrase- Returns:
- phrase with highlighting markup around all matched terms
-
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- text to search withinterm- search term to look for in the phrasemaxDistance- maximum allowed Damerau-Levenshtein edit distance (0 = exact match)- Returns:
- true if phrase contains term within maxDistance; false otherwise
-
replaceHighlightingPlaceholders
replaceHighlightingPlaceholders.- Parameters:
phrase- text containing highlighting placeholder markup- Returns:
- phrase with placeholders replaced by HTML mark tags
-
removeHighlightingPlaceholders
- Parameters:
phrase- text containing highlighting placeholder markup- 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- Solr search query stringfacetFieldName- Solr field name to collect facet values fromfacetMinCount- minimum document count for a facet value to be included- Returns:
- list of facet value strings
- 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- Solr search query stringfacetFieldName- Solr field name to collect facet values fromfacetPrefix- The facet field value must start with these characters. Ignored if null or blankfacetMinCount- minimum document count for a facet value to be includedparams- additional Solr query parameters- Returns:
- list of facet value strings
- 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- browsing menu field configuration to querystartsWith- optional prefix to filter terms by first character(s)filterQuery- optional additional Solr filter querylanguage- language code for language-specific fields- Returns:
- Number of found terms
- Throws:
PresentationExceptionIndexUnreachableException
-
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- browsing menu field configuration to queryfilterQuery- optional additional Solr filter querylocale- locale used to select language-specific fields- Returns:
- List
- Throws:
PresentationExceptionIndexUnreachableException
-
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- browsing menu field configuration defining the field to browsestartsWith- optional prefix to filter terms by first character(s)filterQuery- optional additional Solr filter querystart- index of the first result (pagination)rows- maximum number of results to returncomparator- comparator used to sort the resulting browse termslanguage- language code for language-specific fields- Returns:
- list of browse terms matching the given criteria
- 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.- Parameters:
query- Solr query string to parse for field:value pairsdiscriminatorValue- current sub-theme discriminator value to exclude from terms- Returns:
- map of Solr field names to sets of extracted search terms
-
unquoteValue
Removes outer double quotes from the given value.- Parameters:
value- the string value to unquotecontainsEscapedDoubleQuotes- Use true if inner double quotes are already backslash-escaped, false otherwise- Returns:
- value without surrounding quotation marks
-
parseSearchQueryGroupFromQuery
public static SearchQueryGroup parseSearchQueryGroupFromQuery(String query, String facetString, String template, String language) - Parameters:
query- Solr search query string to parsefacetString- serialized facet selection stringtemplate- Advanced search fields templatelanguage- language code for field labels- Returns:
- Parsed
SearchQueryGroup
-
removeTruncation
Removes '*' at the start or end of the given value.- Parameters:
value- search term possibly containing leading or trailing wildcards- Returns:
- value without truncation
-
generateQueryParams
generateQueryParams.- Parameters:
termQuery- term query used to construct the boost query- Returns:
- map of Solr query parameters including the boost query
-
facetifyList
facetifyList.- Parameters:
sourceList- list of Solr field names to convert to facet field names- Returns:
- list of facetified field names * @should facetify correctly
-
facetifyField
facetifyField.- Parameters:
fieldName- Solr field name to convert to a facet field name- Returns:
- field name with the FACET_ prefix applied
-
sortifyField
sortifyField.- Parameters:
fieldName- Solr field name to convert to a sort field name- Returns:
- field name with the SORT_ prefix applied
-
boolifyField
boolifyField.- Parameters:
fieldName- Solr field name to convert to a boolean field name- Returns:
- field name with the BOOL_ prefix applied
-
normalizeField
- Parameters:
fieldName- Solr field name to normalize by removing known prefixes and suffixes- Returns:
- Normalized fieldName
-
defacetifyField
defacetifyField.- Parameters:
fieldName- facetified Solr field name to convert back to its base field name- Returns:
- base field name without the FACET_ prefix
-
generateExpandQuery
public static String generateExpandQuery(List<String> fields, Map<String, Set<String>> searchTerms, int proximitySearchDistance) Creates a Solr expand query string out of lists of fields and terms.- Parameters:
fields- list of Solr field names to include in the expand querysearchTerms- map of field names to sets of search terms for highlightingproximitySearchDistance- word distance for proximity search- Returns:
- Solr expand query string
-
generateAdvancedExpandQuery
Creates a Solr expand query string out of advanced search query item groups.- Parameters:
group- advanced search query group containing the query itemsallowFuzzySearch- if true, fuzzy search tokens are included in the query- Returns:
- Solr expand query string
-
getExpandQueryFieldList
public static List<String> getExpandQueryFieldList(int searchType, SearchFilter searchFilter, SearchQueryGroup queryGroup, List<String> additionalFields) getExpandQueryFieldList.- Parameters:
searchType- integer constant identifying the search type (regular, advanced, calendar, etc.)searchFilter- active search filter determining which fields to expand intoqueryGroup- advanced search query group containing the query itemsadditionalFields- optional additional fields to append to the result- Returns:
- list of Solr field names to use in the expand query
-
prepareQuery
prepareQuery.- Parameters:
query- raw search query string to prepare- Returns:
- prepared query string wrapped in parentheses, or a fallback record-listing query
-
prepareQuery
Puts non-empty queries into parentheses and replaces empty queries with a top level record-only query (for collection listing).- Parameters:
query- raw search query string to preparedocstructWhitelistFilterQuery- fallback filter query for record listing when query is empty- Returns:
- prepared query string wrapped in parentheses, or the whitelist filter query
-
buildTermQuery
- Parameters:
searchTerms- collection of search terms to combine into a query- Returns:
- Term query from searchTerms
-
buildTermQuery
- Parameters:
searchTerms- collection of search terms to combine into a queryaddOperators- if true, AND operators are inserted between terms- 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- raw search query string before suffixes are appliedboostTopLevelDocstructs- If true, query elements for boosting will be addedaggregationType-SearchAggregationType- Returns:
- complete Solr query string with all suffixes
- Throws:
IndexUnreachableException- if any.
-
buildFinalQuery
public static String buildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, HttpServletRequest request, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.- Parameters:
rawQuery- raw search query string before suffixes are appliedboostTopLevelDocstructs- If true, query elements for boosting will be addedrequest- HTTP servlet request used to retrieve filter query suffixaggregationType-SearchAggregationType- Returns:
- complete Solr query string with all suffixes
-
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-SXSSFWorkbookto populatefinalQuery- Complete query with suffixes.exportQuery- Query constructed from the user's input, without any secret suffixes.sortFields- list of sort field/direction pairsfilterQueries- Solr filter query stringsparams- additional Solr query parameterssearchTerms- map of field names to sets of search terms for highlightinglocale- language locale for column header translationproximitySearchDistance- word distance for proximity search- Throws:
IndexUnreachableException- if any.DAOException- if any.PresentationException- if any.ViewerConfigurationException- if any.
-
getExpandQueryParams
- Parameters:
expandQuery- the query used to filter the expanded hits- Returns:
- Map<String, String>
-
getExpandQueryParams
- Parameters:
expandQuery- the query used to filter the expanded hitsmaxHits- maximum number of expanded hits per main hits- 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- access condition value to query forescapeAccessCondition- if true, special URL characters in the value are escaped- 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- string to prepend to the term in the fuzzy templatesuffix- string to append to the term in the fuzzy template- 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- string to prepend to the term in the fuzzy templatesuffix- string to append to the term in the fuzzy template- Returns:
- term with fuzzy search token
-
addProximitySearchToken
- Parameters:
term- search phrase to append the proximity token todistance- maximum word distance between terms in a proximity search- Returns:
String
-
removeProximitySearchToken
- Parameters:
term- Search term containing proximity search token- Returns:
- term without proximity search token
-
extractProximitySearchDistanceFromQuery
- Parameters:
query- Solr query string possibly containing a proximity search token- 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- search term possibly containing leading and/or trailing wildcard characters- 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- list of facet query strings to include in the expand queryallowedFacetQueryRegexes- Optional list containing regexes for allowed facet queries- Returns:
- Expand query
-