Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example using Hibernate Search #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-datastore-search</artifactId>
<version>${elide.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-test-helpers</artifactId>
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/example/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -112,6 +125,31 @@ public String getDynamicConfigPath() {
return analyticPropeties;
}

@Override
public DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore aggregationDataStore,
EntityManagerFactory entityManagerFactory) {

List<DataStore> 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() {
Expand Down Expand Up @@ -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");
/*
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/tmp/lucene/indexes"/>
<property name="hibernate.search.default.locking_strategy" value="single"/>
*/
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");
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/example/models/ArtifactGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down