Package org.apache.lucene.monitor
Class Monitor
- java.lang.Object
-
- org.apache.lucene.monitor.Monitor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class Monitor extends java.lang.Object implements java.io.Closeable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMonitor.PresearcherQueryCollector<T extends QueryMatch>static classMonitor.QueryCacheStatsStatistics for the query cache and query indexprivate static classMonitor.StandardQueryCollector<T extends QueryMatch>
-
Field Summary
Fields Modifier and Type Field Description private Analyzeranalyzerprivate longcommitBatchSizeprivate longlastPurgedprivate java.util.List<MonitorUpdateListener>listenersprotected Presearcherpresearcherprivate java.util.concurrent.ScheduledExecutorServicepurgeExecutorprivate QueryIndexqueryIndex
-
Constructor Summary
Constructors Constructor Description Monitor(Analyzer analyzer)Create a non-persistent Monitor instance with the default term-filtering PresearcherMonitor(Analyzer analyzer, MonitorConfiguration config)Create a new Monitor instance with a specific configurationMonitor(Analyzer analyzer, Presearcher presearcher)Create a new non-persistent Monitor instanceMonitor(Analyzer analyzer, Presearcher presearcher, MonitorConfiguration configuration)Create a new Monitor instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddQueryIndexUpdateListener(MonitorUpdateListener listener)Register aMonitorUpdateListenerthat will be notified whenever changes are made to the Monitor's queryindexvoidclear()Delete all queries from the monitorvoidclose()private voidcommit(java.util.List<MonitorQuery> updates)<T extends QueryMatch>
PresearcherMatches<T>debug(Document[] docs, MatcherFactory<T> factory)Match a DocumentBatch against the queries stored in the Monitor, also returning information about which queries were selected by the presearcher, and why.<T extends QueryMatch>
PresearcherMatches<T>debug(Document doc, MatcherFactory<T> factory)Match a singleDocumentagainst the queries stored in the Monitor, also returning information about which queries were selected by the presearcher, and why.voiddeleteById(java.lang.String... queryIds)Delete queries from the monitor by IDvoiddeleteById(java.util.List<java.lang.String> queryIds)Delete queries from the monitor by IDintgetDisjunctCount()MonitorQuerygetQuery(java.lang.String queryId)Get the MonitorQuery for a given query idMonitor.QueryCacheStatsgetQueryCacheStats()intgetQueryCount()java.util.Set<java.lang.String>getQueryIds()<T extends QueryMatch>
MultiMatchingQueries<T>match(Document[] docs, MatcherFactory<T> factory)Match an array ofDocuments against the queryindex, calling aCandidateMatcherproduced by the suppliedMatcherFactoryfor each possible matching query.<T extends QueryMatch>
MatchingQueries<T>match(Document doc, MatcherFactory<T> factory)Match a singleDocumentagainst the queryindex, calling aCandidateMatcherproduced by the suppliedMatcherFactoryfor each possible matching query.voidpurgeCache()Remove unused queries from the query cache.voidregister(java.lang.Iterable<MonitorQuery> queries)Add new queries to the monitorvoidregister(MonitorQuery... queries)Add new queries to the monitor
-
-
-
Field Detail
-
presearcher
protected final Presearcher presearcher
-
analyzer
private final Analyzer analyzer
-
queryIndex
private final QueryIndex queryIndex
-
listeners
private final java.util.List<MonitorUpdateListener> listeners
-
commitBatchSize
private final long commitBatchSize
-
purgeExecutor
private final java.util.concurrent.ScheduledExecutorService purgeExecutor
-
lastPurged
private long lastPurged
-
-
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 analyzeDocuments 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 analyzeDocuments at match timepresearcher- 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 analyzeDocuments at match timeconfig- 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 analyzeDocuments at match timepresearcher- the presearcher to useconfiguration- the configuration- Throws:
java.io.IOException
-
-
Method Detail
-
addQueryIndexUpdateListener
public void addQueryIndexUpdateListener(MonitorUpdateListener listener)
Register aMonitorUpdateListenerthat will be notified whenever changes are made to the Monitor's queryindex- Parameters:
listener- listener to register
-
getQueryCacheStats
public Monitor.QueryCacheStats getQueryCacheStats()
- Returns:
- Statistics for the internal query index and cache
-
purgeCache
public void purgeCache() throws java.io.IOExceptionRemove unused queries from the query cache.This is normally called from a background thread at a rate set by configurePurgeFrequency().
- Throws:
java.io.IOException- on IO errors
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.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.IOExceptionDelete 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.IOExceptionDelete 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.IOExceptionDelete all queries from the monitor- Throws:
java.io.IOException- on IO errors
-
match
public <T extends QueryMatch> MultiMatchingQueries<T> match(Document[] docs, MatcherFactory<T> factory) throws java.io.IOException
Match an array ofDocuments against the queryindex, calling aCandidateMatcherproduced by the suppliedMatcherFactoryfor each possible matching query.- Type Parameters:
T- the type ofQueryMatchto return- Parameters:
docs- the DocumentBatch to matchfactory- aMatcherFactoryto use to create aCandidateMatcherfor the match run- Returns:
- a
MatchingQueriesobject summarizing the match run. - Throws:
java.io.IOException- on IO errors
-
match
public <T extends QueryMatch> MatchingQueries<T> match(Document doc, MatcherFactory<T> factory) throws java.io.IOException
Match a singleDocumentagainst the queryindex, calling aCandidateMatcherproduced by the suppliedMatcherFactoryfor each possible matching query.- Type Parameters:
T- the type ofQueryMatchto return- Parameters:
doc- the InputDocument to matchfactory- aMatcherFactoryto use to create aCandidateMatcherfor the match run- Returns:
- a
MatchingQueriesobject summarizing the match run. - 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 errorsjava.lang.IllegalStateException- if queries are not stored in the queryindex
-
getDisjunctCount
public int getDisjunctCount()
- Returns:
- the number of queries (after decomposition) stored in this Monitor
-
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 QueryMatch> PresearcherMatches<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 indexfactory- aMatcherFactoryto use to create aCandidateMatcherfor the match run- Returns:
- a
PresearcherMatchesobject containing debug information - Throws:
java.io.IOException- on IO errors
-
debug
public <T extends QueryMatch> PresearcherMatches<T> debug(Document doc, MatcherFactory<T> factory) throws java.io.IOException
Match a singleDocumentagainst 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 indexfactory- aMatcherFactoryto use to create aCandidateMatcherfor the match run- Returns:
- a
PresearcherMatchesobject containing debug information - Throws:
java.io.IOException- on IO errors
-
-