From ef5f9394bb550797299742c2f7b4c8384ed64a17 Mon Sep 17 00:00:00 2001 From: Varun Jain Date: Fri, 29 Sep 2023 09:53:25 -0700 Subject: [PATCH] Renaming and addressing comments of Martin Signed-off-by: Varun Jain --- .../neuralsearch/plugin/NeuralSearch.java | 9 +++---- ...va => EnrichingQueryDefaultProcessor.java} | 10 +++---- .../plugin/NeuralSearchTests.java | 4 +-- ... => EnrichingQueryDefaultProcessorIT.java} | 10 +++---- ... EnrichingQueryDefaultProcessorTests.java} | 26 +++++++++---------- 5 files changed, 28 insertions(+), 31 deletions(-) rename src/main/java/org/opensearch/neuralsearch/processor/{NeuralQueryProcessor.java => EnrichingQueryDefaultProcessor.java} (89%) rename src/test/java/org/opensearch/neuralsearch/processor/{NeuralQueryProcessorIT.java => EnrichingQueryDefaultProcessorIT.java} (89%) rename src/test/java/org/opensearch/neuralsearch/processor/{NeuralQueryProcessorTests.java => EnrichingQueryDefaultProcessorTests.java} (59%) diff --git a/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java b/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java index 9be60fed1..47882f25f 100644 --- a/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java +++ b/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java @@ -28,11 +28,8 @@ import org.opensearch.ingest.Processor; import org.opensearch.ml.client.MachineLearningNodeClient; import org.opensearch.neuralsearch.ml.MLCommonsClientAccessor; -import org.opensearch.neuralsearch.processor.NeuralQueryProcessor; -import org.opensearch.neuralsearch.processor.NormalizationProcessor; -import org.opensearch.neuralsearch.processor.NormalizationProcessorWorkflow; -import org.opensearch.neuralsearch.processor.SparseEncodingProcessor; -import org.opensearch.neuralsearch.processor.TextEmbeddingProcessor; +import org.opensearch.neuralsearch.processor.*; +import org.opensearch.neuralsearch.processor.EnrichingQueryDefaultProcessor; import org.opensearch.neuralsearch.processor.combination.ScoreCombinationFactory; import org.opensearch.neuralsearch.processor.combination.ScoreCombiner; import org.opensearch.neuralsearch.processor.factory.NormalizationProcessorFactory; @@ -145,6 +142,6 @@ public List> getSettings() { public Map> getRequestProcessors( Parameters parameters ) { - return Map.of(NeuralQueryProcessor.TYPE, new NeuralQueryProcessor.Factory()); + return Map.of(EnrichingQueryDefaultProcessor.TYPE, new EnrichingQueryDefaultProcessor.Factory()); } } diff --git a/src/main/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessor.java similarity index 89% rename from src/main/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessor.java rename to src/main/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessor.java index e38d96941..4b01a8f88 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessor.java @@ -25,7 +25,7 @@ */ @Setter @Getter -public class NeuralQueryProcessor extends AbstractProcessor implements SearchRequestProcessor { +public class EnrichingQueryDefaultProcessor extends AbstractProcessor implements SearchRequestProcessor { /** * Key to reference this processor type from a search pipeline. @@ -46,7 +46,7 @@ public String getType() { return TYPE; } - private NeuralQueryProcessor( + private EnrichingQueryDefaultProcessor( String tag, String description, boolean ignoreFailure, @@ -77,10 +77,10 @@ public static class Factory implements Processor.Factory /** * Create the processor object. * - * @return NeuralQueryProcessor + * @return EnrichingQueryDefaultProcessor */ @Override - public NeuralQueryProcessor create( + public EnrichingQueryDefaultProcessor create( Map> processorFactories, String tag, String description, @@ -100,7 +100,7 @@ public NeuralQueryProcessor create( throw new IllegalArgumentException("model Id or neural info map either of them should be provided"); } - return new NeuralQueryProcessor(tag, description, ignoreFailure, modelId, neuralInfoMap); + return new EnrichingQueryDefaultProcessor(tag, description, ignoreFailure, modelId, neuralInfoMap); } } } diff --git a/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java b/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java index 9c8a23d03..e3fe2bf0f 100644 --- a/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java +++ b/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java @@ -12,7 +12,7 @@ import java.util.Optional; import org.opensearch.ingest.Processor; -import org.opensearch.neuralsearch.processor.NeuralQueryProcessor; +import org.opensearch.neuralsearch.processor.EnrichingQueryDefaultProcessor; import org.opensearch.neuralsearch.processor.NormalizationProcessor; import org.opensearch.neuralsearch.processor.TextEmbeddingProcessor; import org.opensearch.neuralsearch.processor.factory.NormalizationProcessorFactory; @@ -83,6 +83,6 @@ public void testRequestProcessors() { parameters ); assertNotNull(processors); - assertNotNull(processors.get(NeuralQueryProcessor.TYPE)); + assertNotNull(processors.get(EnrichingQueryDefaultProcessor.TYPE)); } } diff --git a/src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorIT.java b/src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorIT.java similarity index 89% rename from src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorIT.java rename to src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorIT.java index 584388957..436a12d7e 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorIT.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorIT.java @@ -7,7 +7,6 @@ import static org.opensearch.neuralsearch.TestUtils.createRandomVector; -import java.io.IOException; import java.util.Collections; import java.util.Map; @@ -22,7 +21,7 @@ import com.google.common.primitives.Floats; -public class NeuralQueryProcessorIT extends BaseNeuralSearchIT { +public class EnrichingQueryDefaultProcessorIT extends BaseNeuralSearchIT { private static final String index = "my-nlp-index"; private static final String search_pipeline = "search-pipeline"; @@ -48,7 +47,7 @@ public void tearDown() { } @SneakyThrows - public void testNeuralQueryProcessor() throws Exception { + public void testEnrichingQueryProcessor_whenNoModelIdPassed_thenSuccess() { initializeIndexIfNotExist(); String modelId = getDeployedModelId(); createSearchRequestProcessor(modelId, search_pipeline); @@ -64,8 +63,9 @@ public void testNeuralQueryProcessor() throws Exception { } - private void initializeIndexIfNotExist() throws IOException { - if (index.equals(NeuralQueryProcessorIT.index) && !indexExists(index)) { + @SneakyThrows + private void initializeIndexIfNotExist() { + if (index.equals(EnrichingQueryDefaultProcessorIT.index) && !indexExists(index)) { prepareKnnIndex( index, Collections.singletonList(new KNNFieldConfig(TEST_KNN_VECTOR_FIELD_NAME_1, TEST_DIMENSION, TEST_SPACE_TYPE)) diff --git a/src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorTests.java b/src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorTests.java similarity index 59% rename from src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorTests.java rename to src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorTests.java index d1540524f..897a2b8e0 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorTests.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/EnrichingQueryDefaultProcessorTests.java @@ -14,11 +14,11 @@ import org.opensearch.search.builder.SearchSourceBuilder; import org.opensearch.test.OpenSearchTestCase; -public class NeuralQueryProcessorTests extends OpenSearchTestCase { +public class EnrichingQueryDefaultProcessorTests extends OpenSearchTestCase { - public void testFactory() throws Exception { - NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); - NeuralQueryProcessor processor = createTestProcessor(factory); + public void testFactory_whenMissingQueryParam_thenThrowException() throws Exception { + EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory(); + EnrichingQueryDefaultProcessor processor = createTestProcessor(factory); assertEquals("vasdcvkcjkbldbjkd", processor.getModelId()); assertEquals("bahbkcdkacb", processor.getNeuralFieldDefaultIdMap().get("fieldName").toString()); @@ -30,33 +30,33 @@ public void testFactory() throws Exception { } public void testFactory_whenModelIdIsNotString_thenFail() { - NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); + EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory(); Map configMap = new HashMap<>(); configMap.put("default_model_id", 55555L); expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), null, null, false, configMap, null)); } - public void testProcessRequest() throws Exception { - NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); + public void testProcessRequest_whenVisitingQueryBuilder_thenSuccess() throws Exception { + EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory(); NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); SearchRequest searchRequest = new SearchRequest(); searchRequest.source(new SearchSourceBuilder().query(neuralQueryBuilder)); - NeuralQueryProcessor processor = createTestProcessor(factory); + EnrichingQueryDefaultProcessor processor = createTestProcessor(factory); SearchRequest processSearchRequest = processor.processRequest(searchRequest); assertEquals(processSearchRequest, searchRequest); } public void testType() throws Exception { - NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); - NeuralQueryProcessor processor = createTestProcessor(factory); - assertEquals(NeuralQueryProcessor.TYPE, processor.getType()); + EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory(); + EnrichingQueryDefaultProcessor processor = createTestProcessor(factory); + assertEquals(EnrichingQueryDefaultProcessor.TYPE, processor.getType()); } - private NeuralQueryProcessor createTestProcessor(NeuralQueryProcessor.Factory factory) throws Exception { + private EnrichingQueryDefaultProcessor createTestProcessor(EnrichingQueryDefaultProcessor.Factory factory) throws Exception { Map configMap = new HashMap<>(); configMap.put("default_model_id", "vasdcvkcjkbldbjkd"); configMap.put("neural_field_default_id", Map.of("fieldName", "bahbkcdkacb")); - NeuralQueryProcessor processor = factory.create(Collections.emptyMap(), null, null, false, configMap, null); + EnrichingQueryDefaultProcessor processor = factory.create(Collections.emptyMap(), null, null, false, configMap, null); return processor; } }