mirror of https://github.com/apache/lucene.git
Revert "GH#11601: Add ability to compute reader states after refresh"
This reverts commit bde4051374
.
This commit is contained in:
parent
e2e848ea61
commit
c16ebc9be2
|
@ -219,36 +219,6 @@ public abstract class ReferenceManager<G> implements Closeable {
|
||||||
return doTryRefresh;
|
return doTryRefresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute some state of the reference using a parameter. */
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface StateCalculator<R, G, P> {
|
|
||||||
R calculate(G current, P param);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If you need to compute something after the refresh, you can use this method instead of {@link
|
|
||||||
* #maybeRefresh()}.
|
|
||||||
*
|
|
||||||
* @throws IOException if refreshing the resource causes an {@link IOException}
|
|
||||||
*/
|
|
||||||
public final <R, P> R maybeRefreshAndReturnState(
|
|
||||||
StateCalculator<R, G, P> refreshedStateCalculator, P param) throws IOException {
|
|
||||||
ensureOpen();
|
|
||||||
|
|
||||||
// Ensure only 1 thread does refresh at once; other threads just return immediately:
|
|
||||||
final boolean doTryRefresh = refreshLock.tryLock();
|
|
||||||
if (doTryRefresh) {
|
|
||||||
try {
|
|
||||||
doMaybeRefresh();
|
|
||||||
return refreshedStateCalculator.calculate(current, param);
|
|
||||||
} finally {
|
|
||||||
refreshLock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You must call this (or {@link #maybeRefresh()}), periodically, if you want that {@link
|
* You must call this (or {@link #maybeRefresh()}), periodically, if you want that {@link
|
||||||
* #acquire()} will return refreshed instances.
|
* #acquire()} will return refreshed instances.
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.facet.sortedset;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.apache.lucene.facet.FacetsConfig;
|
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
|
||||||
import org.apache.lucene.search.ReferenceManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get reader states after a refresh. Example call: readerStates =
|
|
||||||
* searcherManager.maybeRefreshAndReturnState(new SSDVReaderStatesCalculator(), config);
|
|
||||||
*/
|
|
||||||
public class SSDVReaderStatesCalculator
|
|
||||||
implements ReferenceManager.StateCalculator<
|
|
||||||
List<SortedSetDocValuesReaderState>, IndexSearcher, FacetsConfig> {
|
|
||||||
|
|
||||||
/** No arguments needed */
|
|
||||||
public SSDVReaderStatesCalculator() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SortedSetDocValuesReaderState> calculate(IndexSearcher current, FacetsConfig config) {
|
|
||||||
return config.getDimConfigs().keySet().stream()
|
|
||||||
.map(
|
|
||||||
field -> {
|
|
||||||
try {
|
|
||||||
return new DefaultSortedSetDocValuesReaderState(
|
|
||||||
current.getIndexReader(), field, config);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue