From 5bb29bf3651d1be6c507109c7515fe9ec4f8eb36 Mon Sep 17 00:00:00 2001 From: Tushar Naik Date: Thu, 2 Mar 2023 21:21:43 +0530 Subject: [PATCH] Using the KeywordAnalyzer to skip analysis on the subsequent page hack --- forage-core/pom.xml | 2 +- forage-dropwizard-bundle/pom.xml | 2 +- .../forage/dropwizard/bundle/ForageBundle.java | 14 ++++++++++++-- forage-models/pom.xml | 2 +- forage-search-engine/pom.xml | 9 +++++++-- .../engine/lucene/ForageLuceneSearchEngine.java | 3 ++- pom.xml | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/forage-core/pom.xml b/forage-core/pom.xml index 0082e2f..c34655e 100644 --- a/forage-core/pom.xml +++ b/forage-core/pom.xml @@ -5,7 +5,7 @@ forage com.livetheoogway.forage - 1.0.10 + 1.0.11 4.0.0 diff --git a/forage-dropwizard-bundle/pom.xml b/forage-dropwizard-bundle/pom.xml index 5ab5dcd..8770335 100644 --- a/forage-dropwizard-bundle/pom.xml +++ b/forage-dropwizard-bundle/pom.xml @@ -5,7 +5,7 @@ forage com.livetheoogway.forage - 1.0.10 + 1.0.11 4.0.0 diff --git a/forage-dropwizard-bundle/src/main/java/com/livetheoogway/forage/dropwizard/bundle/ForageBundle.java b/forage-dropwizard-bundle/src/main/java/com/livetheoogway/forage/dropwizard/bundle/ForageBundle.java index cf7d0e7..f771c1c 100644 --- a/forage-dropwizard-bundle/src/main/java/com/livetheoogway/forage/dropwizard/bundle/ForageBundle.java +++ b/forage-dropwizard-bundle/src/main/java/com/livetheoogway/forage/dropwizard/bundle/ForageBundle.java @@ -28,6 +28,8 @@ import io.dropwizard.lifecycle.Managed; import io.dropwizard.setup.Environment; import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.apache.lucene.analysis.Analyzer; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -64,6 +66,10 @@ public ForageSearchEngine searchEngine() { return delegatedForageSearchEngine; } + public Analyzer analyser() { + return null; + } + /** * Use this to do adhoc {@link UpdateEngine#bootstrap()}, other than the periodic bootstrap that happens as part * of this bundle. @@ -80,11 +86,15 @@ public void run(final T configuration, final Environment environment) { @Override public void start() { log.info("[forage][startup] Starting the engine..."); - final ForageSearchEngineBuilder engineBuilder = ForageSearchEngineBuilder.builder() + val engineBuilder = ForageSearchEngineBuilder.builder() .withObjectMapper(environment.getObjectMapper()) .withDataStore(dataStore(configuration)); + val analyser = analyser(); + if (analyser != null) { + engineBuilder.withAnalyser(analyser); + } - final ForageEngineIndexer forageEngineIndexer = new ForageEngineIndexer<>(engineBuilder); + val forageEngineIndexer = new ForageEngineIndexer<>(engineBuilder); delegatedForageSearchEngine.onStart(forageEngineIndexer); diff --git a/forage-models/pom.xml b/forage-models/pom.xml index 7a1d56d..63f7941 100644 --- a/forage-models/pom.xml +++ b/forage-models/pom.xml @@ -5,7 +5,7 @@ forage com.livetheoogway.forage - 1.0.10 + 1.0.11 4.0.0 diff --git a/forage-search-engine/pom.xml b/forage-search-engine/pom.xml index ad62986..5031080 100644 --- a/forage-search-engine/pom.xml +++ b/forage-search-engine/pom.xml @@ -5,7 +5,7 @@ forage com.livetheoogway.forage - 1.0.10 + 1.0.11 4.0.0 @@ -13,8 +13,8 @@ 9.1.0 + 8.11.2 1.7.25 - @@ -33,6 +33,11 @@ lucene-queryparser ${lucene.version} + + org.apache.lucene + lucene-analyzers-common + ${lucene-analyzers-common.version} + com.fasterxml.jackson.core jackson-core diff --git a/forage-search-engine/src/main/java/com/livetheoogway/forage/search/engine/lucene/ForageLuceneSearchEngine.java b/forage-search-engine/src/main/java/com/livetheoogway/forage/search/engine/lucene/ForageLuceneSearchEngine.java index ef4f0a7..d1ade5b 100644 --- a/forage-search-engine/src/main/java/com/livetheoogway/forage/search/engine/lucene/ForageLuceneSearchEngine.java +++ b/forage-search-engine/src/main/java/com/livetheoogway/forage/search/engine/lucene/ForageLuceneSearchEngine.java @@ -42,6 +42,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.TopDocs; @@ -79,7 +80,7 @@ public ForageLuceneSearchEngine(final ObjectMapper mapper, this.luceneQueryGenerator = new LuceneQueryGenerator(analyzer, queryParserFactory); this.lucenePagination = new LucenePagination(mapper); this.dataStore = dataStore; - this.queryParser = new QueryParser("TEMP", analyzer); //todo needs a more elegant solution for page parsing + this.queryParser = new QueryParser("NO_FIELD", new KeywordAnalyzer()); //todo needs a more elegant solution for page parsing } @Override diff --git a/pom.xml b/pom.xml index f7b3ef7..4d9bdc2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.livetheoogway.forage forage pom - 1.0.10 + 1.0.11 forage