Class Monitor

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Monitor
    extends java.lang.Object
    implements java.io.Closeable
    A Monitor contains a set of Query objects with associated IDs, and efficiently matches them against sets of Document objects.
    • Field Detail

      • analyzer

        private final Analyzer analyzer
      • commitBatchSize

        private final long commitBatchSize
    • Constructor Detail

      • Monitor

        public Monitor​(Analyzer analyzer)
                throws java.io.IOException
        Create a non-persistent Monitor instance with the default term-filtering Presearcher
        Parameters:
        analyzer - to analyze Documents at match time
        Throws:
        java.io.IOException
      • Monitor

        public Monitor​(Analyzer analyzer,
                       Presearcher presearcher)
                throws java.io.IOException
        Create a new non-persistent Monitor instance
        Parameters:
        analyzer - to analyze Documents at match time
        presearcher - the presearcher to use
        Throws:
        java.io.IOException
      • Monitor

        public Monitor​(Analyzer analyzer,
                       MonitorConfiguration config)
                throws java.io.IOException
        Create a new Monitor instance with a specific configuration
        Parameters:
        analyzer - to analyze Documents at match time
        config - the configuration
        Throws:
        java.io.IOException
      • Monitor

        public Monitor​(Analyzer analyzer,
                       Presearcher presearcher,
                       MonitorConfiguration configuration)
                throws java.io.IOException
        Create a new Monitor instance
        Parameters:
        analyzer - to analyze Documents at match time
        presearcher - the presearcher to use
        configuration - the configuration
        Throws:
        java.io.IOException
    • Method Detail

      • addQueryIndexUpdateListener

        public void addQueryIndexUpdateListener​(MonitorUpdateListener listener)
        Register a MonitorUpdateListener that will be notified whenever changes are made to the Monitor's queryindex
        Parameters:
        listener - listener to register
      • getQueryCacheStats

        public Monitor.QueryCacheStats getQueryCacheStats()
                                                   throws java.io.IOException
        Returns:
        Statistics for the internal query index and cache
        Throws:
        java.io.IOException
      • purgeCache

        public void purgeCache()
                        throws java.io.IOException
        Remove unused queries from the query cache.

        This is normally called from a background thread at a rate set by configurePurgeFrequency().

        When Monitor is in read-only mode, cache is NEVER purged automatically you MUST call it when you want new changes.

        Throws:
        java.io.IOException - on IO errors
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • register

        public void register​(java.lang.Iterable<MonitorQuery> queries)
                      throws java.io.IOException
        Add new queries to the monitor
        Parameters:
        queries - the MonitorQueries to add
        Throws:
        java.io.IOException
      • commit

        private void commit​(java.util.List<MonitorQuery> updates)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • register

        public void register​(MonitorQuery... queries)
                      throws java.io.IOException
        Add new queries to the monitor
        Parameters:
        queries - the MonitorQueries to add
        Throws:
        java.io.IOException - on IO errors
      • deleteById

        public void deleteById​(java.util.List<java.lang.String> queryIds)
                        throws java.io.IOException
        Delete queries from the monitor by ID
        Parameters:
        queryIds - the IDs to delete
        Throws:
        java.io.IOException - on IO errors
      • deleteById

        public void deleteById​(java.lang.String... queryIds)
                        throws java.io.IOException
        Delete queries from the monitor by ID
        Parameters:
        queryIds - the IDs to delete
        Throws:
        java.io.IOException - on IO errors
      • clear

        public void clear()
                   throws java.io.IOException
        Delete all queries from the monitor
        Throws:
        java.io.IOException - on IO errors
      • getQuery

        public MonitorQuery getQuery​(java.lang.String queryId)
                              throws java.io.IOException
        Get the MonitorQuery for a given query id
        Parameters:
        queryId - the id of the query to get
        Returns:
        the MonitorQuery stored for this id, or null if not found
        Throws:
        java.io.IOException - on IO errors
        java.lang.IllegalStateException - if queries are not stored in the queryindex
      • getDisjunctCount

        public int getDisjunctCount()
                             throws java.io.IOException
        Returns:
        the number of queries (after decomposition) stored in this Monitor
        Throws:
        java.io.IOException
      • getQueryCount

        public int getQueryCount()
                          throws java.io.IOException
        Returns:
        the number of queries stored in this Monitor
        Throws:
        java.io.IOException - on IO errors
      • getQueryIds

        public java.util.Set<java.lang.String> getQueryIds()
                                                    throws java.io.IOException
        Returns:
        the set of query ids of the queries stored in this Monitor
        Throws:
        java.io.IOException - on IO errors
      • debug

        public <T extends QueryMatchPresearcherMatches<T> debug​(Document[] docs,
                                                                  MatcherFactory<T> factory)
                                                           throws java.io.IOException
        Match a DocumentBatch against the queries stored in the Monitor, also returning information about which queries were selected by the presearcher, and why.
        Type Parameters:
        T - the type of QueryMatch produced by the CandidateMatcher
        Parameters:
        docs - a DocumentBatch to match against the index
        factory - a MatcherFactory to use to create a CandidateMatcher for the match run
        Returns:
        a PresearcherMatches object containing debug information
        Throws:
        java.io.IOException - on IO errors
      • debug

        public <T extends QueryMatchPresearcherMatches<T> debug​(Document doc,
                                                                  MatcherFactory<T> factory)
                                                           throws java.io.IOException
        Match a single Document against the queries stored in the Monitor, also returning information about which queries were selected by the presearcher, and why.
        Type Parameters:
        T - the type of QueryMatch produced by the CandidateMatcher
        Parameters:
        doc - an InputDocument to match against the index
        factory - a MatcherFactory to use to create a CandidateMatcher for the match run
        Returns:
        a PresearcherMatches object containing debug information
        Throws:
        java.io.IOException - on IO errors