Upgrade to Lucene 4.5.1

This commit is contained in:
Simon Willnauer 2013-10-18 15:41:37 +02:00
parent e981e411d7
commit 3a34aa735e
10 changed files with 24 additions and 100 deletions

View File

@ -30,7 +30,7 @@
</parent>
<properties>
<lucene.version>4.5.0</lucene.version>
<lucene.version>4.5.1</lucene.version>
<tests.jvms>1</tests.jvms>
<tests.shuffle>true</tests.shuffle>
<tests.output>onerror</tests.output>

View File

@ -17,11 +17,7 @@ package org.apache.lucene.queries;
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.search.*;
import org.apache.lucene.search.BooleanClause.Occur;
import org.elasticsearch.Version;
import org.elasticsearch.common.lucene.search.Queries;
/**
@ -74,70 +70,4 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery {
public String getLowFreqMinimumNumberShouldMatchSpec() {
return lowFreqMinNumShouldMatchSpec;
}
static {
assert Version.CURRENT.luceneVersion.compareTo(org.apache.lucene.util.Version.LUCENE_45) == 0 : "Remove buildQuery() once 4.6 is out";
}
@Override
protected Query buildQuery(final int maxDoc,
final TermContext[] contextArray, final Term[] queryTerms) {
BooleanQuery lowFreq = new BooleanQuery(disableCoord);
BooleanQuery highFreq = new BooleanQuery(disableCoord);
highFreq.setBoost(highFreqBoost);
lowFreq.setBoost(lowFreqBoost);
BooleanQuery query = new BooleanQuery(true);
for (int i = 0; i < queryTerms.length; i++) {
TermContext termContext = contextArray[i];
if (termContext == null) {
lowFreq.add(new TermQuery(queryTerms[i]), lowFreqOccur);
} else {
if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency)
|| (termContext.docFreq() > (int) Math.ceil(maxTermFrequency
* (float) maxDoc))) {
highFreq
.add(new TermQuery(queryTerms[i], termContext), highFreqOccur);
} else {
lowFreq.add(new TermQuery(queryTerms[i], termContext), lowFreqOccur);
}
}
}
final int numLowFreqClauses = lowFreq.clauses().size();
final int numHighFreqClauses = highFreq.clauses().size();
if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) {
int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
lowFreq.setMinimumNumberShouldMatch(minMustMatch);
}
if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) {
int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
highFreq.setMinimumNumberShouldMatch(minMustMatch);
}
if (lowFreq.clauses().isEmpty()) {
/*
* if lowFreq is empty we rewrite the high freq terms in a conjunction to
* prevent slow queries.
* Only if a specic high_freq should_match is not specified.
*/
if (highFreq.getMinimumNumberShouldMatch() == 0 && highFreqOccur != Occur.MUST) {
for (BooleanClause booleanClause : highFreq) {
booleanClause.setOccur(Occur.MUST);
}
}
highFreq.setBoost(getBoost());
return highFreq;
} else if (highFreq.clauses().isEmpty()) {
// only do low freq terms - we don't have high freq terms
lowFreq.setBoost(getBoost());
return lowFreq;
} else {
query.add(highFreq, Occur.SHOULD);
query.add(lowFreq, Occur.MUST);
query.setBoost(getBoost());
return query;
}
}
}

View File

@ -48,8 +48,8 @@ public class SimpleDocSetCache extends AbstractIndexComponent implements DocSetC
}
@Override
public void onClose(SegmentReader owner) {
cache.remove(owner.getCoreCacheKey());
public void onClose(Object coreCacheKey) {
cache.remove(coreCacheKey);
}
@Override

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.cache.filter;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;
import org.elasticsearch.common.component.CloseableComponent;
import org.elasticsearch.index.IndexComponent;
@ -47,7 +46,7 @@ public interface FilterCache extends IndexComponent, CloseableComponent {
Filter cache(Filter filterToCache);
void clear(IndexReader reader);
void clear(Object reader);
void clear(String reason);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.cache.filter.none;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -71,7 +70,7 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac
}
@Override
public void clear(IndexReader reader) {
public void clear(Object reader) {
// nothing to do here
}
}

View File

@ -23,7 +23,6 @@ import com.google.common.cache.Cache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.Weigher;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SegmentReader;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
@ -105,19 +104,19 @@ public class WeightedFilterCache extends AbstractIndexComponent implements Filte
}
@Override
public void onClose(SegmentReader owner) {
clear(owner);
public void onClose(Object coreKey) {
clear(coreKey);
}
@Override
public void clear(IndexReader reader) {
public void clear(Object coreCacheKey) {
// we add the seen reader before we add the first cache entry for this reader
// so, if we don't see it here, its won't be in the cache
Boolean removed = seenReaders.remove(reader.getCoreCacheKey());
Boolean removed = seenReaders.remove(coreCacheKey);
if (removed == null) {
return;
}
indicesFilterCache.addReaderKeyToClean(reader.getCoreCacheKey());
indicesFilterCache.addReaderKeyToClean(coreCacheKey);
}
@Override

View File

@ -21,7 +21,6 @@ package org.elasticsearch.index.cache.id;
import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.elasticsearch.common.component.CloseableComponent;
import org.elasticsearch.index.IndexComponent;
import org.elasticsearch.index.service.IndexService;
@ -40,7 +39,7 @@ public interface IdCache extends IndexComponent, CloseableComponent, Iterable<Id
void clear();
void clear(IndexReader reader);
void clear(Object coreCacheKey);
void refresh(List<AtomicReaderContext> readers) throws IOException;

View File

@ -83,13 +83,13 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se
}
@Override
public void onClose(SegmentReader owner) {
clear(owner);
public void onClose(Object coreCacheKey) {
clear(coreCacheKey);
}
@Override
public void clear(IndexReader reader) {
SimpleIdReaderCache removed = idReaders.remove(reader.getCoreCacheKey());
public void clear(Object coreCacheKey) {
SimpleIdReaderCache removed = idReaders.remove(coreCacheKey);
if (removed != null) onRemoval(removed);
}

View File

@ -24,7 +24,6 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SegmentReader;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.index.mapper.FieldMapper;
@ -52,7 +51,7 @@ public interface IndexFieldDataCache {
*/
void clear(String fieldName);
void clear(IndexReader reader);
void clear(Object coreCacheKey);
interface Listener {
@ -134,13 +133,13 @@ public interface IndexFieldDataCache {
}
@Override
public void clear(IndexReader reader) {
cache.invalidate(new Key(reader.getCoreCacheKey()));
public void clear(Object coreCacheKey) {
cache.invalidate(new Key(coreCacheKey));
}
@Override
public void onClose(SegmentReader owner) {
cache.invalidate(new Key(owner.getCoreCacheKey()));
public void onClose(Object coreCacheKey) {
cache.invalidate(new Key(coreCacheKey));
}
static class Key {

View File

@ -21,7 +21,6 @@ package org.elasticsearch.indices.fielddata.cache;
import com.google.common.cache.*;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SegmentReader;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.AbstractComponent;
@ -169,8 +168,8 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
}
@Override
public void onClose(SegmentReader owner) {
cache.invalidate(new Key(this, owner.getCoreCacheKey()));
public void onClose(Object coreKey) {
cache.invalidate(new Key(this, coreKey));
}
@Override
@ -194,8 +193,8 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL
}
@Override
public void clear(IndexReader reader) {
cache.invalidate(new Key(this, reader.getCoreCacheKey()));
public void clear(Object coreCacheKey) {
cache.invalidate(new Key(this, coreCacheKey));
}
}