Interface SearchIndexAccessor

All Known Implementing Classes:
DelegatingSearchIndexAccessor, EdgeSearchIndexAccessor, LuceneSearchIndexAccessor, OpenSearchSearchIndexAccessor

@ThreadSafe public interface SearchIndexAccessor
An V2 interface which provides the following thread-safe actions on a search index: To hook into core search indexes behaviour (content and change index), inject the exposed beans via Spring. To create custom ones use CustomSearchIndexRegistry or extend DelegatingSearchIndexAccessor.

WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See SiteSearchPermissionsQueryFactory to add one yourself. See PredefinedSearchBuilder to build a pre-defined search which contains permission checking.

Since:
7.16
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Executes a SearchIndexAction on the underlying search index.
     
    long
    Get the total size of the index in bytes.
    int
    Get the total number of index documents for the underlying search index
    default void
    Refresh the index immediately, which publishes its most recent changes and makes them available for searching.
    void
    reset(Runnable replaceIndex)
    Execute a method after the index has been closed and before the index has been reopened
    long
    scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<ScannedDocument> consumer, float defaultScore)
    Scans the index for documents that match the provided searchQuery.
    long
    scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String,String[]>> consumer)
    Scans the index for documents that match the provided searchQuery.
    search(ISearch search, Set<String> requestedFields)
    Perform a search, the returned SearchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult.
    void
    snapshot(File destinationDirectory)
    Take a snapshot of the current index and store it into the destination directory
    void
    Execute the update action in a batch.
  • Method Details

    • search

      SearchResults search(ISearch search, Set<String> requestedFields) throws InvalidSearchException
      Perform a search, the returned SearchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult.

      SearchResults will throw an FieldNotRequestedException if an attempt is made to access a field value that has not had it's key included in the projection Set.

      NOTE: the search limit will be capped at SearchConstants.MAX_LIMIT and the startOffset will be capped at SearchConstants.MAX_START_OFFSET for more efficient heap usage. See SearchResults.getNextPageSearch() for pagination.

      WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See SiteSearchPermissionsQueryFactory to add one yourself. See PredefinedSearchBuilder to build a pre-defined search which contains permission checking.

      Parameters:
      search - the search to perform.
      requestedFields - requested fields. Passing null will request all fields, and passing empty set will request none.
      Throws:
      InvalidSearchException - if some error occurred converting the search object into * a search that could be performed in the back-end. Usually this is a sign that some plugin that was * used to create the search is no longer available.
      See Also:
    • scan

      long scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<Map<String,String[]>> consumer)
      Scans the index for documents that match the provided searchQuery. The requestedFields set is used to specify which values need to be returned. The consumer will collect all the results found by the scan.

      Note that it is possible for a document to match the query, but not have any of the requested fields. This will result in an empty String[] for those fields that don't exist on the document. If you don't want to return those documents, you should specify a consumer that filters these out.

      WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See SiteSearchPermissionsQueryFactory to add one yourself. See PredefinedSearchBuilder to build a pre-defined search which contains permission checking.

      Parameters:
      searchQuery - SearchQuery to scan the index for.
      requestedFields - Set of field names that are requested from the index. Any fields provided here that is not on the document will return an empty String[] Passing null will request all fields, and passing empty set will request none.
      consumer - Consumer that handles each found document.
      Returns:
      the number of documents that matched the searchQuery.
      Throws:
      SearchIndexAccessException - if there is an IO error.
      See Also:
    • scan

      long scan(SearchQuery searchQuery, Set<String> requestedFields, Consumer<ScannedDocument> consumer, float defaultScore)
      Scans the index for documents that match the provided searchQuery. The requestedFields set is used to specify which values need to be returned. The consumer will collect all the results found by the scan and convert them into ScannedDocument, which contains a score (if scoreIncluded is true) and a field-value map of the requested fields.

      Note that it is possible for a document to match the query, but not have any of the requested fields as the other scan method.

      This will result in an empty String[] for those fields that don't exist on the document. If you don't want to return those documents, you should specify a consumer that filters these out.

      WARNING: there is no default permissions checking behaviour provided. You MUST provide a search which specifies permissions checking. See SiteSearchPermissionsQueryFactory to add one yourself. See PredefinedSearchBuilder to build a pre-defined search which contains permission checking.

      Parameters:
      searchQuery - SearchQuery to scan the index for.
      requestedFields - Set of field names that are requested from the index. Any fields provided here that is not on the document will return an empty String[] Passing null will request all fields, and passing empty set will request none.
      consumer - Consumer that handles each found document.
      defaultScore - a default score to be included in the ScannedDocument if it is not possible to retrieve the score for the document.
      Returns:
      the number of documents that matched the searchQuery.
      Throws:
      SearchIndexAccessException - if there is an IO error.
      See Also:
    • execute

      void execute(SearchIndexAction action) throws SearchIndexAccessException
      Executes a SearchIndexAction on the underlying search index.
      Parameters:
      action - SearchIndexAction
      Throws:
      SearchIndexAccessException - if there is an io error.
    • numDocs

      int numDocs() throws SearchIndexAccessException
      Get the total number of index documents for the underlying search index
      Returns:
      the total number of index documents
      Throws:
      SearchIndexAccessException
    • getSizeInBytes

      long getSizeInBytes() throws SearchIndexAccessException
      Get the total size of the index in bytes.
      Returns:
      size of the index in bytes
      Throws:
      SearchIndexAccessException
      Since:
      8.8.0
    • withBatchUpdate

      void withBatchUpdate(BatchUpdateAction batchUpdateAction)
      Execute the update action in a batch. Executions are transactional, reads can't see any writes made and the index will be locked for updating by other threads. Currently, there is no rollback when the transaction fails for any reason. This is a bug which will be investigated in future.
      Parameters:
      batchUpdateAction - the batch update action
    • snapshot

      void snapshot(File destinationDirectory) throws SearchIndexAccessException
      Take a snapshot of the current index and store it into the destination directory
      Parameters:
      destinationDirectory - the destination directory
      Throws:
      SearchIndexAccessException - if the snapshot could not be taken
      UnsupportedOperationException - when using a SearchIndexAccessor for the main or change indexes.
      Since:
      7.16
    • reset

      void reset(Runnable replaceIndex)
      Execute a method after the index has been closed and before the index has been reopened
      Parameters:
      replaceIndex - the method that needs to be executed
    • getFieldMappings

      FieldMappings getFieldMappings()
      Returns:
      FieldMappings associated with this index
      Since:
      8.6
    • refreshIndex

      default void refreshIndex() throws IOException
      Refresh the index immediately, which publishes its most recent changes and makes them available for searching. This method is only applicable to the OpenSearch platform.
      Throws:
      IOException