forked from opensearch-project/OpenSearch
-
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.
Search Query Categorizor initial skeleton using QueryBuilderVisitor
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
server/src/main/java/org/opensearch/action/search/SearchQueryCategorizor.java
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,49 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.apache.lucene.search.BooleanClause; | ||
import org.opensearch.index.query.BoolQueryBuilder; | ||
import org.opensearch.index.query.MatchQueryBuilder; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.index.query.QueryBuilderVisitor; | ||
import org.opensearch.index.query.QueryStringQueryBuilder; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
|
||
public class SearchQueryCategorizor { | ||
|
||
public static void categorize(SearchSourceBuilder source) { | ||
QueryBuilder topLevelQueryBuilder = source.query(); | ||
QueryBuilderVisitor queryBuilderVisitor = new QueryBuilderVisitor() { | ||
@Override | ||
public void accept(QueryBuilder qb) { | ||
// This method will be called for every QueryBuilder node in the tree. | ||
// The tree referred to here is the tree of querybuilders for the incoming search | ||
// query with the topLevelQueryBuilder as the root. | ||
|
||
// Increment counter for current QueryBuilder using Metric Framework. | ||
if (qb instanceof BoolQueryBuilder) { | ||
// Increment counter for Bool using Metric Framework. | ||
} else if (qb instanceof MatchQueryBuilder) { | ||
// Increment counter for Match using Metric Framework. | ||
} else if (qb instanceof QueryStringQueryBuilder) { | ||
// Increment counter for QueryStringQuery using Metric Framework. | ||
} | ||
// Similar for other builders | ||
} | ||
|
||
@Override | ||
public QueryBuilderVisitor getChildVisitor(BooleanClause.Occur occur) { | ||
return this; | ||
} | ||
}; | ||
topLevelQueryBuilder.visit(queryBuilderVisitor); | ||
} | ||
|
||
} |
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