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 StringConstantREGEX_QUOTATION_MARKS="\"[^()]*?static final SearchFilterConstantSEARCH_FILTER_ALLstatic final Stringstatic final StringConstantSEARCH_TERM_SPLIT_REGEXstatic final StringRegex for splitting search values (including colons).static final intConstantSEARCH_TYPE_ADVANCED=1static final intConstantSEARCH_TYPE_CALENDAR=3static final intConstantSEARCH_TYPE_REGULAR=0static final intConstantSEARCH_TYPE_TERMS=4static 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, jakarta.servlet.http.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(jakarta.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.static StringgetAllSuffixes(jakarta.servlet.http.HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.static StringgetAllSuffixes(jakarta.servlet.http.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 stringsstatic 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) Remove '*' at the start or end of the given valuestatic StringreplaceHighlightingPlaceholders.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.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.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 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 voidupdateFilterQuerySuffix(jakarta.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_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
ConstantREGEX_QUOTATION_MARKS="\"[^()]*?\"".- 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-StringSolr search query. Merges full-text and metadata hits into their corresponding docstructs.first-IntegerFirst row indexrows-IntegerNumber of rows to returnsortFields- aListobject.resultFields- aListobject.filterQueries- aListobject.params- aMapobject.searchTerms- aMapobject.exportFields- aListobject.locale- aLocaleobject.proximitySearchDistance-- 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-StringSolr search query. Merges full-text and metadata hits into their corresponding docstructs.first-Integervonrows-IntegerbissortFields- aListobject.resultFields- aListobject.filterQueries- aListobject.params- aMapobject.searchTerms- aMapobject.exportFields- aListobject.locale- aLocaleobject.keepSolrDoc-proximitySearchDistance-- 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-StringSolr search query. Merges full-text and metadata hits into their corresponding docstructs.first-IntegerFirst hit indexrows-IntegerNumber of hits to returnsortFields- aListobject.resultFields- aListobject.filterQueries- aListobject.params- aMapobject.searchTerms- aMapobject.exportFields- aListobject.additionalMetadataListType- Optional addtional metadata list type, to be used on alternative search hit views, etc.locale- aLocaleobject.keepSolrDoc-proximitySearchDistance-- 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-- Returns:
HitTypefor doc
-
getAllSuffixes
Returns all suffixes relevant to search filtering.- Returns:
- a
Stringobject.
-
getAllSuffixes
public static String getAllSuffixes(jakarta.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix) Returns all suffixes relevant to search filtering.- Parameters:
request- aHttpServletRequestobject.addStaticQuerySuffix- a boolean.addCollectionBlacklistSuffix- a boolean.- Returns:
- Generated Solr query suffix
-
getAllSuffixes
public static String getAllSuffixes(jakarta.servlet.http.HttpServletRequest request, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) - Parameters:
request- aHttpServletRequestobject.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(jakarta.servlet.http.HttpServletRequest request, boolean addArchiveFilterSuffix, boolean addStaticQuerySuffix, boolean addCollectionBlacklistSuffix, String privilege) Returns all suffixes relevant to search filtering.- Parameters:
request- aHttpServletRequestobject.addArchiveFilterSuffix- a boolean.addStaticQuerySuffix- if true, add the configured static query suffix to the queryaddCollectionBlacklistSuffix- a boolean.privilege- Privilege to check (Connector checks a different privilege)- Returns:
- Generated Solr query suffix
-
getAllSuffixesExceptCollectionBlacklist
Returns all suffixes relevant to search filtering.- Returns:
- a
Stringobject.
-
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- aStringobject.index- a int.sortFields- aListobject.filterQueries- aListobject.params- aMapobject.searchTerms- aMapobject.locale- aLocaleobject.proximitySearchDistance-- Returns:
- a
BrowseElementobject. - 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- aStringobject.value- aStringobject.filterForWhitelist- a boolean.filterForBlacklist- a boolean.splittingChar- aStringobject.- 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
Mapobject. - 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- aStringobject.facetFields- aListobject.facetMinCount- a int.getFieldStatistics- a boolean.- Returns:
- a
QueryResponseobject. - Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getMinMaxYears
public static int[] getMinMaxYears(String subQuery) throws PresentationException, IndexUnreachableException getMinMaxYears.
- Parameters:
subQuery- aStringobject.- 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- aListobject.- Returns:
- a
Listobject. - 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(jakarta.servlet.http.HttpServletRequest request, String privilege) throws IndexUnreachableException, PresentationException, DAOException Updates the calling agent's session with a personalized filter sub-query.- Parameters:
request- aHttpServletRequestobject.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- aUserobject.ipAddress- aStringobject.client-privilege- Privilege to check (Connector checks a different privilege)- Returns:
- a
Stringobject. - 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- aSetobject.inFulltext- aStringobject.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
Listobject.
-
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- aStringobject.facetFieldName- aStringobject.facetMinCount- a int.- Returns:
- a
Listobject. - 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- aStringobject.facetFieldName- aStringobject.facetPrefix- The facet field value must start with these characters. Ignored if null or blankfacetMinCount- a int.params-- Returns:
- a
Listobject. - 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:
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-filterQuery-locale-- 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- aBrowsingMenuFieldConfigobject.startsWith- aStringobject.filterQuery- aStringobject.start-rows-comparator- aComparatorobject.language- Language for language-specific fields- Returns:
- a
Listobject. - 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
Mapobject.
-
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, 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
Stringobject.
-
getExpandQueryFieldList
public static List<String> getExpandQueryFieldList(int searchType, SearchFilter searchFilter, SearchQueryGroup queryGroup, List<String> additionalFields) getExpandQueryFieldList.
- Parameters:
searchType- a int.searchFilter- aSearchFilterobject.queryGroup- aSearchQueryGroupobject.additionalFields- Optinal additional fields to return- Returns:
- a
Listobject.
-
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- aStringobject.boostTopLevelDocstructs- If true, query elements for boosting will be addedaggregationType-SearchAggregationType- Returns:
- a
Stringobject. - Throws:
IndexUnreachableException- if any.
-
buildFinalQuery
public static String buildFinalQuery(String rawQuery, boolean boostTopLevelDocstructs, jakarta.servlet.http.HttpServletRequest request, SearchAggregationType aggregationType) Constructs the complete query using the raw query and adding all available suffixes.- Parameters:
rawQuery- aStringobject.boostTopLevelDocstructs- If true, query elements for boosting will be addedrequest-aggregationType-SearchAggregationType- Returns:
- a
Stringobject.
-
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- aListobject.filterQueries- aListobject.params- aMapobject.searchTerms- aMapobject.locale- aLocaleobject.proximitySearchDistance-- 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-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
-