From 1fc6ab2e4aed3fee3c9aba6c6fbdc4b7edabf366 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Tue, 2 Mar 2021 01:53:36 +0100 Subject: [PATCH] Generated serializable queries --- pom.xml | 23 ++ .../IndicizationExample.java | 33 +- src/main/data-generator/lucene-query.yaml | 198 ++++++++++++ .../dbengine/client/LuceneIndex.java | 95 +++--- .../cavallium/dbengine/client/MultiSort.java | 23 +- .../client/query/ClientQueryParams.java | 82 +++++ .../dbengine/client/query/QueryGson.java | 88 ++++++ .../dbengine/client/query/QueryParser.java | 58 ++++ .../query/QueryUtils.java} | 101 +++--- .../dbengine/database/LLLuceneIndex.java | 41 +-- .../database/disk/LLLocalLuceneIndex.java | 122 +++----- .../disk/LLLocalMultiLuceneIndex.java | 48 +-- .../dbengine/lucene/LuceneUtils.java | 9 - .../lucene/serializer/BooleanQuery.java | 43 --- .../lucene/serializer/BooleanQueryInfo.java | 42 --- .../lucene/serializer/BooleanQueryPart.java | 25 -- .../lucene/serializer/BoostQuery.java | 25 -- .../lucene/serializer/ConstantScoreQuery.java | 22 -- .../serializer/DocValuesFieldExistsQuery.java | 26 -- .../lucene/serializer/FuzzyQuery.java | 50 --- .../lucene/serializer/IntPointExactQuery.java | 20 -- .../lucene/serializer/IntPointRangeQuery.java | 23 -- .../serializer/LongPointExactQuery.java | 20 -- .../serializer/LongPointRangeQuery.java | 23 -- .../lucene/serializer/MatchAllDocsQuery.java | 13 - .../dbengine/lucene/serializer/Occur.java | 41 --- .../lucene/serializer/ParseException.java | 8 - .../lucene/serializer/PhraseQuery.java | 39 --- .../serializer/QueryConstructorType.java | 35 --- .../lucene/serializer/QueryParser.java | 295 ------------------ .../serializer/SerializedQueryObject.java | 9 - ...edNumericDocValuesFieldSlowRangeQuery.java | 24 -- .../lucene/serializer/StringifyUtils.java | 61 ---- .../lucene/serializer/SynonymQuery.java | 34 -- .../lucene/serializer/TermPosition.java | 32 -- .../dbengine/lucene/serializer/TermQuery.java | 37 --- .../lucene/serializer/WildcardQuery.java | 37 --- 37 files changed, 640 insertions(+), 1265 deletions(-) create mode 100644 src/main/data-generator/lucene-query.yaml create mode 100644 src/main/java/it/cavallium/dbengine/client/query/ClientQueryParams.java create mode 100644 src/main/java/it/cavallium/dbengine/client/query/QueryGson.java create mode 100644 src/main/java/it/cavallium/dbengine/client/query/QueryParser.java rename src/main/java/it/cavallium/dbengine/{lucene/serializer/Query.java => client/query/QueryUtils.java} (52%) delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryInfo.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryPart.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/BoostQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/ConstantScoreQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/DocValuesFieldExistsQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/FuzzyQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointExactQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointRangeQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointExactQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointRangeQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/MatchAllDocsQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/Occur.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/ParseException.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/PhraseQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/QueryConstructorType.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/QueryParser.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/SerializedQueryObject.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/SortedNumericDocValuesFieldSlowRangeQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/StringifyUtils.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/SynonymQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/TermPosition.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/TermQuery.java delete mode 100644 src/main/java/it/cavallium/dbengine/lucene/serializer/WildcardQuery.java diff --git a/pom.xml b/pom.xml index a081a2a..8f5dc4a 100644 --- a/pom.xml +++ b/pom.xml @@ -178,6 +178,11 @@ lucene-relevance 8.0.0.0.5 + + it.cavallium + data-generator + 0.9.0-SNAPSHOT + src/test/java @@ -230,6 +235,24 @@ false + + it.cavallium + data-generator + 0.9.0-SNAPSHOT + + + generate-lucene-query-sources + generate-sources + + run + + + it.cavallium.dbengine.client.query + ${basedir}/src/main/data-generator/lucene-query.yaml + + + + diff --git a/src/example/java/it.cavallium.dbengine.client/IndicizationExample.java b/src/example/java/it.cavallium.dbengine.client/IndicizationExample.java index 1104a4e..7f1c96c 100644 --- a/src/example/java/it.cavallium.dbengine.client/IndicizationExample.java +++ b/src/example/java/it.cavallium.dbengine.client/IndicizationExample.java @@ -1,16 +1,17 @@ package it.cavallium.dbengine.client; +import it.cavallium.dbengine.client.query.QueryUtils; +import it.cavallium.dbengine.client.query.current.data.QueryParams; +import it.cavallium.dbengine.client.query.current.data.ScoreMode; +import it.cavallium.dbengine.client.query.current.data.ScoreSort; import it.cavallium.dbengine.database.LLDocument; import it.cavallium.dbengine.database.LLItem; import it.cavallium.dbengine.database.LLLuceneIndex; -import it.cavallium.dbengine.database.LLScoreMode; -import it.cavallium.dbengine.database.LLSort; import it.cavallium.dbengine.database.LLTerm; +import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection; import it.cavallium.dbengine.lucene.LuceneUtils; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity; -import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection; -import it.cavallium.dbengine.lucene.serializer.Query; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -36,11 +37,13 @@ public class IndicizationExample { ) .then(index.refresh()) .then(index.search(null, - Query.exactSearch(TextFieldsAnalyzer.N4GramPartialString, "name", "Mario"), - 1, - LLSort.newSortScore(), - LLScoreMode.COMPLETE, - null, + QueryParams + .builder() + .query(QueryUtils.exactSearch(TextFieldsAnalyzer.N4GramPartialString, "name", "Mario")) + .limit(1) + .sort(ScoreSort.of()) + .scoreMode(ScoreMode.of(false, true)) + .build(), "id" )) .flatMap(results -> results @@ -106,8 +109,16 @@ public class IndicizationExample { }) )) .then(index.refresh()) - .then(index.search(null, Query.exactSearch(TextFieldsAnalyzer.N4GramPartialString,"name", "Mario"), 10, MultiSort.topScore() - .getQuerySort(), LLScoreMode.COMPLETE, null, "id")) + .then(index.search(null, + QueryParams + .builder() + .query(QueryUtils.exactSearch(TextFieldsAnalyzer.N4GramPartialString, "name", "Mario")) + .limit(10) + .sort(MultiSort.topScore().getQuerySort()) + .scoreMode(ScoreMode.of(false, true)) + .build(), + "id" + )) .flatMap(results -> LuceneUtils.mergeStream(results .results(), MultiSort.topScoreRaw(), 10L) .doOnNext(value -> System.out.println("Value: " + value)) diff --git a/src/main/data-generator/lucene-query.yaml b/src/main/data-generator/lucene-query.yaml new file mode 100644 index 0000000..bf54085 --- /dev/null +++ b/src/main/data-generator/lucene-query.yaml @@ -0,0 +1,198 @@ +# A type that starts with "-" is an optional type, otherwise it can't be null +currentVersion: "0.0.0" +interfacesData: + Query: [] +# versions must have only numbers, lowercase letters, dots, dashes. Maximum: 99.999.9999 +versions: + 0.0.0: + details: + changelog: "First version" + superTypes: + Query: [ + BoxedQuery, TermQuery, PhraseQuery, WildcardQuery, SynonymQuery, FuzzyQuery, MatchAllDocsQuery, + MatchNoDocsQuery, BooleanQuery, SortedNumericDocValuesFieldSlowRangeQuery, SortedDocFieldExistsQuery, + ConstantScoreQuery, BoostQuery, IntPointRangeQuery, LongPointRangeQuery, IntPointExactQuery, + LongPointExactQuery + ] + Occur: [OccurMust, OccurMustNot, OccurShould, OccurFilter] + Sort: [NoSort, NumericSort, ScoreSort, DocSort, RandomSort] + customTypes: {} + classes: + + # Basic data + # ========== + + # Wrapper for type Query + BoxedQuery: + data: + query: Query + # A term consists in a field that is exactly equal to the value string + Term: + data: + field: String + value: String + # A Term with a position relative to the start of the query. Used internally in some specific queries + TermPosition: + data: + term: Term + position: int + # A Term with a specified boost. Used internally in some specific queries + TermAndBoost: + data: + term: Term + boost: float + # Occur options used for boolean queries + OccurMust: + data: { } + OccurMustNot: + data: { } + OccurShould: + data: { } + OccurFilter: + data: { } + + # Text queries + # ============ + + # Query that matches a term. + TermQuery: + data: + term: Term + # Query that matches a phrase. + PhraseQuery: + data: + # A phrase is a collection of positioned terms, with absolute positions, + # counted as characters from the beginning of the phrase. + phrase: TermPosition[] + slop: int + # Advanced query that matches text allowing asterisks in the query + WildcardQuery: + data: + field: String + pattern: String # Example: "*ing" + # Advanced query that matches different exact values (synonyms) + SynonymQuery: + data: + field: String + parts: TermAndBoost[] # Each term has a boost. The preferred synonym has the highest boost value. + # Advanced query. todo: document it + FuzzyQuery: + data: + term: Term + maxEdits: int + prefixLength: int + maxExpansions: int + transpositions: boolean + + + # Combination queries + # =================== + + # Query that matches everything + MatchAllDocsQuery: + data: {} + # Query that matches nothing + MatchNoDocsQuery: + data: {} + # Query that matches if the document satisfies all the required parts + BooleanQuery: + data: + # Each part can be: + # - "MUST" + # - "MUST_NOT" + # - "SHOULD" + # - "FILTER" (advanced, ignore this) + # "SHOULD" is like "MUST" but it's not necessary. + parts: BooleanQueryPart[] + minShouldMatch: int # If set, it specifies how many "SHOULD" parts must be matched. 0 if not set + # Part of a boolean query + BooleanQueryPart: + data: + query: Query + occur: Occur + + + # Number queries + # ============== + + # Advanced query that matches only a range of a sorted field, from "min" to "max". + SortedNumericDocValuesFieldSlowRangeQuery: + data: + field: String + min: long + max: long + # Query that matches if the sorted field exist in the document + SortedDocFieldExistsQuery: + data: + field: String + + + # Score modifying queries + # ============ + + # Query that fixes the score of a query + ConstantScoreQuery: + data: + query: Query + score: float + # Query that boosts the query score + BoostQuery: + data: + query: Query + scoreBoost: float + + + # Sorted fields queries + # ===================== + + # Query that matches an int point field, from "min", to "max" + IntPointRangeQuery: + data: + field: String + min: int + max: int + # Query that matches a long point field, from "min", to "max" + LongPointRangeQuery: + data: + field: String + min: long + max: long + # Query that matches an int point field + IntPointExactQuery: + data: + field: String + value: int + # Query that matches a long point field + LongPointExactQuery: + data: + field: String + value: long + + + # Extra data used for parameters and the client + # ============================================= + + # Query parameters + QueryParams: + data: + query: Query + limit: long + minCompetitiveScore: -float + sort: Sort + scoreMode: ScoreMode + NoSort: + data: { } + NumericSort: + data: + field: String + reverse: boolean + RandomSort: + data: { } + ScoreSort: + data: { } + DocSort: + data: { } + ScoreMode: + data: + onlyTopScores: boolean + computeScores: boolean diff --git a/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java b/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java index ba710cb..eda2bbb 100644 --- a/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java @@ -1,15 +1,15 @@ package it.cavallium.dbengine.client; +import it.cavallium.dbengine.client.query.ClientQueryParams; +import it.cavallium.dbengine.client.query.current.data.Query; import it.cavallium.dbengine.database.LLLuceneIndex; import it.cavallium.dbengine.database.LLScoreMode; import it.cavallium.dbengine.database.LLSearchResult; import it.cavallium.dbengine.database.LLSnapshot; import it.cavallium.dbengine.database.LLSnapshottable; -import it.cavallium.dbengine.database.LLSort; import it.cavallium.dbengine.database.LLTerm; -import it.cavallium.dbengine.lucene.LuceneUtils; import it.cavallium.dbengine.database.collections.Joiner.ValueGetter; -import it.cavallium.dbengine.lucene.serializer.Query; +import it.cavallium.dbengine.lucene.LuceneUtils; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -112,96 +112,95 @@ public class LuceneIndex implements LLSnapshottable { /** * - * @param limit the limit is valid for each lucene instance. + * @param queryParams the limit is valid for each lucene instance. * If you have 15 instances, the number of elements returned * can be at most limit * 15 * @return the collection has one or more flux */ - public Mono> moreLikeThis(@Nullable CompositeSnapshot snapshot, + public Mono> moreLikeThis( + ClientQueryParams> queryParams, T key, - U mltDocumentValue, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore) { + U mltDocumentValue) { Flux>> mltDocumentFields = indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue); return luceneIndex - .moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit, - minCompetitiveScore, enableScoring, sortByScore, indicizer.getKeyFieldName()) - .map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit)); + .moreLikeThis(resolveSnapshot(queryParams.getSnapshot()), queryParams.toQueryParams(), indicizer.getKeyFieldName(), mltDocumentFields) + .map(llSearchResult -> this.transformLuceneResult(llSearchResult, + queryParams.getSort(), + queryParams.getScoreMode(), + queryParams.getLimit() + )); } /** * - * @param limit the limit is valid for each lucene instance. + * @param queryParams the limit is valid for each lucene instance. * If you have 15 instances, the number of elements returned * can be at most limit * 15 * @return the collection has one or more flux */ - public Mono> moreLikeThisWithValues(@Nullable CompositeSnapshot snapshot, + public Mono> moreLikeThisWithValues( + ClientQueryParams> queryParams, T key, U mltDocumentValue, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, ValueGetter valueGetter) { Flux>> mltDocumentFields = indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue); return luceneIndex - .moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit, - minCompetitiveScore, enableScoring, sortByScore, indicizer.getKeyFieldName()) - .map(llSearchResult -> - this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter)); + .moreLikeThis(resolveSnapshot(queryParams.getSnapshot()), + queryParams.toQueryParams(), + indicizer.getKeyFieldName(), + mltDocumentFields + ) + .map(llSearchResult -> this.transformLuceneResultWithValues(llSearchResult, + queryParams.getSort(), + queryParams.getScoreMode(), + queryParams.getLimit(), + valueGetter + )); } /** * - * @param limit the limit is valid for each lucene instance. + * @param queryParams the limit is valid for each lucene instance. * If you have 15 instances, the number of elements returned * can be at most limit * 15 * @return the collection has one or more flux */ - public Mono> search(@Nullable CompositeSnapshot snapshot, - Query query, - long limit, - @Nullable MultiSort> sort, - LLScoreMode scoreMode, - @Nullable Float minCompetitiveScore) { - LLSort querySort = sort != null ? sort.getQuerySort() : null; + public Mono> search( + ClientQueryParams> queryParams) { return luceneIndex - .search(resolveSnapshot(snapshot), query, limit, querySort, scoreMode, minCompetitiveScore, - indicizer.getKeyFieldName()) - .map(llSearchResult -> this.transformLuceneResult(llSearchResult, sort, scoreMode, limit)); + .search(resolveSnapshot(queryParams.getSnapshot()), queryParams.toQueryParams(), indicizer.getKeyFieldName()) + .map(llSearchResult -> this.transformLuceneResult(llSearchResult, + queryParams.getSort(), + queryParams.getScoreMode(), + queryParams.getLimit() + )); } /** * - * @param limit the limit is valid for each lucene instance. + * @param queryParams the limit is valid for each lucene instance. * If you have 15 instances, the number of elements returned * can be at most limit * 15 * @return the collection has one or more flux */ - public Mono> searchWithValues(@Nullable CompositeSnapshot snapshot, - Query query, - long limit, - @Nullable MultiSort> sort, - LLScoreMode scoreMode, - @Nullable Float minCompetitiveScore, + public Mono> searchWithValues( + ClientQueryParams> queryParams, ValueGetter valueGetter) { - LLSort querySort = sort != null ? sort.getQuerySort() : null; return luceneIndex - .search(resolveSnapshot(snapshot), query, limit, querySort, scoreMode, minCompetitiveScore, - indicizer.getKeyFieldName()) - .map(llSearchResult -> this.transformLuceneResultWithValues(llSearchResult, sort, scoreMode, limit, valueGetter)); + .search(resolveSnapshot(queryParams.getSnapshot()), queryParams.toQueryParams(), indicizer.getKeyFieldName()) + .map(llSearchResult -> this.transformLuceneResultWithValues(llSearchResult, + queryParams.getSort(), + queryParams.getScoreMode(), + queryParams.getLimit(), + valueGetter + )); } public Mono count(@Nullable CompositeSnapshot snapshot, Query query) { - return this.search(snapshot, query, 0, null, LLScoreMode.COMPLETE_NO_SCORES, null) + return this.search(ClientQueryParams.>builder().snapshot(snapshot).query(query).limit(0).build()) .flatMap(SearchResultKeys::totalHitsCount) .single(); } diff --git a/src/main/java/it/cavallium/dbengine/client/MultiSort.java b/src/main/java/it/cavallium/dbengine/client/MultiSort.java index 38571fb..bb60e68 100644 --- a/src/main/java/it/cavallium/dbengine/client/MultiSort.java +++ b/src/main/java/it/cavallium/dbengine/client/MultiSort.java @@ -1,17 +1,20 @@ package it.cavallium.dbengine.client; +import it.cavallium.dbengine.client.query.current.data.NumericSort; +import it.cavallium.dbengine.client.query.current.data.RandomSort; +import it.cavallium.dbengine.client.query.current.data.ScoreSort; +import it.cavallium.dbengine.client.query.current.data.Sort; import it.cavallium.dbengine.database.LLKeyScore; -import it.cavallium.dbengine.database.LLSort; import java.util.Comparator; import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; public class MultiSort { - private final LLSort querySort; + private final Sort querySort; private final Comparator resultSort; - public MultiSort(LLSort querySort, Comparator resultSort) { + public MultiSort(Sort querySort, Comparator resultSort) { this.querySort = querySort; this.resultSort = resultSort; } @@ -26,7 +29,7 @@ public class MultiSort { */ public static MultiSort sortedNumericInt(String fieldName, ToIntFunction toIntFunction, boolean reverse) { // Create lucene sort - LLSort querySort = LLSort.newSortedNumericSortField(fieldName, reverse); + Sort querySort = NumericSort.of(fieldName, reverse); // Create result sort Comparator resultSort = Comparator.comparingInt(toIntFunction); @@ -48,7 +51,7 @@ public class MultiSort { */ public static MultiSort sortedNumericLong(String fieldName, ToLongFunction toLongFunction, boolean reverse) { // Create lucene sort - LLSort querySort = LLSort.newSortedNumericSortField(fieldName, reverse); + Sort querySort = NumericSort.of(fieldName, reverse); // Create result sort Comparator resultSort = Comparator.comparingLong(toLongFunction); @@ -61,22 +64,22 @@ public class MultiSort { } public static MultiSort randomSortField() { - return new MultiSort<>(LLSort.newRandomSortField(), (a, b) -> 0); + return new MultiSort<>(RandomSort.of(), (a, b) -> 0); } public static MultiSort topScoreRaw() { - return new MultiSort<>(LLSort.newSortScore(), Comparator.comparingDouble(LLKeyScore::getScore).reversed()); + return new MultiSort<>(ScoreSort.of(), Comparator.comparingDouble(LLKeyScore::getScore).reversed()); } public static MultiSort> topScore() { - return new MultiSort<>(LLSort.newSortScore(), Comparator.>comparingDouble(SearchResultKey::getScore).reversed()); + return new MultiSort<>(ScoreSort.of(), Comparator.>comparingDouble(SearchResultKey::getScore).reversed()); } public static MultiSort> topScoreWithValues() { - return new MultiSort<>(LLSort.newSortScore(), Comparator.>comparingDouble(SearchResultItem::getScore).reversed()); + return new MultiSort<>(ScoreSort.of(), Comparator.>comparingDouble(SearchResultItem::getScore).reversed()); } - public LLSort getQuerySort() { + public Sort getQuerySort() { return querySort; } diff --git a/src/main/java/it/cavallium/dbengine/client/query/ClientQueryParams.java b/src/main/java/it/cavallium/dbengine/client/query/ClientQueryParams.java new file mode 100644 index 0000000..62dccb7 --- /dev/null +++ b/src/main/java/it/cavallium/dbengine/client/query/ClientQueryParams.java @@ -0,0 +1,82 @@ +package it.cavallium.dbengine.client.query; + +import it.cavallium.data.generator.nativedata.Nullablefloat; +import it.cavallium.dbengine.client.CompositeSnapshot; +import it.cavallium.dbengine.client.MultiSort; +import it.cavallium.dbengine.client.query.current.data.NoSort; +import it.cavallium.dbengine.client.query.current.data.Query; +import it.cavallium.dbengine.client.query.current.data.QueryParams; +import it.cavallium.dbengine.client.query.current.data.ScoreMode; +import it.cavallium.dbengine.database.LLScoreMode; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Builder.Default; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.ToString; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@EqualsAndHashCode +@AllArgsConstructor( + staticName = "of" +) +@Data +@Builder +@ToString +public final class ClientQueryParams { + + @Nullable + @Default + private CompositeSnapshot snapshot = null; + + @NotNull + @NonNull + private Query query; + + @Default + private long limit = Long.MAX_VALUE; + + @Nullable + @Default + private Float minCompetitiveScore = null; + + @Nullable + @Default + private MultiSort sort = null; + + @NotNull + @NonNull + @Default + private LLScoreMode scoreMode = LLScoreMode.COMPLETE; + + public ScoreMode toScoreMode() { + ScoreMode scoreMode; + switch (getScoreMode()) { + case COMPLETE: + scoreMode = ScoreMode.of(false, true); + break; + case COMPLETE_NO_SCORES: + scoreMode = ScoreMode.of(false, false); + break; + case TOP_SCORES: + scoreMode = ScoreMode.of(true, true); + break; + default: + throw new IllegalArgumentException(); + } + return scoreMode; + } + + public QueryParams toQueryParams() { + return QueryParams + .builder() + .query(getQuery()) + .sort(getSort() != null ? getSort().getQuerySort() : NoSort.of()) + .minCompetitiveScore(Nullablefloat.ofNullable(getMinCompetitiveScore())) + .limit(getLimit()) + .scoreMode(toScoreMode()) + .build(); + } +} diff --git a/src/main/java/it/cavallium/dbengine/client/query/QueryGson.java b/src/main/java/it/cavallium/dbengine/client/query/QueryGson.java new file mode 100644 index 0000000..9ecb66c --- /dev/null +++ b/src/main/java/it/cavallium/dbengine/client/query/QueryGson.java @@ -0,0 +1,88 @@ +package it.cavallium.dbengine.client.query; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonSyntaxException; +import it.cavallium.dbengine.client.query.current.CurrentVersion; +import it.cavallium.dbengine.client.query.current.data.IBasicType; +import it.cavallium.dbengine.client.query.current.data.IType; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Set; + +public class QueryGson { + + private static final HashMap, Set>> implementationClassesSerializers = new HashMap<>(); + private static final JsonElement EMPTY_JSON_OBJECT = new JsonObject(); + + static { + for (var superTypeClass : CurrentVersion.getSuperTypeClasses()) { + implementationClassesSerializers.put(superTypeClass, CurrentVersion.getSuperTypeSubtypesClasses(superTypeClass)); + } + } + + public static GsonBuilder registerAdapters(GsonBuilder gsonBuilder) { + implementationClassesSerializers.forEach((interfaceClass, implementationClasses) -> { + gsonBuilder.registerTypeAdapter(interfaceClass, new DbClassesGenericSerializer<>(implementationClasses)); + }); + return gsonBuilder; + } + + public static class DbClassesGenericSerializer implements JsonSerializer, JsonDeserializer { + + private final BiMap> subTypes; + + public DbClassesGenericSerializer(Set> implementationClasses) { + subTypes = HashBiMap.create(implementationClasses.size()); + for (Class implementationClass : implementationClasses) { + var name = implementationClass.getSimpleName(); + this.subTypes.put(name, implementationClass); + } + } + + @Override + public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject result = new JsonObject(); + Class type = src.getClass(); + if (!subTypes.inverse().containsKey(type)) { + throw new JsonSyntaxException("Unknown element type: " + type.getCanonicalName()); + } + result.add("type", new JsonPrimitive(subTypes.inverse().get(src.getClass()))); + if (Arrays + .stream(src.getClass().getDeclaredFields()) + .anyMatch(field -> !Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()))) { + result.add("properties", context.serialize(src, src.getClass())); + } + + return result; + } + + @Override + public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject jsonObject = json.getAsJsonObject(); + String type = jsonObject.get("type").getAsString(); + JsonElement element; + if (jsonObject.has("properties")) { + element = jsonObject.get("properties"); + } else { + element = EMPTY_JSON_OBJECT; + } + + if (!subTypes.containsKey(type)) { + throw new JsonParseException("Unknown element type: " + type); + } + return context.deserialize(element, subTypes.get(type)); + } + } +} \ No newline at end of file diff --git a/src/main/java/it/cavallium/dbengine/client/query/QueryParser.java b/src/main/java/it/cavallium/dbengine/client/query/QueryParser.java new file mode 100644 index 0000000..68b2b09 --- /dev/null +++ b/src/main/java/it/cavallium/dbengine/client/query/QueryParser.java @@ -0,0 +1,58 @@ +package it.cavallium.dbengine.client.query; + +import it.cavallium.dbengine.client.query.current.data.NumericSort; +import it.cavallium.dbengine.client.query.current.data.QueryParams; +import org.apache.commons.lang.NotImplementedException; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; +import org.apache.lucene.search.Sort; +import org.apache.lucene.search.SortField; +import org.apache.lucene.search.SortField.Type; +import org.apache.lucene.search.SortedNumericSortField; + +public class QueryParser { + public static Query toQuery(it.cavallium.dbengine.client.query.current.data.Query query) { + if (query == null) return null; + throw new NotImplementedException(); + } + + public static boolean isScoringEnabled(QueryParams queryParams) { + return queryParams.getScoreMode().getComputeScores(); + } + + public static Sort toSort(it.cavallium.dbengine.client.query.current.data.Sort sort) { + switch (sort.getBasicType$()) { + case NoSort: + return null; + case ScoreSort: + return new Sort(SortField.FIELD_SCORE); + case DocSort: + return new Sort(SortField.FIELD_DOC); + case NumericSort: + NumericSort numericSort = (NumericSort) sort; + return new Sort(new SortedNumericSortField(numericSort.getField(), Type.LONG, numericSort.getReverse())); + default: + throw new IllegalStateException("Unexpected value: " + sort.getBasicType$()); + } + } + + @SuppressWarnings("ConstantConditions") + public static ScoreMode toScoreMode(it.cavallium.dbengine.client.query.current.data.ScoreMode scoreMode) { + if (scoreMode.getComputeScores() && scoreMode.getOnlyTopScores()) { + return ScoreMode.TOP_SCORES; + } else if (scoreMode.getComputeScores() && !scoreMode.getOnlyTopScores()) { + return ScoreMode.COMPLETE; + } else if (!scoreMode.getComputeScores() && scoreMode.getOnlyTopScores()) { + throw new IllegalStateException("Conflicting score mode options: [computeScores = false, onlyTopScore = true]"); + } else if (!scoreMode.getComputeScores() && !scoreMode.getOnlyTopScores()) { + return ScoreMode.COMPLETE_NO_SCORES; + } else { + throw new IllegalStateException("Unexpected value: " + scoreMode); + } + } + + public static it.cavallium.dbengine.client.query.current.data.Term toQueryTerm(Term term) { + return it.cavallium.dbengine.client.query.current.data.Term.of(term.field(), term.text()); + } +} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/Query.java b/src/main/java/it/cavallium/dbengine/client/query/QueryUtils.java similarity index 52% rename from src/main/java/it/cavallium/dbengine/lucene/serializer/Query.java rename to src/main/java/it/cavallium/dbengine/client/query/QueryUtils.java index 8795832..b138ea1 100644 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/Query.java +++ b/src/main/java/it/cavallium/dbengine/client/query/QueryUtils.java @@ -1,8 +1,18 @@ -package it.cavallium.dbengine.lucene.serializer; - -import static it.cavallium.dbengine.lucene.serializer.QueryParser.USE_PHRASE_QUERY; -import static it.cavallium.dbengine.lucene.serializer.QueryParser.USE_QUERY_BUILDER; +package it.cavallium.dbengine.client.query; +import it.cavallium.dbengine.client.query.current.data.BooleanQuery; +import it.cavallium.dbengine.client.query.current.data.BooleanQueryPart; +import it.cavallium.dbengine.client.query.current.data.Occur; +import it.cavallium.dbengine.client.query.current.data.OccurFilter; +import it.cavallium.dbengine.client.query.current.data.OccurMust; +import it.cavallium.dbengine.client.query.current.data.OccurMustNot; +import it.cavallium.dbengine.client.query.current.data.OccurShould; +import it.cavallium.dbengine.client.query.current.data.PhraseQuery; +import it.cavallium.dbengine.client.query.current.data.Query; +import it.cavallium.dbengine.client.query.current.data.SynonymQuery; +import it.cavallium.dbengine.client.query.current.data.TermAndBoost; +import it.cavallium.dbengine.client.query.current.data.TermPosition; +import it.cavallium.dbengine.client.query.current.data.TermQuery; import it.cavallium.dbengine.lucene.LuceneUtils; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; import java.io.IOException; @@ -19,62 +29,27 @@ import org.apache.lucene.search.BooleanClause; import org.apache.lucene.util.QueryBuilder; import org.jetbrains.annotations.NotNull; -public interface Query extends SerializedQueryObject { +public class QueryUtils { - static Query approximateSearch(TextFieldsAnalyzer preferredAnalyzer, String field, String text) { - if (USE_QUERY_BUILDER) { - var qb = new QueryBuilder(LuceneUtils.getAnalyzer(preferredAnalyzer)); - var luceneQuery = qb.createMinShouldMatchQuery(field, text, 0.75f); - return transformQuery(field, luceneQuery); - } - - try { - var terms = getTerms(preferredAnalyzer, field, text); - - List booleanQueryParts = new LinkedList<>(); - for (TermPosition term : terms) { - booleanQueryParts.add(new BooleanQueryPart(new TermQuery(term.getTerm()), Occur.MUST)); - booleanQueryParts.add(new BooleanQueryPart(new PhraseQuery(terms.toArray(TermPosition[]::new)), Occur.SHOULD)); - } - return new BooleanQuery(booleanQueryParts); - } catch (IOException e) { - e.printStackTrace(); - return exactSearch(preferredAnalyzer, field, text); - } + public static Query approximateSearch(TextFieldsAnalyzer preferredAnalyzer, String field, String text) { + var qb = new QueryBuilder(LuceneUtils.getAnalyzer(preferredAnalyzer)); + var luceneQuery = qb.createMinShouldMatchQuery(field, text, 0.75f); + return transformQuery(field, luceneQuery); } - static Query exactSearch(TextFieldsAnalyzer preferredAnalyzer, String field, String text) { - if (USE_QUERY_BUILDER) { - var qb = new QueryBuilder(LuceneUtils.getAnalyzer(preferredAnalyzer)); - var luceneQuery = qb.createPhraseQuery(field, text); - return transformQuery(field, luceneQuery); - } - - try { - var terms = getTerms(preferredAnalyzer, field, text); - - if (USE_PHRASE_QUERY) { - return new PhraseQuery(terms.toArray(TermPosition[]::new)); - } else { - List booleanQueryParts = new LinkedList<>(); - for (TermPosition term : terms) { - booleanQueryParts.add(new BooleanQueryPart(new TermQuery(term.getTerm()), Occur.MUST)); - } - booleanQueryParts.add(new BooleanQueryPart(new PhraseQuery(terms.toArray(TermPosition[]::new)), Occur.FILTER)); - return new BooleanQuery(booleanQueryParts); - } - } catch (IOException exception) { - throw new RuntimeException(exception); - } + public static Query exactSearch(TextFieldsAnalyzer preferredAnalyzer, String field, String text) { + var qb = new QueryBuilder(LuceneUtils.getAnalyzer(preferredAnalyzer)); + var luceneQuery = qb.createPhraseQuery(field, text); + return transformQuery(field, luceneQuery); } @NotNull private static Query transformQuery(String field, org.apache.lucene.search.Query luceneQuery) { if (luceneQuery == null) { - return new TermQuery(field, ""); + return TermQuery.of(it.cavallium.dbengine.client.query.current.data.Term.of(field, "")); } if (luceneQuery instanceof org.apache.lucene.search.TermQuery) { - return new TermQuery(((org.apache.lucene.search.TermQuery) luceneQuery).getTerm()); + return TermQuery.of(QueryParser.toQueryTerm(((org.apache.lucene.search.TermQuery) luceneQuery).getTerm())); } if (luceneQuery instanceof org.apache.lucene.search.BooleanQuery) { var booleanQuery = (org.apache.lucene.search.BooleanQuery) luceneQuery; @@ -85,23 +60,23 @@ public interface Query extends SerializedQueryObject { Occur occur; switch (booleanClause.getOccur()) { case MUST: - occur = Occur.MUST; + occur = OccurMust.of(); break; case FILTER: - occur = Occur.FILTER; + occur = OccurFilter.of(); break; case SHOULD: - occur = Occur.SHOULD; + occur = OccurShould.of(); break; case MUST_NOT: - occur = Occur.MUST_NOT; + occur = OccurMustNot.of(); break; default: throw new IllegalArgumentException(); } - queryParts.add(new BooleanQueryPart(transformQuery(field, queryPartQuery), occur)); + queryParts.add(BooleanQueryPart.of(transformQuery(field, queryPartQuery), occur)); } - return new BooleanQuery(queryParts).setMinShouldMatch(booleanQuery.getMinimumNumberShouldMatch()); + return BooleanQuery.of(queryParts.toArray(BooleanQueryPart[]::new), booleanQuery.getMinimumNumberShouldMatch()); } if (luceneQuery instanceof org.apache.lucene.search.PhraseQuery) { var phraseQuery = (org.apache.lucene.search.PhraseQuery) luceneQuery; @@ -112,13 +87,17 @@ public interface Query extends SerializedQueryObject { for (int i = 0; i < terms.length; i++) { var term = terms[i]; var position = positions[i]; - termPositions[i] = new TermPosition(term, position); + termPositions[i] = TermPosition.of(QueryParser.toQueryTerm(term), position); } - return new PhraseQuery(termPositions).setSlop(slop); + return PhraseQuery.of(termPositions, 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) + return SynonymQuery.of(field, + synonymQuery + .getTerms() + .stream() + .map(term -> TermAndBoost.of(QueryParser.toQueryTerm(term), 1)) + .toArray(TermAndBoost[]::new) ); } @@ -138,7 +117,7 @@ public interface Query extends SerializedQueryObject { while (ts.incrementToken()) { var tokenPositionIncrement = positionIncrementTermAttr.getPositionIncrement(); termPosition += tokenPositionIncrement; - terms.add(new TermPosition(new Term(field, charTermAttr.getBytesRef()), termPosition)); + terms.add(TermPosition.of(QueryParser.toQueryTerm(new Term(field, charTermAttr.getBytesRef())), termPosition)); } ts.end(); // Perform end-of-stream operations, e.g. set the final offset. } diff --git a/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java index c08f32d..9e6d4b1 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java @@ -1,6 +1,10 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.lucene.serializer.Query; +import it.cavallium.data.generator.nativedata.Nullablefloat; +import it.cavallium.dbengine.client.query.current.data.NoSort; +import it.cavallium.dbengine.client.query.current.data.Query; +import it.cavallium.dbengine.client.query.current.data.QueryParams; +import it.cavallium.dbengine.client.query.current.data.ScoreMode; import java.util.Set; import org.jetbrains.annotations.Nullable; import reactor.core.publisher.Flux; @@ -25,38 +29,27 @@ public interface LLLuceneIndex extends LLSnapshottable { Mono deleteAll(); /** - * @param additionalQuery An additional query that will be used with the moreLikeThis query: "mltQuery AND additionalQuery" - * @param limit the limit is valid for each lucene instance. - * If you have 15 instances, the number of elements returned - * can be at most limit * 15 + * @param queryParams the limit is valid for each lucene instance. If you have 15 instances, the number of elements + * returned can be at most limit * 15. + *

+ * The additional query will be used with the moreLikeThis query: "mltQuery AND additionalQuery" * @return the collection has one or more flux */ Mono moreLikeThis(@Nullable LLSnapshot snapshot, - Flux>> mltDocumentFields, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, - String keyFieldName); + QueryParams queryParams, + String keyFieldName, + Flux>> mltDocumentFields); /** - * - * @param limit the limit is valid for each lucene instance. - * If you have 15 instances, the number of elements returned - * can be at most limit * 15 + * @param queryParams the limit is valid for each lucene instance. If you have 15 instances, the number of elements + * returned can be at most limit * 15 * @return the collection has one or more flux */ - Mono search(@Nullable LLSnapshot snapshot, - Query query, - long limit, - @Nullable LLSort sort, - LLScoreMode scoreMode, - @Nullable Float minCompetitiveScore, - String keyFieldName); + Mono search(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName); default Mono count(@Nullable LLSnapshot snapshot, Query query) { - return this.search(snapshot, query, 0, null, null, null, null) + QueryParams params = QueryParams.of(query, 0, Nullablefloat.empty(), NoSort.of(), ScoreMode.of(false, false)); + return this.search(snapshot, params, null) .flatMap(LLSearchResult::totalHitsCount) .single(); } diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java index 59ee817..fad2e30 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java @@ -1,17 +1,15 @@ package it.cavallium.dbengine.database.disk; -import static it.cavallium.dbengine.lucene.LuceneUtils.checkScoringArgumentsValidity; - import com.google.common.base.Suppliers; +import it.cavallium.dbengine.client.query.QueryParser; +import it.cavallium.dbengine.client.query.current.data.QueryParams; import it.cavallium.dbengine.database.EnglishItalianStopFilter; import it.cavallium.dbengine.database.LLDocument; import it.cavallium.dbengine.database.LLKeyScore; import it.cavallium.dbengine.database.LLLuceneIndex; -import it.cavallium.dbengine.database.LLScoreMode; import it.cavallium.dbengine.database.LLSearchCollectionStatisticsGetter; import it.cavallium.dbengine.database.LLSearchResult; import it.cavallium.dbengine.database.LLSnapshot; -import it.cavallium.dbengine.database.LLSort; import it.cavallium.dbengine.database.LLTerm; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.lucene.LuceneUtils; @@ -21,8 +19,6 @@ import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity; import it.cavallium.dbengine.lucene.searcher.AdaptiveStreamSearcher; import it.cavallium.dbengine.lucene.searcher.AllowOnlyQueryParsingCollectorStreamSearcher; import it.cavallium.dbengine.lucene.searcher.LuceneStreamSearcher; -import it.cavallium.dbengine.lucene.serializer.ParseException; -import it.cavallium.dbengine.lucene.serializer.QueryParser; import java.io.IOException; import java.nio.file.Path; import java.time.Duration; @@ -49,12 +45,10 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SearcherManager; import org.apache.lucene.search.Sort; -import org.apache.lucene.search.SortField; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.search.similarities.TFIDFSimilarity; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.LoggerFactory; @@ -104,7 +98,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { */ private final AtomicLong lastSnapshotSeqNo = new AtomicLong(0); /** - * Snapshot seq no to index commit point + * LLSnapshot seq no to index commit point */ private final ConcurrentHashMap snapshots = new ConcurrentHashMap<>(); private final boolean lowMemory; @@ -229,7 +223,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { return Mono.fromCallable(() -> { var indexSnapshot = this.snapshots.remove(snapshot.getSequenceNumber()); if (indexSnapshot == null) { - throw new IOException("Snapshot " + snapshot.getSequenceNumber() + " not found!"); + throw new IOException("LLSnapshot " + snapshot.getSequenceNumber() + " not found!"); } //noinspection BlockingMethodInNonBlockingContext @@ -358,21 +352,13 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Override public Mono moreLikeThis(@Nullable LLSnapshot snapshot, - Flux>> mltDocumentFieldsFlux, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, - String keyFieldName) { + QueryParams queryParams, + String keyFieldName, + Flux>> mltDocumentFieldsFlux) { return moreLikeThis(snapshot, - mltDocumentFieldsFlux, - additionalQuery, - limit, - minCompetitiveScore, - enableScoring, - sortByScore, + queryParams, keyFieldName, + mltDocumentFieldsFlux, false, 0, 1 @@ -380,23 +366,15 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { } public Mono distributedMoreLikeThis(@Nullable LLSnapshot snapshot, - Flux>> mltDocumentFieldsFlux, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, + QueryParams queryParams, String keyFieldName, + Flux>> mltDocumentFieldsFlux, long actionId, int scoreDivisor) { return moreLikeThis(snapshot, - mltDocumentFieldsFlux, - additionalQuery, - limit, - minCompetitiveScore, - enableScoring, - sortByScore, + queryParams, keyFieldName, + mltDocumentFieldsFlux, false, actionId, scoreDivisor @@ -404,20 +382,14 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { } public Mono distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot, + QueryParams queryParams, + String keyFieldName, Flux>> mltDocumentFieldsFlux, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, - String keyFieldName, long actionId) { + long actionId) { return moreLikeThis(snapshot, - mltDocumentFieldsFlux, - additionalQuery, - -1, - minCompetitiveScore, - enableScoring, - sortByScore, + queryParams, keyFieldName, + mltDocumentFieldsFlux, true, actionId, 1 @@ -427,20 +399,16 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @SuppressWarnings({"unchecked", "rawtypes"}) private Mono moreLikeThis(@Nullable LLSnapshot snapshot, - Flux>> mltDocumentFieldsFlux, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, + QueryParams queryParams, String keyFieldName, + Flux>> mltDocumentFieldsFlux, boolean doDistributedPre, long actionId, int scoreDivisor) { Query luceneAdditionalQuery; try { - luceneAdditionalQuery = additionalQuery != null ? QueryParser.parse(additionalQuery) : null; - } catch (ParseException e) { + luceneAdditionalQuery = QueryParser.toQuery(queryParams.getQuery()); + } catch (Exception e) { return Mono.error(e); } return mltDocumentFieldsFlux @@ -459,7 +427,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { mlt.setMinTermFreq(1); mlt.setMinDocFreq(3); mlt.setMaxDocFreqPct(20); - mlt.setBoost(enableScoring); + mlt.setBoost(QueryParser.isScoringEnabled(queryParams)); mlt.setStopWords(EnglishItalianStopFilter.getStopWordsString()); var similarity = getSimilarity(); if (similarity instanceof TFIDFSimilarity) { @@ -483,15 +451,13 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { return luceneSearch(doDistributedPre, indexSearcher, - limit, - minCompetitiveScore, + queryParams.getLimit(), + queryParams.getMinCompetitiveScore().getNullable(), keyFieldName, scoreDivisor, luceneQuery, - (enableScoring && sortByScore) ? new Sort(SortField.FIELD_SCORE) : null, - (enableScoring && minCompetitiveScore != null) ? - ScoreMode.TOP_SCORES : - (enableScoring ? ScoreMode.COMPLETE : ScoreMode.COMPLETE_NO_SCORES) + QueryParser.toSort(queryParams.getSort()), + QueryParser.toScoreMode(queryParams.getScoreMode()) ); }) .subscribeOn(luceneQueryScheduler) @@ -511,38 +477,30 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { } @Override - public Mono search(@Nullable LLSnapshot snapshot, it.cavallium.dbengine.lucene.serializer.Query query, long limit, - @Nullable LLSort sort, @NotNull LLScoreMode scoreMode, @Nullable Float minCompetitiveScore, String keyFieldName) { - return search(snapshot, query, limit, sort, scoreMode, minCompetitiveScore, - keyFieldName, false, 0, 1); + public Mono search(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName) { + return search(snapshot, queryParams, keyFieldName, false, 0, 1); } - public Mono distributedSearch(@Nullable LLSnapshot snapshot, it.cavallium.dbengine.lucene.serializer.Query query, long limit, - @Nullable LLSort sort, @NotNull LLScoreMode scoreMode, @Nullable Float minCompetitiveScore, String keyFieldName, long actionId, int scoreDivisor) { - return search(snapshot, query, limit, sort, scoreMode, minCompetitiveScore, - keyFieldName, false, actionId, scoreDivisor); + public Mono distributedSearch(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName, long actionId, int scoreDivisor) { + return search(snapshot, queryParams, keyFieldName, false, actionId, scoreDivisor); } - public Mono distributedPreSearch(@Nullable LLSnapshot snapshot, it.cavallium.dbengine.lucene.serializer.Query query, - @Nullable LLSort sort, @NotNull LLScoreMode scoreMode, @Nullable Float minCompetitiveScore, String keyFieldName, long actionId) { + public Mono distributedPreSearch(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName, long actionId) { return this - .search(snapshot, query, -1, sort, scoreMode, - minCompetitiveScore, keyFieldName, true, actionId, 1) + .search(snapshot, queryParams, keyFieldName, true, actionId, 1) .flatMap(LLSearchResult::completion); } private Mono search(@Nullable LLSnapshot snapshot, - it.cavallium.dbengine.lucene.serializer.Query query, long limit, - @Nullable LLSort sort, @NotNull LLScoreMode scoreMode, @Nullable Float minCompetitiveScore, String keyFieldName, + QueryParams queryParams, String keyFieldName, boolean doDistributedPre, long actionId, int scoreDivisor) { return acquireSearcherWrapper(snapshot, doDistributedPre, actionId) .flatMap(indexSearcher -> Mono .fromCallable(() -> { - Objects.requireNonNull(scoreMode, "ScoreMode must not be null"); - checkScoringArgumentsValidity(sort, scoreMode); - Query luceneQuery = QueryParser.parse(query); - Sort luceneSort = LLUtils.toSort(sort); - org.apache.lucene.search.ScoreMode luceneScoreMode = LLUtils.toScoreMode(scoreMode); + Objects.requireNonNull(queryParams.getScoreMode(), "ScoreMode must not be null"); + Query luceneQuery = QueryParser.toQuery(queryParams.getQuery()); + Sort luceneSort = QueryParser.toSort(queryParams.getSort()); + org.apache.lucene.search.ScoreMode luceneScoreMode = QueryParser.toScoreMode(queryParams.getScoreMode()); return Tuples.of(luceneQuery, Optional.ofNullable(luceneSort), luceneScoreMode); }) .subscribeOn(luceneQueryScheduler) @@ -554,8 +512,8 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { return luceneSearch(doDistributedPre, indexSearcher, - limit, - minCompetitiveScore, + queryParams.getLimit(), + queryParams.getMinCompetitiveScore().getNullable(), keyFieldName, scoreDivisor, luceneQuery, diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java index 4aa9da2..ce5f46d 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java @@ -2,16 +2,14 @@ package it.cavallium.dbengine.database.disk; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import it.cavallium.dbengine.client.query.current.data.QueryParams; import it.cavallium.dbengine.database.LLDocument; import it.cavallium.dbengine.database.LLLuceneIndex; -import it.cavallium.dbengine.database.LLScoreMode; import it.cavallium.dbengine.database.LLSearchResult; import it.cavallium.dbengine.database.LLSnapshot; -import it.cavallium.dbengine.database.LLSort; import it.cavallium.dbengine.database.LLTerm; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity; -import it.cavallium.dbengine.lucene.serializer.Query; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import java.io.IOException; @@ -202,13 +200,9 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { @Override public Mono moreLikeThis(@Nullable LLSnapshot snapshot, - Flux>> mltDocumentFields, - @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, - long limit, - @Nullable Float minCompetitiveScore, - boolean enableScoring, - boolean sortByScore, - String keyFieldName) { + QueryParams queryParams, + String keyFieldName, + Flux>> mltDocumentFields) { long actionId; int scoreDivisor; Flux>> mltDocumentFieldsShared; @@ -227,12 +221,9 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { .flatMap(tuple -> tuple .getT1() .distributedPreMoreLikeThis(tuple.getT2().orElse(null), - mltDocumentFieldsShared, - additionalQuery, - minCompetitiveScore, - enableScoring, - sortByScore, + queryParams, keyFieldName, + mltDocumentFieldsShared, actionId ) ) @@ -253,13 +244,9 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { .flatMap(tuple -> tuple .getT1() .distributedMoreLikeThis(tuple.getT2().orElse(null), - mltDocumentFieldsShared, - additionalQuery, - limit, - minCompetitiveScore, - enableScoring, - sortByScore, + queryParams, keyFieldName, + mltDocumentFieldsShared, actionId, scoreDivisor ) @@ -280,16 +267,12 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { @Override public Mono search(@Nullable LLSnapshot snapshot, - Query query, - long limit, - @Nullable LLSort sort, - LLScoreMode scoreMode, - @Nullable Float minCompetitiveScore, + QueryParams queryParams, String keyFieldName) { long actionId; int scoreDivisor; Mono distributedPre; - if (luceneIndices.length <= 1 || scoreMode == LLScoreMode.COMPLETE_NO_SCORES) { + if (luceneIndices.length <= 1 || !queryParams.getScoreMode().getComputeScores()) { actionId = -1; scoreDivisor = 1; distributedPre = Mono.empty(); @@ -306,10 +289,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { .flatMap(tuple -> tuple .getT1() .distributedPreSearch(tuple.getT2().orElse(null), - query, - sort, - scoreMode, - minCompetitiveScore, + queryParams, keyFieldName, actionId ) @@ -327,11 +307,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { .flatMap(tuple -> tuple .getT1() .distributedSearch(tuple.getT2().orElse(null), - query, - limit, - sort, - scoreMode, - minCompetitiveScore, + queryParams, keyFieldName, actionId, scoreDivisor diff --git a/src/main/java/it/cavallium/dbengine/lucene/LuceneUtils.java b/src/main/java/it/cavallium/dbengine/lucene/LuceneUtils.java index 5c475e5..ed2209e 100644 --- a/src/main/java/it/cavallium/dbengine/lucene/LuceneUtils.java +++ b/src/main/java/it/cavallium/dbengine/lucene/LuceneUtils.java @@ -2,9 +2,6 @@ package it.cavallium.dbengine.lucene; import it.cavallium.dbengine.client.MultiSort; import it.cavallium.dbengine.database.LLKeyScore; -import it.cavallium.dbengine.database.LLScoreMode; -import it.cavallium.dbengine.database.LLSort; -import it.cavallium.dbengine.database.LLSortType; import it.cavallium.dbengine.lucene.analyzer.NCharGramAnalyzer; import it.cavallium.dbengine.lucene.analyzer.NCharGramEdgeAnalyzer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; @@ -191,12 +188,6 @@ public class LuceneUtils { }); } - public static void checkScoringArgumentsValidity(LLSort sort, LLScoreMode scoreMode) { - if ((sort == null || sort.getType() != LLSortType.SCORE) && scoreMode != LLScoreMode.COMPLETE_NO_SCORES) { - throw new IllegalArgumentException("You must sort by score if the scores are enabled"); - } - } - public static void collectTopDoc(Logger logger, int docId, float score, diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQuery.java deleted file mode 100644 index e5190f2..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQuery.java +++ /dev/null @@ -1,43 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import java.util.Arrays; -import java.util.Collection; -import java.util.stream.Collectors; - -@SuppressWarnings("unused") -public class BooleanQuery implements Query { - - private final BooleanQueryPart[] parts; - private int minShouldMatch; - - public BooleanQuery(BooleanQueryPart... parts) { - this.parts = parts; - } - - public BooleanQuery(Collection parts) { - this.parts = parts.toArray(BooleanQueryPart[]::new); - } - - public BooleanQuery setMinShouldMatch(int minShouldMatch) { - this.minShouldMatch = minShouldMatch; - return this; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyInt(data, minShouldMatch); - StringBuilder listData = new StringBuilder(); - listData.append(parts.length).append('|'); - for (BooleanQueryPart part : parts) { - part.stringify(listData); - } - StringifyUtils.writeHeader(data, QueryConstructorType.BOOLEAN_QUERY_INFO_LIST, listData); - StringifyUtils.writeHeader(output, QueryConstructorType.BOOLEAN_QUERY, data); - } - - @Override - public String toString() { - return Arrays.stream(parts).map(Object::toString).collect(Collectors.joining(" || ", "((", ") Minimum should matches:" + minShouldMatch + ")")); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryInfo.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryInfo.java deleted file mode 100644 index 61aa517..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryInfo.java +++ /dev/null @@ -1,42 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import java.util.Objects; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.Query; - -public class BooleanQueryInfo { - - public final Query query; - public final BooleanClause.Occur occur; - - public BooleanQueryInfo(Query query, BooleanClause.Occur occur) { - this.query = query; - this.occur = occur; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - BooleanQueryInfo that = (BooleanQueryInfo) o; - return Objects.equals(query, that.query) && - occur == that.occur; - } - - @Override - public int hashCode() { - return Objects.hash(query, occur); - } - - @Override - public String toString() { - return "BooleanQueryInfo{" + - "query=" + query + - ", occur=" + occur + - '}'; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryPart.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryPart.java deleted file mode 100644 index d34f273..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/BooleanQueryPart.java +++ /dev/null @@ -1,25 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class BooleanQueryPart implements SerializedQueryObject { - - private final Query query; - private final Occur occur; - - public BooleanQueryPart(Query query, Occur occur) { - this.query = query; - this.occur = occur; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - query.stringify(data); - occur.stringify(data); - StringifyUtils.writeHeader(output, QueryConstructorType.BOOLEAN_QUERY_INFO, data); - } - - @Override - public String toString() { - return occur + ":" + query; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/BoostQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/BoostQuery.java deleted file mode 100644 index 20dbd8e..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/BoostQuery.java +++ /dev/null @@ -1,25 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class BoostQuery implements Query { - - private final Query query; - private final float boostValue; - - public BoostQuery(Query query, float boostValue) { - this.query = query; - this.boostValue = boostValue; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - query.stringify(data); - StringifyUtils.stringifyFloat(data, boostValue); - StringifyUtils.writeHeader(output, QueryConstructorType.BOOST_QUERY, data); - } - - @Override - public String toString() { - return "(" + query + " *" + boostValue + ")"; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/ConstantScoreQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/ConstantScoreQuery.java deleted file mode 100644 index c1f07ac..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/ConstantScoreQuery.java +++ /dev/null @@ -1,22 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class ConstantScoreQuery implements Query { - - private final Query query; - - public ConstantScoreQuery(Query query) { - this.query = query; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - query.stringify(data); - StringifyUtils.writeHeader(output, QueryConstructorType.CONSTANT_SCORE_QUERY, data); - } - - @Override - public String toString() { - return "(" + query + " *1)"; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/DocValuesFieldExistsQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/DocValuesFieldExistsQuery.java deleted file mode 100644 index 4195152..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/DocValuesFieldExistsQuery.java +++ /dev/null @@ -1,26 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class DocValuesFieldExistsQuery implements Query { - - private final String field; - - public DocValuesFieldExistsQuery(String field) { - this.field = field; - } - - public String getField() { - return field; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, field); - StringifyUtils.writeHeader(output, QueryConstructorType.DOC_VALUES_FIELD_EXISTS_QUERY, data); - } - - @Override - public String toString() { - return "(existence of field " + field + ")"; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/FuzzyQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/FuzzyQuery.java deleted file mode 100644 index 77c33fc..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/FuzzyQuery.java +++ /dev/null @@ -1,50 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.util.automaton.LevenshteinAutomata; - -@SuppressWarnings("unused") -public class FuzzyQuery implements Query { - - private final Term term; - private final int val1; - private final int val2; - private final int val3; - private final boolean bool; - - /** - * Create a new FuzzyQuery that will match terms with an edit distance of at most - * maxEdits to term. If a prefixLength > 0 is - * specified, a common prefix of that length is also required. - * - * @param term the term to search for - * @param maxEdits must be {@code >= 0} and {@code <=} {@link LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE}. - * @param prefixLength length of common (non-fuzzy) prefix - * @param maxExpansions the maximum number of terms to match. If this number is greater than - * {@link BooleanQuery#getMaxClauseCount} when the query is rewritten, then - * the maxClauseCount will be used instead. - * @param transpositions true if transpositions should be treated as a primitive edit operation. - * If this is false, comparisons will implement the classic Levenshtein - * algorithm. - */ - public FuzzyQuery(Term term, int maxEdits, int prefixLength, int maxExpansions, - boolean transpositions) { - this.term = term; - this.val1 = maxEdits; - this.val2 = prefixLength; - this.val3 = maxExpansions; - this.bool = transpositions; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyTerm(data, term); - StringifyUtils.stringifyInt(data, val1); - StringifyUtils.stringifyInt(data, val2); - StringifyUtils.stringifyInt(data, val3); - StringifyUtils.stringifyBool(data, bool); - StringifyUtils.writeHeader(output, QueryConstructorType.FUZZY_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointExactQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointExactQuery.java deleted file mode 100644 index bb18eee..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointExactQuery.java +++ /dev/null @@ -1,20 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class IntPointExactQuery implements Query { - - private final String name; - private final int value; - - public IntPointExactQuery(String name, int value) { - this.name = name; - this.value = value; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, name); - StringifyUtils.stringifyInt(data, value); - StringifyUtils.writeHeader(output, QueryConstructorType.INT_POINT_EXACT_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointRangeQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointRangeQuery.java deleted file mode 100644 index aea6c53..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/IntPointRangeQuery.java +++ /dev/null @@ -1,23 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class IntPointRangeQuery implements Query { - - private final String name; - private final int min; - private final int max; - - public IntPointRangeQuery(String name, int min, int max) { - this.name = name; - this.min = min; - this.max = max; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, name); - StringifyUtils.stringifyInt(data, min); - StringifyUtils.stringifyInt(data, max); - StringifyUtils.writeHeader(output, QueryConstructorType.INT_POINT_RANGE_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointExactQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointExactQuery.java deleted file mode 100644 index f92b869..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointExactQuery.java +++ /dev/null @@ -1,20 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class LongPointExactQuery implements Query { - - private final String name; - private final long value; - - public LongPointExactQuery(String name, long value) { - this.name = name; - this.value = value; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, name); - StringifyUtils.stringifyLong(data, value); - StringifyUtils.writeHeader(output, QueryConstructorType.LONG_POINT_EXACT_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointRangeQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointRangeQuery.java deleted file mode 100644 index 2cb3063..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/LongPointRangeQuery.java +++ /dev/null @@ -1,23 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class LongPointRangeQuery implements Query { - - private final String name; - private final long min; - private final long max; - - public LongPointRangeQuery(String name, long min, long max) { - this.name = name; - this.min = min; - this.max = max; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, name); - StringifyUtils.stringifyLong(data, min); - StringifyUtils.stringifyLong(data, max); - StringifyUtils.writeHeader(output, QueryConstructorType.LONG_POINT_RANGE_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/MatchAllDocsQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/MatchAllDocsQuery.java deleted file mode 100644 index 6763c9b..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/MatchAllDocsQuery.java +++ /dev/null @@ -1,13 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class MatchAllDocsQuery implements Query { - - public MatchAllDocsQuery() { - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.writeHeader(output, QueryConstructorType.MATCH_ALL_DOCS_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/Occur.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/Occur.java deleted file mode 100644 index 398d161..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/Occur.java +++ /dev/null @@ -1,41 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import org.apache.lucene.search.BooleanClause; - -@SuppressWarnings("unused") -public class Occur implements SerializedQueryObject { - - private final BooleanClause.Occur occur; - - public Occur(BooleanClause.Occur occur) { - this.occur = occur; - } - - public static Occur MUST = new Occur(BooleanClause.Occur.MUST); - public static Occur FILTER = new Occur(BooleanClause.Occur.FILTER); - public static Occur SHOULD = new Occur(BooleanClause.Occur.SHOULD); - public static Occur MUST_NOT = new Occur(BooleanClause.Occur.MUST_NOT); - - @Override - public void stringify(StringBuilder output) { - switch (occur) { - case MUST: - StringifyUtils.writeHeader(output, QueryConstructorType.OCCUR_MUST, new StringBuilder()); - break; - case FILTER: - StringifyUtils.writeHeader(output, QueryConstructorType.OCCUR_FILTER, new StringBuilder()); - break; - case SHOULD: - StringifyUtils.writeHeader(output, QueryConstructorType.OCCUR_SHOULD, new StringBuilder()); - break; - case MUST_NOT: - StringifyUtils.writeHeader(output, QueryConstructorType.OCCUR_MUST_NOT, new StringBuilder()); - break; - } - } - - @Override - public String toString() { - return occur.name(); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/ParseException.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/ParseException.java deleted file mode 100644 index 5925492..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/ParseException.java +++ /dev/null @@ -1,8 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public class ParseException extends Exception { - - public ParseException(Exception e) { - super(e); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/PhraseQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/PhraseQuery.java deleted file mode 100644 index 0ddf8da..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/PhraseQuery.java +++ /dev/null @@ -1,39 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import java.util.Arrays; -import java.util.stream.Collectors; - -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 - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringBuilder listData = new StringBuilder(); - listData.append(parts.length).append('|'); - for (TermPosition part : parts) { - StringifyUtils.stringifyTermPosition(listData, part); - } - StringifyUtils.writeHeader(data, QueryConstructorType.TERM_POSITION_LIST, listData); - StringifyUtils.stringifyInt(data, slop); - StringifyUtils.writeHeader(output, QueryConstructorType.PHRASE_QUERY, data); - } - - @Override - public String toString() { - return Arrays.stream(parts).map(Object::toString).collect(Collectors.joining(", ", "(", ")")); - } - - public PhraseQuery setSlop(int slop) { - this.slop = slop; - return this; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryConstructorType.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryConstructorType.java deleted file mode 100644 index 325ed51..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryConstructorType.java +++ /dev/null @@ -1,35 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public enum QueryConstructorType { - BOOLEAN_QUERY, - BOOLEAN_QUERY_INFO, - BOOST_QUERY, - CONSTANT_SCORE_QUERY, - SORTED_SLOW_RANGE_QUERY, - INT_POINT_EXACT_QUERY, - LONG_POINT_EXACT_QUERY, - TERM_QUERY, - WILDCARD_QUERY, - DOC_VALUES_FIELD_EXISTS_QUERY, - FUZZY_QUERY, - PHRASE_QUERY, - SYNONYM_QUERY, - STRING, - OCCUR_MUST, - OCCUR_SHOULD, - OCCUR_FILTER, - OCCUR_MUST_NOT, - FLOAT, - LONG, - INT, - TERM, - NULL, - BOOLEAN, - TERM_POSITION_LIST, - TERM_QUERY_LIST, - TERM_POSITION, - BOOLEAN_QUERY_INFO_LIST, - LONG_POINT_RANGE_QUERY, - INT_POINT_RANGE_QUERY, - MATCH_ALL_DOCS_QUERY -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryParser.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryParser.java deleted file mode 100644 index c934bdf..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/QueryParser.java +++ /dev/null @@ -1,295 +0,0 @@ -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; -import org.apache.lucene.document.LongPoint; -import org.apache.lucene.document.SortedNumericDocValuesField; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.BoostQuery; -import org.apache.lucene.search.ConstantScoreQuery; -import org.apache.lucene.search.DocValuesFieldExistsQuery; -import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.PhraseQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.SynonymQuery; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.WildcardQuery; - -public class QueryParser { - - static final boolean USE_PHRASE_QUERY = true; - static final boolean USE_QUERY_BUILDER = true; - - public static Query parse(String text) throws ParseException { - try { - return (Query) parse(text, new AtomicInteger(0)); - } catch (Exception e) { - throw new ParseException(e); - } - } - - public static Query parse(it.cavallium.dbengine.lucene.serializer.Query query) throws ParseException { - StringBuilder sb = new StringBuilder(); - query.stringify(sb); - return parse(sb.toString()); - } - - private static Object parse(String completeText, AtomicInteger position) { - String text = completeText.substring(position.get()); - if (text.length() <= 2) { - return null; - } - PrimitiveIterator.OfInt iterator = text.chars().iterator(); - StringBuilder numberBuilder = new StringBuilder(); - int index = 0; - while (iterator.hasNext()) { - char character = (char) iterator.nextInt(); - index++; - if (character == '|') { - break; - } else { - numberBuilder.append(character); - } - } - int len = Integer.parseInt(numberBuilder.toString(), 16); - StringBuilder typeBuilder = new StringBuilder(); - while (iterator.hasNext()) { - char character = (char) iterator.nextInt(); - index++; - if (character == '|') { - break; - } else { - typeBuilder.append(character); - } - } - QueryConstructorType type = QueryConstructorType.values()[Integer.parseInt(typeBuilder.toString())]; - - position.addAndGet(index); - - String toParse = text.substring(index, index + len); - switch (type) { - case BOOST_QUERY: - Query query = (Query) parse(completeText, position); - Float numb = (Float) parse(completeText, position); - assert query != null; - assert numb != null; - return new BoostQuery(query, numb); - case CONSTANT_SCORE_QUERY: - Query queryC = (Query) parse(completeText, position); - assert queryC != null; - return new ConstantScoreQuery(queryC); - case FUZZY_QUERY: - Term fqTerm = (Term) parse(completeText, position); - Integer numb1 = (Integer) parse(completeText, position); - Integer numb2 = (Integer) parse(completeText, position); - Integer numb3 = (Integer) parse(completeText, position); - Boolean bool1 = (Boolean) parse(completeText, position); - assert fqTerm != null; - assert numb1 != null; - assert numb2 != null; - assert numb3 != null; - assert bool1 != null; - return new FuzzyQuery(fqTerm, numb1, numb2, numb3, bool1); - case PHRASE_QUERY: - TermPosition[] pqTerms = (TermPosition[]) parse(completeText, position); - var pqB = new PhraseQuery.Builder(); - assert pqTerms != null; - for (TermPosition pqTerm : pqTerms) { - if (pqTerm != null) { - 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); - var pqB2 = new SynonymQuery.Builder(fieldName); - TermQuery[] pqTerms2 - = (TermQuery[]) parse(completeText, position); - assert pqTerms2 != null; - for (TermQuery pqTerm : pqTerms2) { - if (pqTerm != null) { - pqB2.addTerm(pqTerm.getTerm()); - } - } - return pqB2.build(); - case BOOLEAN_QUERY: - var bqB = new BooleanQuery.Builder(); - //noinspection ConstantConditions - int minShouldMatch = (Integer) parse(completeText, position); - bqB.setMinimumNumberShouldMatch(minShouldMatch); - BooleanQueryInfo[] bqTerms = (BooleanQueryInfo[]) parse(completeText, position); - assert bqTerms != null; - for (BooleanQueryInfo bqTerm : bqTerms) { - bqB.add(bqTerm.query, bqTerm.occur); - } - return bqB.build(); - case BOOLEAN_QUERY_INFO: - Query query1 = (Query) parse(completeText, position); - BooleanClause.Occur occur = (BooleanClause.Occur) parse(completeText, position); - return new BooleanQueryInfo(query1, occur); - case INT_POINT_EXACT_QUERY: - String string1 = (String) parse(completeText, position); - Integer int1 = (Integer) parse(completeText, position); - assert string1 != null; - assert int1 != null; - return IntPoint.newExactQuery(string1, int1); - case LONG_POINT_EXACT_QUERY: - String string5 = (String) parse(completeText, position); - Long long3 = (Long) parse(completeText, position); - assert string5 != null; - assert long3 != null; - return LongPoint.newExactQuery(string5, long3); - case SORTED_SLOW_RANGE_QUERY: - String string2 = (String) parse(completeText, position); - Long long1 = (Long) parse(completeText, position); - Long long2 = (Long) parse(completeText, position); - assert string2 != null; - assert long1 != null; - assert long2 != null; - return SortedNumericDocValuesField.newSlowRangeQuery(string2, long1, long2); - case LONG_POINT_RANGE_QUERY: - String stringX2 = (String) parse(completeText, position); - Long longX1 = (Long) parse(completeText, position); - Long longX2 = (Long) parse(completeText, position); - assert stringX2 != null; - assert longX1 != null; - assert longX2 != null; - return LongPoint.newRangeQuery(stringX2, longX1, longX2); - case INT_POINT_RANGE_QUERY: - String stringX3 = (String) parse(completeText, position); - Integer intX1 = (Integer) parse(completeText, position); - Integer intX2 = (Integer) parse(completeText, position); - assert stringX3 != null; - assert intX1 != null; - assert intX2 != null; - return IntPoint.newRangeQuery(stringX3, intX1, intX2); - case INT: - position.addAndGet(toParse.length()); - return Integer.parseInt(toParse); - case LONG: - position.addAndGet(toParse.length()); - return Long.parseLong(toParse); - case TERM: - String string3 = (String) parse(completeText, position); - String string4 = (String) parse(completeText, position); - assert string4 != null; - return new Term(string3, string4); - case TERM_POSITION: - Term term1 = (Term) parse(completeText, position); - Integer intX3 = (Integer) parse(completeText, position); - assert intX3 != null; - return new TermPosition(term1, intX3); - case TERM_QUERY: - Term term2 = (Term) parse(completeText, position); - assert term2 != null; - return new TermQuery(term2); - case WILDCARD_QUERY: - Term term3 = (Term) parse(completeText, position); - assert term3 != null; - return new WildcardQuery(term3); - case DOC_VALUES_FIELD_EXISTS_QUERY: - String fieldKey = (String) parse(completeText, position); - assert fieldKey != null; - return new DocValuesFieldExistsQuery(fieldKey); - case FLOAT: - position.addAndGet(toParse.length()); - return Float.parseFloat(toParse); - case STRING: - position.addAndGet(toParse.length()); - return new String(Base64.getDecoder().decode(toParse), StandardCharsets.UTF_8); - case BOOLEAN: - position.addAndGet(toParse.length()); - return Boolean.parseBoolean(toParse); - case NULL: - position.addAndGet(toParse.length()); - return null; - case TERM_POSITION_LIST: - int termsCount; - StringBuilder termsCountBuilder = new StringBuilder(); - var it = toParse.chars().iterator(); - while (it.hasNext()) { - char character = (char) it.nextInt(); - position.incrementAndGet(); - if (character == '|') { - break; - } else { - termsCountBuilder.append(character); - } - } - termsCount = Integer.parseInt(termsCountBuilder.toString()); - - var result1 = new TermPosition[termsCount]; - for (int i = 0; i < termsCount; i++) { - result1[i] = (TermPosition) parse(completeText, position); - } - return result1; - case TERM_QUERY_LIST: - int termsCount2; - StringBuilder termsCountBuilder2 = new StringBuilder(); - var it2 = toParse.chars().iterator(); - while (it2.hasNext()) { - char character = (char) it2.nextInt(); - position.incrementAndGet(); - if (character == '|') { - break; - } else { - termsCountBuilder2.append(character); - } - } - termsCount2 = Integer.parseInt(termsCountBuilder2.toString()); - - var result2 = new TermQuery[termsCount2]; - for (int i = 0; i < termsCount2; i++) { - result2[i] = (TermQuery) parse(completeText, position); - } - return result2; - case BOOLEAN_QUERY_INFO_LIST: - int termsCount3; - StringBuilder termsCountBuilder3 = new StringBuilder(); - var it3 = toParse.chars().iterator(); - while (it3.hasNext()) { - char character = (char) it3.nextInt(); - position.incrementAndGet(); - if (character == '|') { - break; - } else { - termsCountBuilder3.append(character); - } - } - termsCount3 = Integer.parseInt(termsCountBuilder3.toString()); - - var result3 = new BooleanQueryInfo[termsCount3]; - for (int i = 0; i < termsCount3; i++) { - result3[i] = (BooleanQueryInfo) parse(completeText, position); - } - return result3; - case OCCUR_MUST: - return BooleanClause.Occur.MUST; - case OCCUR_FILTER: - return BooleanClause.Occur.FILTER; - case OCCUR_SHOULD: - return BooleanClause.Occur.SHOULD; - case OCCUR_MUST_NOT: - return BooleanClause.Occur.MUST_NOT; - case MATCH_ALL_DOCS_QUERY: - return new MatchAllDocsQuery(); - default: - throw new UnsupportedOperationException("Unknown query constructor type: " + type); - } - } - - public static String stringify(SerializedQueryObject query) { - StringBuilder sb = new StringBuilder(); - query.stringify(sb); - return sb.toString(); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/SerializedQueryObject.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/SerializedQueryObject.java deleted file mode 100644 index 38919da..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/SerializedQueryObject.java +++ /dev/null @@ -1,9 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -public interface SerializedQueryObject { - - /** - * returns length|type|---data--- - */ - void stringify(StringBuilder output); -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/SortedNumericDocValuesFieldSlowRangeQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/SortedNumericDocValuesFieldSlowRangeQuery.java deleted file mode 100644 index b450929..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/SortedNumericDocValuesFieldSlowRangeQuery.java +++ /dev/null @@ -1,24 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -@SuppressWarnings("unused") -public class SortedNumericDocValuesFieldSlowRangeQuery implements Query { - - private final String name; - private final long min; - private final long max; - - public SortedNumericDocValuesFieldSlowRangeQuery(String name, long min, long max) { - this.name = name; - this.min = min; - this.max = max; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, name); - StringifyUtils.stringifyLong(data, min); - StringifyUtils.stringifyLong(data, max); - StringifyUtils.writeHeader(output, QueryConstructorType.SORTED_SLOW_RANGE_QUERY, data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/StringifyUtils.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/StringifyUtils.java deleted file mode 100644 index 3fa4f9c..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/StringifyUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import org.apache.lucene.index.Term; - -@SuppressWarnings("unused") -public class StringifyUtils { - - public static void stringifyFloat(StringBuilder output, float value) { - writeHeader(output, QueryConstructorType.FLOAT, new StringBuilder().append(value)); - } - - public static void stringifyInt(StringBuilder output, int value) { - writeHeader(output, QueryConstructorType.INT, new StringBuilder().append(value)); - } - - public static void stringifyLong(StringBuilder output, long value) { - writeHeader(output, QueryConstructorType.LONG, new StringBuilder().append(value)); - } - - public static void stringifyBool(StringBuilder output, boolean value) { - writeHeader(output, QueryConstructorType.BOOLEAN, new StringBuilder().append(value)); - } - - public static void stringifyString(StringBuilder output, String value) { - writeHeader(output, QueryConstructorType.STRING, new StringBuilder() - .append(Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8)))); - } - - public static void stringifyTerm(StringBuilder output, Term value) { - var data = new StringBuilder(); - stringifyString(data, value.field()); - stringifyString(data, value.text()); - writeHeader(output, QueryConstructorType.TERM, data); - } - - public static void stringifyTermQuery(StringBuilder output, TermQuery value) { - var data = new StringBuilder(); - stringifyTerm(data, value.getTerm()); - writeHeader(output, QueryConstructorType.TERM_QUERY, data); - } - - public static void stringifyTermPosition(StringBuilder output, TermPosition value) { - var data = new StringBuilder(); - stringifyTerm(data, value.getTerm()); - stringifyInt(data, value.getPosition()); - writeHeader(output, QueryConstructorType.TERM_POSITION, data); - } - - public static void stringifyNullTerm(StringBuilder output) { - writeHeader(output, QueryConstructorType.NULL, new StringBuilder()); - } - - public static void writeHeader(StringBuilder output, QueryConstructorType type, - StringBuilder data) { - output.append(Integer.toHexString(data.length())).append('|'); - output.append(type.ordinal()).append('|'); - output.append(data); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/SynonymQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/SynonymQuery.java deleted file mode 100644 index d8be361..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/SynonymQuery.java +++ /dev/null @@ -1,34 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import java.util.Arrays; -import java.util.stream.Collectors; - -public class SynonymQuery implements Query { - - private final String field; - // some terms can be null - private final TermQuery[] parts; - - public SynonymQuery(String field, TermQuery... parts) { - this.field = field; - this.parts = parts; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyString(data, field); - StringBuilder listData = new StringBuilder(); - listData.append(parts.length).append('|'); - for (TermQuery part : parts) { - StringifyUtils.stringifyTermQuery(listData, part); - } - StringifyUtils.writeHeader(data, QueryConstructorType.TERM_QUERY_LIST, listData); - StringifyUtils.writeHeader(output, QueryConstructorType.SYNONYM_QUERY, data); - } - - @Override - public String toString() { - return Arrays.stream(parts).map(Object::toString).collect(Collectors.joining(", ", "(", ")")); - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/TermPosition.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/TermPosition.java deleted file mode 100644 index cb13eaf..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/TermPosition.java +++ /dev/null @@ -1,32 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import org.apache.lucene.index.Term; - -public class TermPosition implements Query { - - private final Term term; - private final int position; - - public TermPosition(Term term, int position) { - this.term = term; - this.position = position; - } - - public Term getTerm() { - return term; - } - - public int getPosition() { - return position; - } - - @Override - public void stringify(StringBuilder output) { - - } - - @Override - public String toString() { - return "(" + term.field() + ":" + term.text() + " at " + position + ")"; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/TermQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/TermQuery.java deleted file mode 100644 index 0be09f9..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/TermQuery.java +++ /dev/null @@ -1,37 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import it.cavallium.dbengine.database.LLTerm; -import org.apache.lucene.index.Term; - -public class TermQuery implements Query { - - private final Term term; - - public TermQuery(Term term) { - this.term = term; - } - - public TermQuery(LLTerm term) { - this.term = new Term(term.getKey(), term.getValue()); - } - - public TermQuery(String name, String val) { - this.term = new Term(name, val); - } - - public Term getTerm() { - return term; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyTerm(data, term); - StringifyUtils.writeHeader(output, QueryConstructorType.TERM_QUERY, data); - } - - @Override - public String toString() { - return "(" + term.field() + ":" + term.text() + ")"; - } -} diff --git a/src/main/java/it/cavallium/dbengine/lucene/serializer/WildcardQuery.java b/src/main/java/it/cavallium/dbengine/lucene/serializer/WildcardQuery.java deleted file mode 100644 index 1e0c773..0000000 --- a/src/main/java/it/cavallium/dbengine/lucene/serializer/WildcardQuery.java +++ /dev/null @@ -1,37 +0,0 @@ -package it.cavallium.dbengine.lucene.serializer; - -import it.cavallium.dbengine.database.LLTerm; -import org.apache.lucene.index.Term; - -public class WildcardQuery implements Query { - - private final Term term; - - public WildcardQuery(Term term) { - this.term = term; - } - - public WildcardQuery(LLTerm term) { - this.term = new Term(term.getKey(), term.getValue()); - } - - public WildcardQuery(String name, String val) { - this.term = new Term(name, val); - } - - public Term getTerm() { - return term; - } - - @Override - public void stringify(StringBuilder output) { - StringBuilder data = new StringBuilder(); - StringifyUtils.stringifyTerm(data, term); - StringifyUtils.writeHeader(output, QueryConstructorType.WILDCARD_QUERY, data); - } - - @Override - public String toString() { - return "(" + term.field() + ":" + term.text() + ")"; - } -}