This commit is contained in:
Andrea Cavalli 2021-02-16 23:15:56 +01:00
parent 787092c6f9
commit c36824699a
4 changed files with 26 additions and 2 deletions

View File

@ -512,13 +512,13 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
keyFieldName,
keyScore -> {
EmitResult result = topKeysSink.tryEmitNext(fixKeyScore(keyScore, scoreDivisor));
if (result.isFailure()) {
if (result.isFailure() && result != EmitResult.FAIL_CANCELLED) {
throw new EmissionException(result);
}
},
totalHitsCount -> {
EmitResult result = totalHitsCountSink.tryEmitValue(totalHitsCount);
if (result.isFailure()) {
if (result.isFailure() && result != EmitResult.FAIL_CANCELLED) {
throw new EmissionException(result);
}
}

View File

@ -7,9 +7,11 @@ public class PhraseQuery implements Query {
// some terms can be null
private final TermPosition[] parts;
private int slop;
public PhraseQuery(TermPosition... parts) {
this.parts = parts;
this.slop = 0;
}
@Override
@ -21,6 +23,7 @@ public class PhraseQuery implements Query {
StringifyUtils.stringifyTermPosition(listData, part);
}
StringifyUtils.writeHeader(data, QueryConstructorType.TERM_POSITION_LIST, listData);
StringifyUtils.stringifyInt(data, slop);
StringifyUtils.writeHeader(output, QueryConstructorType.PHRASE_QUERY, data);
}
@ -28,4 +31,9 @@ public class PhraseQuery implements Query {
public String toString() {
return Arrays.stream(parts).map(Object::toString).collect(Collectors.joining(", ", "(", ")"));
}
public PhraseQuery setSlop(int slop) {
this.slop = slop;
return this;
}
}

View File

@ -103,6 +103,19 @@ public interface Query extends SerializedQueryObject {
}
return new BooleanQuery(queryParts).setMinShouldMatch(booleanQuery.getMinimumNumberShouldMatch());
}
if (luceneQuery instanceof org.apache.lucene.search.PhraseQuery) {
var phraseQuery = (org.apache.lucene.search.PhraseQuery) luceneQuery;
int slop = phraseQuery.getSlop();
var terms = phraseQuery.getTerms();
var positions = phraseQuery.getPositions();
TermPosition[] termPositions = new TermPosition[terms.length];
for (int i = 0; i < terms.length; i++) {
var term = terms[i];
var position = positions[i];
termPositions[i] = new TermPosition(term, position);
}
return new PhraseQuery(termPositions).setSlop(slop);
}
org.apache.lucene.search.SynonymQuery synonymQuery = (org.apache.lucene.search.SynonymQuery) luceneQuery;
return new SynonymQuery(field,
synonymQuery.getTerms().stream().map(TermQuery::new).toArray(TermQuery[]::new)

View File

@ -2,6 +2,7 @@ package it.cavallium.dbengine.lucene.serializer;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;
import java.util.PrimitiveIterator;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.document.IntPoint;
@ -98,6 +99,8 @@ public class QueryParser {
pqB.add(pqTerm.getTerm(), pqTerm.getPosition());
}
}
Integer slops = Objects.requireNonNull((Integer) parse(completeText, position));
pqB.setSlop(slops);
return pqB.build();
case SYNONYM_QUERY:
var fieldName = (String) parse(completeText, position);