Skip to content
Permalink
Browse files
Merge pull request #524 from klcodanr/elastic-function-support
OAK-9727 - ElasticSearch Index Function Support
  • Loading branch information
thomasmueller committed Mar 22, 2022
2 parents a316bb3 + e5b94ad commit 851486406c2d617949bf14c53f1fec059df8c142
Showing 6 changed files with 181 additions and 147 deletions.
@@ -18,21 +18,22 @@
*/
package org.apache.jackrabbit.oak.plugins.index.elastic;

import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.PropertyDefinition;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.jetbrains.annotations.NotNull;
import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValue;
import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValues;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValue;
import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValues;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.PropertyDefinition;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.jetbrains.annotations.NotNull;

public class ElasticIndexDefinition extends IndexDefinition {

@@ -133,9 +134,16 @@ public ElasticIndexDefinition(NodeState root, NodeState defn, String indexPath,

this.propertiesByName = getDefinedRules()
.stream()
.flatMap(rule -> StreamSupport.stream(rule.getProperties().spliterator(), false))
.flatMap(rule -> Stream.concat(StreamSupport.stream(rule.getProperties().spliterator(), false),
rule.getFunctionRestrictions().stream()))
.filter(pd -> pd.index) // keep only properties that can be indexed
.collect(Collectors.groupingBy(pd -> pd.name));
.collect(Collectors.groupingBy(pd -> {
if (pd.function != null) {
return pd.function;
} else {
return pd.name;
}
}));

this.dynamicBoostProperties = getDefinedRules()
.stream()
@@ -24,7 +24,7 @@
* {@link IndexEditor} implementation that is responsible for keeping the
* corresponding Elasticsearch index up to date
*/
class ElasticIndexEditor extends FulltextIndexEditor<ElasticDocument> {
public class ElasticIndexEditor extends FulltextIndexEditor<ElasticDocument> {
ElasticIndexEditor(FulltextIndexEditorContext<ElasticDocument> context) {
super(context);
}
@@ -57,14 +57,12 @@ protected List<QueryIndex.OrderEntry> createSortOrder(IndexDefinition.IndexingRu
// support for path ordering in both directions
orderEntries.add(o);
}
// TODO: add support for function-based sorting
// for (PropertyDefinition functionIndex : rule.getFunctionRestrictions()) {
// if (functionIndex.ordered && o.getPropertyName().equals(functionIndex.function)) {
// // can manage any order desc/asc
// orderEntries.add(o);
// result.sortedProperties.add(functionIndex);
// }
// }
for (PropertyDefinition functionIndex : rule.getFunctionRestrictions()) {
if (functionIndex.ordered && o.getPropertyName().equals(functionIndex.function)) {
// can manage any order desc/asc
orderEntries.add(o);
}
}
}

//TODO Should we return order entries only when all order clauses are satisfied
@@ -17,41 +17,55 @@
package org.apache.jackrabbit.oak.plugins.index.elastic;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.InitialContentHelper;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.FunctionIndexCommonTest;
import org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditor;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.junit.ClassRule;
import org.junit.Ignore;

import java.util.Set;
import java.util.concurrent.TimeUnit;

import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;

@Ignore
public class ElasticFunctionIndexCommonTest extends FunctionIndexCommonTest {
@ClassRule
public static final ElasticConnectionRule elasticRule =
new ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
public static final ElasticConnectionRule elasticRule = new ElasticConnectionRule(
ElasticTestUtils.ELASTIC_CONNECTION_STRING);

public ElasticFunctionIndexCommonTest() {
indexOptions = new ElasticIndexOptions();
}

@Override
protected ContentRepository createRepository() {
repositoryOptionsUtil = new ElasticTestRepositoryBuilder(elasticRule).build();
return repositoryOptionsUtil.getOak().createContentRepository();
protected String getIndexProvider() {
return "elasticsearch:";
}

@Override
protected void postCommitHook() {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

@Override
protected void createTestIndexNode() {
setTraversalEnabled(false);
protected ContentRepository createRepository() {
ElasticTestRepositoryBuilder builder = new ElasticTestRepositoryBuilder(elasticRule);
builder.setNodeStore(new MemoryNodeStore(InitialContentHelper.INITIAL_CONTENT));
repositoryOptionsUtil = builder.build();

return repositoryOptionsUtil.getOak().createContentRepository();
}

protected Tree createIndex(String name, Set<String> propNames) {
@@ -66,13 +80,14 @@ protected Tree createIndex(Tree index, String name, Set<String> propNames) {
def.setProperty(TYPE_PROPERTY_NAME, indexOptions.getIndexType());
def.setProperty(REINDEX_PROPERTY_NAME, true);
def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
def.setProperty(PropertyStates.createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_NAMES, propNames, Type.STRINGS));
//def.setProperty(LuceneIndexConstants.SAVE_DIR_LISTING, true);
def.setProperty(
PropertyStates.createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_NAMES, propNames, Type.STRINGS));
// def.setProperty(LuceneIndexConstants.SAVE_DIR_LISTING, true);
return index.getChild(INDEX_DEFINITIONS_NAME).getChild(name);
}

@Override
protected String getLoggerName() {
return null;
return ElasticIndexEditor.class.getName();
}
}
@@ -29,7 +29,6 @@
import org.apache.jackrabbit.oak.plugins.index.elastic.query.ElasticIndexProvider;
import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
import org.apache.jackrabbit.oak.query.QueryEngineSettings;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;

import static com.google.common.collect.Lists.newArrayList;
@@ -39,7 +38,7 @@ public class ElasticTestRepositoryBuilder extends TestRepositoryBuilder {

private final ElasticConnection esConnection;
private final ElasticIndexTracker indexTracker;
private final int asyncIndexingTimeInSeconds = 5;
private final int asyncIndexingTimeInSeconds = 1;

public ElasticTestRepositoryBuilder(ElasticConnectionRule elasticRule) {
this.esConnection = elasticRule.useDocker() ? elasticRule.getElasticConnectionForDocker() :

0 comments on commit 8514864

Please sign in to comment.