Interface SimpleSearch


  • public interface SimpleSearch
    Search implements a simple fulltext search with some additions to the search logic and exposes the query result in a scripting friendly object structure. For more complex queries, see Query and the QueryBuilder.
    Since:
    5.2
    • Field Detail

      • RELATED_PREFIX

        static final String RELATED_PREFIX
        The prefix for a query searches for similar content.
        See Also:
        Constant Field Values
    • Method Detail

      • setQuery

        void setQuery​(String query)
        Sets a new fulltext query that will be executed.

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        query - the fulltext query.
      • getQuery

        String getQuery()
        Returns the query term supplied by the user.
        Returns:
        the query term supplied by the user.
      • setSearchIn

        void setSearchIn​(String searchIn)
        Sets the repository path where to search in. This allows to specify a subtree such as "/content/mysite".

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        searchIn - the location where to search in.
      • getSearchIn

        String getSearchIn()
        Returns the repository path where to search in.
        Returns:
        the location where to search in.
      • setHitsPerPage

        void setHitsPerPage​(long num)
        Sets the number of hits to include on a ResultPage. Since only the first page is returned directly and typically fully read by clients, this can also be seen as "limit" for the search result. Further results can be accessed either by retrieving the next result page or by running a new query and setting the start parameter (often also called "offset"). For unlimited results on a single page, use 0. Default value is 10.

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        num - the number of hits to include on a result page (0 for unlimited results)
      • getHitsPerPage

        long getHitsPerPage()
        Returns the number of hits to include per ResultPage, ie. the limit. See setHitsPerPage(long).
        Returns:
        the number of hits to include per result page
      • setStart

        void setStart​(long start)
        This sets an offset for the actual search results, ie. it will skip the first N (= start) items of the underlying result iterator. By default this is 0, ie. right from the very beginning.

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        start - the offset in the actual search results to start from
      • getStart

        long getStart()
        Returns the offset in the actual search results to start from. See setStart(long).
        Returns:
        offset in the actual search results to start from
      • addPredicate

        void addPredicate​(Predicate predicate)
        Allows to add custom predicates for the underlying Query.

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        predicate - a search predicate
      • getResult

        SearchResult getResult()
                        throws RepositoryException
        Returns the search result object. The query is only executed once upon the first call to this method.
        Returns:
        the query result or null if there is no query parameter set.
        Throws:
        RepositoryException - if an exception occurs while executing the query.
      • getTrends

        Trends getTrends()
        Returns a object with access to query trend statistics.
        Returns:
        query trends (popular queries).
      • getRelatedQueries

        List<String> getRelatedQueries()
                                throws RepositoryException
        Returns queries that are related to the current one.
        Returns:
        queries that are related to the current one.
        Throws:
        RepositoryException - if an error occurs while reading from the repository.
      • setSearchProperties

        void setSearchProperties​(String properties)
        Sets the comma-separated list of properties that will be searched for the term given in setQuery(String).

        If this is called after getResult() has been called, i.e. the query was executed already, this will lead to the next getResult() call executing the new query again.

        Parameters:
        properties - comma separated names of the properties that will be searched.
      • getSearchProperties

        String getSearchProperties()
        Returns the comma-separated list of properties that will be searched for the term given in setQuery(String).
        Returns:
        the names of the properties that will be searched.