Class DocumentSearchModelImpl


  • public class DocumentSearchModelImpl
    extends Object
    Document search model is used by the DocumentSearchController as a way to cache search results. PDF document in general can be to big to keep all data in memory at once. ICEpdf uses a dispose/initialization on Page data as memory is needed. When this happens the selected text data will be lost and we have to research the page in question the next time it is viewed.
    This model can be used in two ways; the first is to store search terms and the second is to keep a record of page indexes that have search results. The later uses weak references to make sure we don't leak any memory. If the page has no data available in its weak reference then we can get it. If a there is no value for a given page index then we know the page had no search hits and we can ignore it.
    Since:
    4.0
    • Constructor Detail

      • DocumentSearchModelImpl

        public DocumentSearchModelImpl()
        Creates a new instance with empty search terms and search result caches.
    • Method Detail

      • getSearchTerms

        public ArrayList<SearchTerm> getSearchTerms()
        Gets a list of search terms that make up a given search.
        Returns:
        list of search term, maybe empty but not null.
      • addSearchTerm

        public void addSearchTerm​(SearchTerm searchTerm)
        Add a search term to the model.
        Parameters:
        searchTerm - search term, no checking is done for invalid data.
      • removeSearchTerm

        public void removeSearchTerm​(SearchTerm searchTerm)
        Remove the specified search term from the model.
        Parameters:
        searchTerm - search term to remove.
      • addPageSearchHit

        public void addPageSearchHit​(int pageIndex,
                                     PageText pageText,
                                     int hits)
        Add a search result hit for a given page. A page can have 1 or more hits but all that matters is that there is at least one hit to manage. The index and PageText Object is stored in the cache.
        Parameters:
        pageIndex - page index of search hit(s)
        pageText - PageText for the given page index.
        hits - search results hit count, used to setup word search cursor.
      • getPageSearchHits

        public Set<Integer> getPageSearchHits()
        Gets a set of page hit page indexes. That is to say a list of all page indexes that have search hits. This list can be used to clear searches or to iterate more quickly of the results set.
        Returns:
        set of page indexes that have a least one search result hit.
      • getPageSearchHitsSize

        public int getPageSearchHitsSize()
        Gets the number of pages that have hits.
        Returns:
        search hit number, zero indicates no hits.
      • isPageSearchHit

        public boolean isPageSearchHit​(int pageIndex)
        Check the page index to see if there is a search result.
        Parameters:
        pageIndex - index of page to search
        Returns:
        true if page has search result, false otherwise.
      • getPageTextHit

        public PageText getPageTextHit​(int pageIndex)
      • isPageTextMatch

        public boolean isPageTextMatch​(int pageIndex,
                                       PageText pageText)
        When we know a page has a hit but aren't sure if pageText is still in a highlighted state we can use this method to check. If the weak reference for the pageIndex exists we can compare it against the parameter pageText. If the objects are equal there is no need to search again. If reference is null or not equal then we have to do the search again to get the highlight state back. Pages searches in general are extremely fast and performs better then trying to keep everything in memory.
        Parameters:
        pageIndex - page index to look at PageText results
        pageText - current Page objects PageText object we want to check against whats in the cache.
        Returns:
        false if the search for this page should be done again, otherwise true then we should be ok and don't need to refresh the text state.
      • clearSearchResults

        public void clearSearchResults​(int page)
        Clears cached search results for this page index and clears the highlighted state for this page.
        Parameters:
        page - page index to clear search results from.
      • clearSearchResults

        public void clearSearchResults()
        Clears all search results and highlight states found in the research results cache. This method is especially useful for large documents.
      • getSearchPageCursor

        public int getSearchPageCursor()
      • setSearchPageCursor

        public void setSearchPageCursor​(int searchPageCursor)
      • getSearchWordCursor

        public int getSearchWordCursor()
      • setSearchWordCursor

        public void setSearchWordCursor​(int searchWordCursor)
      • getSearchLineCursor

        public int getSearchLineCursor()
      • setSearchLineCursor

        public void setSearchLineCursor​(int searchLineCursor)