Class Searcher

java.lang.Object
org.omegat.core.search.Searcher

@NullMarked public class Searcher extends Object
This class implements search functionality. It is non-reentrant: each searcher instance must be used by a single thread.

THREAD SAFETY: This class is NOT thread-safe for concurrent access. However, it supports the following safe usage pattern:

  1. Thread A creates Searcher instance and calls search()
  2. Thread A completes search() execution completely
  3. Thread B can safely call getSearchResults() and other getter methods after Thread A completes
The key requirement is that getSearchResults() and other result access methods are only called AFTER search() completes, and no concurrent access occurs during search() execution.

VISIBILITY: The searchCompleted flag ensures proper visibility of search results between threads.

  • Constructor Details

    • Searcher

      public Searcher(IProject project, SearchExpression searchExpression)
      Create new searcher instance.
      Parameters:
      project - Current project
  • Method Details

    • setCancellationToken

      public void setCancellationToken(CancellationToken token)
      Set cancellation token for checking stop requests. Preferred over setThread(LongProcessThread).
    • setThread

      @Deprecated(since="6.1.0") public void setThread(LongProcessThread thread)
      Deprecated.
      Set thread for checking interruption.
    • getExpression

      public SearchExpression getExpression()
    • getSearchResults

      public List<SearchResultEntry> getSearchResults()
      Returns list of search results.
    • search

      public void search() throws IOException
      Search for this.expression and return a list of results.
      Throws:
      IOException - when searching files goes wrong
    • isSearchCompleted

      public boolean isSearchCompleted()
      Indicates whether the search operation has been completed.
      Returns:
      true if the search has been completed; false otherwise.
    • searchString

      public boolean searchString(@Nullable String origText)
      Looks for an occurrence of the search string(s) in the supplied text string.
      Parameters:
      origText - The text string to search in
      Returns:
      True if the text string contains all search strings
    • searchString

      public boolean searchString(@Nullable String origText, boolean collapseResults)
    • getFoundMatches

      public List<SearchMatch> getFoundMatches()
      Retrieves a list of matches found during the search operation.
      Returns:
      a list of SearchMatch objects, where each object provides information about the match's start and end positions, and any associated replacement text.
    • searchText

      public void searchText(String seg, @Nullable String translation, @Nullable String filename)