forked from opensearch-project/index-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for QueryStringQuery in rollups (opensearch-project#616) (
opensearch-project#654) * added support for QueryStringQuery in rollups Signed-off-by: Petar Dzepina <[email protected]> * detekt fix Signed-off-by: Petar Dzepina <[email protected]> * compile fix Signed-off-by: Petar Dzepina <[email protected]> * IT fix Signed-off-by: Petar Dzepina <[email protected]> Signed-off-by: Petar Dzepina <[email protected]> (cherry picked from commit 3de566e) Co-authored-by: Petar Dzepina <[email protected]>
- Loading branch information
1 parent
1e6fef8
commit c9a988d
Showing
10 changed files
with
1,334 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/org/opensearch/indexmanagement/rollup/query/QueryStringQueryParserExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.rollup.query | ||
|
||
import org.apache.lucene.search.Query | ||
import org.opensearch.common.regex.Regex | ||
import org.opensearch.index.query.QueryShardContext | ||
import org.opensearch.index.search.QueryStringQueryParser | ||
|
||
const val EXISTS = "_exists_" | ||
|
||
class QueryStringQueryParserExt : QueryStringQueryParser { | ||
|
||
val discoveredFields = mutableListOf<String>() | ||
var hasLonelyTerms = false | ||
|
||
constructor(context: QueryShardContext?, lenient: Boolean) : super(context, lenient) | ||
constructor(context: QueryShardContext?, defaultField: String, lenient: Boolean) : super(context, defaultField, lenient) | ||
constructor(context: QueryShardContext, resolvedFields: Map<String, Float>, lenient: Boolean) : super(context, resolvedFields, lenient) | ||
|
||
override fun getFuzzyQuery(field: String?, termStr: String?, minSimilarity: Float): Query? { | ||
handleFieldQueryDiscovered(field) | ||
return super.getFuzzyQuery(field, termStr, minSimilarity) | ||
} | ||
override fun getPrefixQuery(field: String?, termStr: String?): Query { | ||
handleFieldQueryDiscovered(field) | ||
return super.getPrefixQuery(field, termStr) | ||
} | ||
override fun getFieldQuery(field: String?, queryText: String?, quoted: Boolean): Query { | ||
handleFieldQueryDiscovered(field, queryText) | ||
return super.getFieldQuery(field, queryText, quoted) | ||
} | ||
override fun getWildcardQuery(field: String?, termStr: String?): Query { | ||
handleFieldQueryDiscovered(field) | ||
return super.getWildcardQuery(field, termStr) | ||
} | ||
override fun getFieldQuery(field: String?, queryText: String?, slop: Int): Query { | ||
handleFieldQueryDiscovered(field, queryText) | ||
return super.getFieldQuery(field, queryText, slop) | ||
} | ||
override fun getRangeQuery(field: String?, part1: String?, part2: String?, startInclusive: Boolean, endInclusive: Boolean): Query { | ||
handleFieldQueryDiscovered(field) | ||
return super.getRangeQuery(field, part1, part2, startInclusive, endInclusive) | ||
} | ||
override fun getRegexpQuery(field: String?, termStr: String?): Query { | ||
handleFieldQueryDiscovered(field) | ||
return super.getRegexpQuery(field, termStr) | ||
} | ||
|
||
private fun handleFieldQueryDiscovered(field: String?, queryText: String? = null) { | ||
if (field == null || Regex.isSimpleMatchPattern(field)) { | ||
hasLonelyTerms = true | ||
} else { | ||
if (field == EXISTS && queryText?.isNotEmpty() == true) discoveredFields.add(queryText) | ||
else discoveredFields.add(field) | ||
} | ||
} | ||
} |
Oops, something went wrong.