org.icepdf.ri.common.search
Class DocumentSearchModelImpl

java.lang.Object
  extended by org.icepdf.ri.common.search.DocumentSearchModelImpl

public class DocumentSearchModelImpl
extends java.lang.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 Summary
DocumentSearchModelImpl()
          Creates a new instance with empty search terms and search result caches.
 
Method Summary
 void addPageSearchHit(int pageIndex, org.icepdf.core.pobjects.graphics.text.PageText pageText)
          Add a search result hit for a given page.
 void addSearchTerm(org.icepdf.core.search.SearchTerm searchTerm)
          Add a search term to the model.
 void clearSearchResults()
          Clears all search results and highlight states found in the research results cache.
 void clearSearchResults(int page)
          Clears cached search results for this page index and clears the highlighted state for this page.
 java.util.Set<java.lang.Integer> getPageSearchHits()
          Gets a set of page hit page indexes.
 org.icepdf.core.pobjects.graphics.text.PageText getPageTextHit(int pageIndex)
           
 java.util.ArrayList<org.icepdf.core.search.SearchTerm> getSearchTerms()
          Gets a list of search terms that make up a given search.
 boolean isPageSearchHit(int pageIndex)
          Check the page index to see if there is a search result.
 boolean isPageTextMatch(int pageIndex, org.icepdf.core.pobjects.graphics.text.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.
 void removeSearchTerm(org.icepdf.core.search.SearchTerm searchTerm)
          Remove the specified search term from the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentSearchModelImpl

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

Method Detail

getSearchTerms

public java.util.ArrayList<org.icepdf.core.search.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(org.icepdf.core.search.SearchTerm searchTerm)
Add a search term to the model.

Parameters:
searchTerm - search term, no checking is done for invalid data.

removeSearchTerm

public void removeSearchTerm(org.icepdf.core.search.SearchTerm searchTerm)
Remove the specified search term from the model.

Parameters:
searchTerm - search term to remove.

addPageSearchHit

public void addPageSearchHit(int pageIndex,
                             org.icepdf.core.pobjects.graphics.text.PageText pageText)
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.

getPageSearchHits

public java.util.Set<java.lang.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.

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 org.icepdf.core.pobjects.graphics.text.PageText getPageTextHit(int pageIndex)

isPageTextMatch

public boolean isPageTextMatch(int pageIndex,
                               org.icepdf.core.pobjects.graphics.text.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.