romseygeek commented on a change in pull request #679: URL: https://github.com/apache/lucene/pull/679#discussion_r809038865
########## File path: lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java ########## @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.monitor; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.*; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.IOUtils; + +class ReadonlyQueryIndex implements QueryIndex { + private final SearcherManager manager; + private final QueryDecomposer decomposer; + private final MonitorQuerySerializer serializer; + + final Map<IndexReader.CacheKey, WritableQueryIndex.QueryTermFilter> termFilters = new HashMap<>(); + + public ReadonlyQueryIndex(MonitorConfiguration configuration) throws IOException { + if (configuration.getDirectoryProvider() == null) { + throw new IllegalStateException( + "You must specify a Directory when configuring a Monitor as read-only."); + } + Directory directory = configuration.getDirectoryProvider().get(); + this.manager = new SearcherManager(directory, new TermsHashBuilder(termFilters)); + this.decomposer = configuration.getQueryDecomposer(); + this.serializer = configuration.getQuerySerializer(); Review comment: So the way the Monitor works at the moment is that it parses all the serialized queries in its QueryIndex on startup, and stores them in an in-memory cache. This means that when we run a document through the Monitor, once it has identified which candidate queries to run against it we don't need to re-parse them, they are already instantiated in RAM. The alternative, which I think is what you've implemented here, is to re-parse the query every time we need to run it. This is perfectly reasonable (in fact it's what elasticsearch's percolator does) but it is a significant change in behaviour so I don't think we should fold it in as part of this ticket. The Writeable query index needs to have all the tricksy behaviour around re-populating the cache, as we need to remove deleted entries or replace updated entries when queries are added or deleted (cache invalidation is hard, apparently!); the read-only index can just hold everything in a single Map that is populated on startup and never changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org