Class SearchRepository

  • All Implemented Interfaces:
    WebSearchWatcher
    Direct Known Subclasses:
    UserRepository

    public abstract class SearchRepository
    extends java.lang.Object
    implements WebSearchWatcher
    The base class for search repositories. Classes that extend this base must provide implementations that define the responses to change events that affect the web searchables this repository is possibly interested in.
    Author:
    Alex Kalderimis
    • Field Detail

      • searchItems

        protected java.util.Set<WebSearchable> searchItems
      • indexes

        protected java.util.Map<java.lang.String,​org.apache.lucene.store.Directory> indexes
      • profile

        protected final Profile profile
      • tagManager

        protected final TagManager tagManager
    • Constructor Detail

      • SearchRepository

        public SearchRepository​(Profile profile)
        Constructor. Create a new search repository for the given profile.
        Parameters:
        profile - The gateway to the user data we want to search.
    • Method Detail

      • startListening

        protected void startListening()
        Begin listening for events on the items of interest.
      • stopListening

        protected void stopListening()
        Stop listening for events
      • getGlobalSearchRepositories

        public static java.util.Set<SearchRepository> getGlobalSearchRepositories()
        Get the search repositories registered as global repositories.
        Returns:
        An unmodifiable set of global search repositories.
      • getGlobalSearchRepository

        public static SearchRepository getGlobalSearchRepository​(Profile profile)
        Get the search repository registered as global repositories for the user specified in input.
        Parameters:
        profile - user profile
        Returns:
        the global search repositories.
      • addGlobalRepository

        public void addGlobalRepository()
        Add a global repository
      • getSearchItems

        public java.util.Set<WebSearchable> getSearchItems()
        Returns an unmodifiable view of the the search items observed by this repository.
        Returns:
        An unmodifiable Set.
      • getWebSearchableMap

        public java.util.Map<java.lang.String,​WebSearchable> getWebSearchableMap​(java.lang.String type)
        Get a map from name -> object for all the websearchables of the given type.
        Parameters:
        type - A valid TagType.
        Returns:
        A new unmodifiable map containing the requested information.
      • populateSearchItems

        protected abstract void populateSearchItems()
        Collect the search items we are interested in initially. The profile associated with this repository is a good place to start looking, but each implementation may decide it is interested in a different subset of the available objects.
      • receiveEvent

        public void receiveEvent​(ChangeEvent e)
        Description copied from interface: WebSearchWatcher
        Receive notification of a change to a WebSearchable somewhere in the universe. It may or may not be relevant to you. You will have to examine the event and decide what action to take.
        Specified by:
        receiveEvent in interface WebSearchWatcher
        Parameters:
        e - The event you care about.
      • getProfile

        protected Profile getProfile()
        Get the profile that this repository belongs to.
        Returns:
        A profile.
      • dropIndex

        protected void dropIndex​(WebSearchable ws)
        Drop the index that contains information about the websearchable object passed in.
        Parameters:
        ws - The item whose cached information we wish to dispose of.
      • getSearchIndex

        public org.apache.lucene.store.Directory getSearchIndex​(java.lang.String type)
        Retrieve a search index for a given type of web searchable objects. If there is already an index around, that will be returned. If not, one will be created and returned.
        Parameters:
        type - The type of the web searchables to index. Should be a valid TagType.
        Returns:
        a RAMDirectory containing the index.
      • handlePropertyChange

        protected abstract void handlePropertyChange​(PropertyChangeEvent e)
        Respond in some way to the change in the properties of a web searchable object.
        Parameters:
        e - The notification of the change event.
      • handleCreation

        protected abstract void handleCreation​(CreationEvent e)
        Respond in some way to the creation of a web searchable object.
        Parameters:
        e - The notification of the change event.
      • handleDeletion

        protected abstract void handleDeletion​(DeletionEvent e)
        Respond in some way to the deletion of a web searchable object.
        Parameters:
        e - The notification of the change event.
      • handleTagAddition

        protected abstract void handleTagAddition​(TaggingEvent e)
        Respond in some way to the addition of a tag to a web searchable object.
        Parameters:
        e - The notification of the change event.
      • handleTagRemoval

        protected abstract void handleTagRemoval​(TaggingEvent e)
        Respond in some way to the removal of a tag from a web searchable object.
        Parameters:
        e - The notification of the change event.
      • handleMassTagging

        protected abstract void handleMassTagging()
        Respond to the fact that multiple tags have been added and that we do not know what they are.