diff --git a/pom.xml b/pom.xml index fe54706..6a25d26 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,11 @@ + + com.yahoo.elide + elide-datastore-search + ${elide.version} + com.yahoo.elide elide-test-helpers diff --git a/src/main/java/example/Settings.java b/src/main/java/example/Settings.java index 652c7a2..5524a9c 100644 --- a/src/main/java/example/Settings.java +++ b/src/main/java/example/Settings.java @@ -7,7 +7,16 @@ package example; import com.google.common.collect.Lists; +import com.yahoo.elide.core.datastore.DataStore; +import com.yahoo.elide.datastores.aggregation.AggregationDataStore; +import com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore; import com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialectFactory; +import com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator; +import com.yahoo.elide.datastores.jpa.JpaDataStore; +import com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction; +import com.yahoo.elide.datastores.multiplex.MultiplexManager; +import com.yahoo.elide.datastores.search.SearchDataStore; +import com.yahoo.elide.modelconfig.store.ConfigDataStore; import com.yahoo.elide.standalone.config.ElideStandaloneAnalyticSettings; import com.yahoo.elide.standalone.config.ElideStandaloneAsyncSettings; import com.yahoo.elide.standalone.config.ElideStandaloneSettings; @@ -24,10 +33,14 @@ import java.io.IOException; import java.sql.DriverManager; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Properties; import javax.jms.ConnectionFactory; +import javax.persistence.EntityManagerFactory; + +import static com.yahoo.elide.datastores.jpa.JpaDataStore.DEFAULT_LOGGER; /** * This class contains common settings for both test and production. @@ -112,6 +125,31 @@ public String getDynamicConfigPath() { return analyticPropeties; } + @Override + public DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore aggregationDataStore, + EntityManagerFactory entityManagerFactory) { + + List stores = new ArrayList<>(); + + + DataStore jpaDataStore = new JpaDataStore( + () -> entityManagerFactory.createEntityManager(), + em -> new NonJtaTransaction(em, TXCANCEL, DEFAULT_LOGGER, true, true)); + + SearchDataStore searchDataStore = new SearchDataStore(jpaDataStore, entityManagerFactory, true, 3, 50); + stores.add(searchDataStore); + + if (getAnalyticProperties().enableDynamicModelConfigAPI()) { + stores.add(new ConfigDataStore(getAnalyticProperties().getDynamicConfigPath(), + new TemplateConfigValidator(getClassScanner(), getAnalyticProperties().getDynamicConfigPath()))); + } + + stores.add(metaDataStore); + stores.add(aggregationDataStore); + + return new MultiplexManager(stores.toArray(new DataStore[0])); + } + @Override public ElideStandaloneSubscriptionSettings getSubscriptionProperties() { return new ElideStandaloneSubscriptionSettings() { @@ -202,6 +240,14 @@ protected Properties getInMemoryProps() { options.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); options.put("hibernate.current_session_context_class", "thread"); options.put("hibernate.jdbc.use_scrollable_resultset", "true"); + /* + + + + */ + options.put("hibernate.search.default.directory_provider", "filesystem"); + options.put("hibernate.search.default.indexBase", "/tmp/lucene/indexes"); + options.put("hibernate.search.default.locking_strategy", "single"); options.put("hibernate.default_batch_fetch_size", 100); options.put("javax.persistence.jdbc.driver", "org.h2.Driver"); diff --git a/src/main/java/example/models/ArtifactGroup.java b/src/main/java/example/models/ArtifactGroup.java index 5d69784..aeee198 100644 --- a/src/main/java/example/models/ArtifactGroup.java +++ b/src/main/java/example/models/ArtifactGroup.java @@ -11,6 +11,9 @@ import com.yahoo.elide.graphql.subscriptions.annotations.SubscriptionField; import lombok.Data; +import org.apache.lucene.analysis.core.LowerCaseFilterFactory; +import org.apache.lucene.analysis.ngram.NGramTokenizerFactory; +import org.hibernate.search.annotations.*; import javax.persistence.Entity; import javax.persistence.Id; @@ -20,15 +23,29 @@ import java.util.List; @Include(name = "group") +@Indexed @Table(name = "artifactgroup") @Entity @Subscription @Data +@AnalyzerDef(name = "case_insensitive", + tokenizer = @TokenizerDef(factory = NGramTokenizerFactory.class, params = { + @Parameter(name = "minGramSize", value = "3"), + @Parameter(name = "maxGramSize", value = "50") + }), + filters = { + @TokenFilterDef(factory = LowerCaseFilterFactory.class) + } +) public class ArtifactGroup { @Id private String name = ""; @SubscriptionField + @Fields({ + @Field(name = "commonName", index = Index.YES, + analyze = Analyze.YES, store = Store.NO, analyzer = @Analyzer(definition = "case_insensitive")), + }) private String commonName = ""; @SubscriptionField