Class SearchFunctionality

java.lang.Object
io.goobi.viewer.model.cms.itemfunctionality.SearchFunctionality
All Implemented Interfaces:
Functionality, SearchInterface
Direct Known Subclasses:
QueryListFunctionality

public class SearchFunctionality extends Object implements Functionality, SearchInterface
CMS item functionality that embeds a search interface with its own query and facet state.
Author:
Florian Alpers
  • Constructor Details

    • SearchFunctionality

      public SearchFunctionality(String pageFacetString, String baseUrl)
      Creates a new SearchFunctionality instance.
      Parameters:
      pageFacetString - Solr filter query fixed for this CMS page
      baseUrl - base URL of the CMS page hosting this search
  • Method Details

    • resetSearch

      public String resetSearch()
      Resets the current search including all results and search parameters.
      Specified by:
      resetSearch in interface SearchInterface
      Returns:
      the url to navigate to, or an empty string if naviation is handled internally
    • redirectToSearchUrl

      public void redirectToSearchUrl(boolean keepUrlParameter)
      redirectToSearchUrl.
      Parameters:
      keepUrlParameter - if true, append current search parameters to the redirect URL
    • searchSimple

      public String searchSimple()
      Perform a simple Search.
      Specified by:
      searchSimple in interface SearchInterface
      Returns:
      the url to navigate to, or an empty string if naviation is handled internally
    • searchAdvanced

      public String searchAdvanced()
      Perform an advanced Search.
      Specified by:
      searchAdvanced in interface SearchInterface
      Returns:
      the url to navigate to, or an empty string if naviation is handled internally
    • searchFacetted

      public void searchFacetted()
      searchFacetted.
    • search

      search.
      Parameters:
      subtheme - subtheme discriminator value to filter search
      Throws:
      PresentationException - if any.
      IndexUnreachableException - if any.
      DAOException - if any.
      ViewerConfigurationException - if any.
    • getUrlPrefix

      public String getUrlPrefix()
      The part of the search url before the page number.
      Returns:
      the URL prefix for the CMS search page, including base URL, context, and query string
    • getUrlSuffix

      public String getUrlSuffix()
      getUrlSuffix.
      Returns:
      the URL suffix for the CMS search page, including sort string and facet string
    • getUrlSuffix

      public String getUrlSuffix(String solrSortFields)
      The part of the search url after the page number.
      Parameters:
      solrSortFields - Solr sort field string to embed in the URL
      Returns:
      the URL suffix for the CMS search page using the given sort fields
    • setPageNo

      public void setPageNo(int pageNo)
      setPageNo.
      Specified by:
      setPageNo in interface Functionality
      Parameters:
      pageNo - a int.
    • getPageNo

      public int getPageNo()
      getPageNo.
      Specified by:
      getPageNo in interface Functionality
      Returns:
      a int.
    • getCurrentPage

      public int getCurrentPage()
      Returns the current result list page number.
      Specified by:
      getCurrentPage in interface SearchInterface
      Returns:
      the current result list page number
    • getSearchBean

      public SearchBean getSearchBean()
      getSearchBean.
      Returns:
      the SearchBean used by this search functionality
    • getHitsPerPage

      public int getHitsPerPage()
      getHitsPerPage.
      Returns:
      the number of search hits displayed per page
    • getActiveContext

      public String getActiveContext()
      Specified by:
      getActiveContext in interface SearchInterface
      Returns:
      The selected result group name or advanced search template
    • setActiveContext

      public void setActiveContext(String activeContext)
      Specified by:
      setActiveContext in interface SearchInterface
      Parameters:
      activeContext - result group name or advanced search template to activate
    • getSortString

      public String getSortString()
      Returns the search string for the selected sort option.
      Specified by:
      getSortString in interface SearchInterface
      Returns:
      the search string for the selected sort option
    • setSortString

      public void setSortString(String solrSortFields)
      Sets the sorting search string.
      Specified by:
      setSortString in interface SearchInterface
      Parameters:
      solrSortFields - sort field and direction encoded as search string
    • getFacetString

      public String getFacetString()
      getFacetString.
      Returns:
      the currently active facet filter string
    • setFacetString

      public void setFacetString(String facetString)
      setFacetString.
      Parameters:
      facetString - active facet filter string to apply
    • getQueryString

      public String getQueryString()
      getQueryString.
      Returns:
      the exact search string from the underlying SearchBean
    • getExactSearchString

      public String getExactSearchString()
      Gets the actual search string.
      Specified by:
      getExactSearchString in interface SearchInterface
      Returns:
      the actual search string
    • setQueryString

      public void setQueryString(String s)
      setQueryString.
      Parameters:
      s - exact search query string to set
    • getBaseUrl

      public String getBaseUrl()
      Getter for the field baseUrl.
      Returns:
      the base URL of the CMS page hosting this search functionality
    • getPageFacetString

      public String getPageFacetString()
      Getter for the field pageFacetString.
      Returns:
      the facet filter string applied to the current search page
    • getNewSearchUrl

      public String getNewSearchUrl()
      getNewSearchUrl.
      Returns:
      the search URL with the sort field reset to default (no sorting)
    • changeSorting

      public String changeSorting() throws IOException
      Description copied from interface: SearchInterface
      Action to execute to change the sort order of hits.
      Specified by:
      changeSorting in interface SearchInterface
      Returns:
      Navigation outcome
      Throws:
      IOException
    • getSortUrl

      public String getSortUrl(String sortString, boolean descending)
      getSortUrl.
      Parameters:
      sortString - Solr sort field name to include in the URL
      descending - if true, prefix the sort field with '!' for descending order
      Returns:
      the search URL for the current page with the given sort order applied
    • getFacettedUrl

      public String getFacettedUrl(String facetString)
      getFacettedUrl.
      Parameters:
      facetString - active facet filter string to embed in the URL
      Returns:
      the search URL with the given facet filter string applied
    • removeFacet

      public String removeFacet(String facet)
      removeFacet.
      Parameters:
      facet - facet value string to remove from the active facet string
      Returns:
      the updated facet string with the given facet removed, or "-" if it becomes empty
    • getCurrentPagePath

      public String getCurrentPagePath()
      getCurrentPagePath.
      Returns:
      the current viewer page path including application name and prettified page path, or an empty string if not available
    • isSearchInDcFlag

      public boolean isSearchInDcFlag()
      Returns if search is performed only within a DC.
      Specified by:
      isSearchInDcFlag in interface SearchInterface
      Returns:
      true if the search is restricted to a specific DC (collection) field, false otherwise
    • isSearchInFacetFieldFlag

      public boolean isSearchInFacetFieldFlag(String fieldName)
      Description copied from interface: SearchInterface
      Returns if search is performed only within a certain facet field.
      Specified by:
      isSearchInFacetFieldFlag in interface SearchInterface
      Parameters:
      fieldName - Solr facet field name to check
      Returns:
      true if the search is restricted to the given facet field, false otherwise
    • getFacets

      public SearchFacets getFacets()
      List all current SearchFacets.
      Specified by:
      getFacets in interface SearchInterface
      Returns:
      all current SearchFacets
    • autocomplete

      public List<String> autocomplete(String suggestion) throws IndexUnreachableException
      Returns suggestions for autocomplete.
      Specified by:
      autocomplete in interface SearchInterface
      Parameters:
      suggestion - partial input string to complete
      Returns:
      suggestions for autocomplete
      Throws:
      IndexUnreachableException - if any.
    • getSearchString

      public String getSearchString()
      Gets the current search string for display.
      Specified by:
      getSearchString in interface SearchInterface
      Returns:
      the current search string for display
    • getSearchFilters

      public List<SearchFilter> getSearchFilters()
      Gets a list of all available search filters.
      Specified by:
      getSearchFilters in interface SearchInterface
      Returns:
      a list of all available search filters
    • getCurrentSearchFilterString

      public String getCurrentSearchFilterString()
      Returns the current search filter as string.
      Specified by:
      getCurrentSearchFilterString in interface SearchInterface
      Returns:
      the current search filter as string
    • setCurrentSearchFilterString

      public void setCurrentSearchFilterString(String filter)
      Sets the current search filter as string.
      Specified by:
      setCurrentSearchFilterString in interface SearchInterface
      Parameters:
      filter - search filter identifier string to activate
    • getActiveSearchType

      public int getActiveSearchType()
      Get the currently active search type. The possible types are defined in SearchHelper
      Specified by:
      getActiveSearchType in interface SearchInterface
      Returns:
      the active search type
    • setActiveSearchType

      public void setActiveSearchType(int type)
      Set the search type to use. The possible types are defined in SearchHelper
      Specified by:
      setActiveSearchType in interface SearchInterface
      Parameters:
      type - search type constant as defined in SearchHelper
    • setSearchString

      public void setSearchString(String searchString)
      Sets the actual search string.
      Specified by:
      setSearchString in interface SearchInterface
      Parameters:
      searchString - raw search query to set
    • isSearchPerformed

      public boolean isSearchPerformed()
      Checks if a search has been performed and any results are to be excepted (provided the search yielded any).
      Specified by:
      isSearchPerformed in interface SearchInterface
      Returns:
      whether a search has been performed after the last reset
    • getHitsCount

      public long getHitsCount()
      Get total number of hits of the last search.
      Specified by:
      getHitsCount in interface SearchInterface
      Returns:
      the total number of hits of the last search
    • getCurrentSearchUrlRoot

      public String getCurrentSearchUrlRoot()
      Returns the base url of the current search page, without any search parameters.
      Specified by:
      getCurrentSearchUrlRoot in interface SearchInterface
      Returns:
      the base url of the current search page, without any search parameters
    • getLastPage

      public int getLastPage()
      Returns the last result list page number.
      Specified by:
      getLastPage in interface SearchInterface
      Returns:
      the last result list page number
    • isExplicitSearchPerformed

      public boolean isExplicitSearchPerformed()
      Checks if a search has been triggered by the user and not yet been reset.
      Specified by:
      isExplicitSearchPerformed in interface SearchInterface
      Returns:
      if a search has been triggered by the user and not yet been reset
    • hasGeoLocationHits

      public boolean hasGeoLocationHits()
      Specified by:
      hasGeoLocationHits in interface SearchInterface
    • getHitsMap

      public GeoMap getHitsMap()
      Specified by:
      getHitsMap in interface SearchInterface