-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Varun Jain <[email protected]>
- Loading branch information
1 parent
dac5012
commit 6903f94
Showing
6 changed files
with
229 additions
and
128 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
100 changes: 0 additions & 100 deletions
100
src/main/java/org/opensearch/neuralsearch/processor/DefaultValueProcessor.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/main/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessor.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,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.processor; | ||
|
||
import java.util.Map; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.ingest.ConfigurationUtils; | ||
import org.opensearch.neuralsearch.query.visitor.NeuralSearchQueryVisitor; | ||
import org.opensearch.search.pipeline.AbstractProcessor; | ||
import org.opensearch.search.pipeline.Processor; | ||
import org.opensearch.search.pipeline.SearchRequestProcessor; | ||
|
||
public class NeuralQueryProcessor extends AbstractProcessor implements SearchRequestProcessor { | ||
|
||
/** | ||
* Key to reference this processor type from a search pipeline. | ||
*/ | ||
public static final String TYPE = "default_query"; | ||
|
||
private final String modelId; | ||
|
||
private final Map<String, Object> fieldInfoMap; | ||
|
||
/** | ||
* Returns the type of the processor. | ||
* | ||
* @return The processor type. | ||
*/ | ||
@Override | ||
public String getType() { | ||
return TYPE; | ||
} | ||
|
||
protected NeuralQueryProcessor( | ||
String tag, | ||
String description, | ||
boolean ignoreFailure, | ||
String modelId, | ||
Map<String, Object> fieldInfoMap | ||
) { | ||
super(tag, description, ignoreFailure); | ||
this.modelId = modelId; | ||
this.fieldInfoMap = fieldInfoMap; | ||
} | ||
|
||
@Override | ||
public SearchRequest processRequest(SearchRequest searchRequest) throws Exception { | ||
QueryBuilder queryBuilder = searchRequest.source().query(); | ||
queryBuilder.visit(new NeuralSearchQueryVisitor(modelId, fieldInfoMap)); | ||
return searchRequest; | ||
} | ||
|
||
public static class Factory implements Processor.Factory<SearchRequestProcessor> { | ||
private static final String DEFAULT_MODEL_ID = "default_model_id"; | ||
private static final String NEURAL_FIELD_MAP = "neural_field_map"; | ||
|
||
@Override | ||
public NeuralQueryProcessor create( | ||
Map<String, Processor.Factory<SearchRequestProcessor>> processorFactories, | ||
String tag, | ||
String description, | ||
boolean ignoreFailure, | ||
Map<String, Object> config, | ||
PipelineContext pipelineContext | ||
) throws Exception { | ||
String modelId = (String) config.remove(DEFAULT_MODEL_ID); | ||
Map<String, Object> neuralInfoMap = ConfigurationUtils.readOptionalMap(TYPE, tag, config, NEURAL_FIELD_MAP); | ||
|
||
if (modelId == null && neuralInfoMap == null) { | ||
throw new IllegalArgumentException("model Id or neural info map either of them should be provided"); | ||
} | ||
|
||
return new NeuralQueryProcessor(tag, description, ignoreFailure, modelId, neuralInfoMap); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.