Skip to content

Commit

Permalink
Add better OR support for mixed indexes.
Browse files Browse the repository at this point in the history
Issue : JanusGraph#163

Signed-off-by: David Clement <[email protected]>
  • Loading branch information
davidclement90 committed Feb 7, 2018
1 parent f2d1354 commit 972c64b
Show file tree
Hide file tree
Showing 33 changed files with 1,883 additions and 541 deletions.
3 changes: 3 additions & 0 deletions docs/basics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ While the index definition example looks similar to the composite index above, i
g.V().has('name', textContains('hercules')).has('age', inside(20, 50))
g.V().has('name', textContains('hercules'))
g.V().has('age', lt(50))
g.V().has('age', outside(20, 50))
g.V().has('age', lt(50).or(gte(60)))
g.V().or(__.has('name', textContains('hercules')), __.has('age', inside(20, 50)))

Mixed indexes support full-text search, range search, geo search and others. Refer to <<search-predicates>> for a list of predicates supported by a particular indexing backend.

Expand Down
3 changes: 2 additions & 1 deletion docs/elasticsearch.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ JanusGraph supports https://www.elastic.co/[Elasticsearch] as an index backend.
* *Flexible Configuration*: Supports remote operation and open-ended settings customization.
* *Collections*: Supports indexing SET and LIST cardinality properties.
* *Temporal*: Nanosecond granularity temporal indexing.
* *Custom Analyzer*: Choose to use a custom analyzer
* *Custom Analyzer*: Choose to use a custom analyzer.
* *Not Query-normal-form*: Supports others queries than Query-normal-form (QNF). QNF for JanusGraph is a variant of CNF (conjunctive normal form) with negation inlined where possible.

Please see <<version-compat>> for details on what versions of Elasticsearch will work with JanusGraph.

Expand Down
1 change: 1 addition & 0 deletions docs/lucene.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ In the above configuration, the index backend is named `search`. Replace `search
* *Geo*: Supports `Geo` predicates to search for geo properties that are intersecting, within, or contained in a given query geometry. Supports points, lines and polygons for indexing. Supports circles and boxes for querying point properties and all shapes for querying non-point properties. Note that JTS is required when using line and polygon shapes (see <<search-predicates#geoshape,Geoshape documentation>> for more information).
* *Numeric Range*: Supports all numeric comparisons in `Compare`.
* *Temporal*: Nanosecond granularity temporal indexing.
* *Not Query-normal-form*: Supports other query than Query-normal-form (QNF). QNF for JanusGraph is a variant of CNF (conjunctive normal form) with negation inlined where possible.

=== Configuration Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public interface JanusGraphQuery<Q extends JanusGraphQuery<Q>> {

Q hasNot(String key, Object value);

Q or(Q subQuery);

<T extends Comparable<?>> Q interval(String key, T startValue, T endValue);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public class IndexFeatures {
private final boolean supportsNanoseconds;
private final boolean supportsCustomAnalyzer;
private final boolean supportsGeoContains;
private final boolean supportNotQueryNormalForm;
private final ImmutableSet<Cardinality> supportedCardinalities;

public IndexFeatures(boolean supportsDocumentTTL, Mapping defaultMap, ImmutableSet<Mapping> supportedMap,
String wildcardField, ImmutableSet<Cardinality> supportedCardinalities, boolean supportsNanoseconds,
boolean supportCustomAnalyzer, boolean supportsGeoContains) {
boolean supportCustomAnalyzer, boolean supportsGeoContains, boolean supportNotQueryNormalForm) {

Preconditions.checkArgument(defaultMap!=null && defaultMap!=Mapping.DEFAULT);
Preconditions.checkArgument(supportedMap!=null && !supportedMap.isEmpty()
Expand All @@ -54,6 +55,7 @@ public IndexFeatures(boolean supportsDocumentTTL, Mapping defaultMap, ImmutableS
this.supportsNanoseconds = supportsNanoseconds;
this.supportsCustomAnalyzer = supportCustomAnalyzer;
this.supportsGeoContains = supportsGeoContains;
this.supportNotQueryNormalForm = supportNotQueryNormalForm;
}

public boolean supportsDocumentTTL() {
Expand All @@ -79,7 +81,7 @@ public boolean supportsCardinality(Cardinality cardinality) {
public boolean supportsNanoseconds() {
return supportsNanoseconds;
}

public boolean supportsCustomAnalyzer() {
return supportsCustomAnalyzer;
}
Expand All @@ -88,6 +90,10 @@ public boolean supportsGeoContains() {
return supportsGeoContains;
}

public boolean supportNotQueryNormalForm() {
return supportNotQueryNormalForm;
}

public static class Builder {

private boolean supportsDocumentTTL = false;
Expand All @@ -97,7 +103,8 @@ public static class Builder {
private String wildcardField = "*";
private boolean supportsNanoseconds;
private boolean supportsCustomAnalyzer;
private boolean supportsGeoContains = false;
private boolean supportsGeoContains;
private boolean supportNotQueryNormalForm;

public Builder supportsDocumentTTL() {
supportsDocumentTTL=true;
Expand Down Expand Up @@ -128,7 +135,7 @@ public Builder supportsNanoseconds() {
supportsNanoseconds = true;
return this;
}

public Builder supportsCustomAnalyzer() {
supportsCustomAnalyzer = true;
return this;
Expand All @@ -139,13 +146,15 @@ public Builder supportsGeoContains() {
return this;
}

public Builder supportNotQueryNormalForm() {
this.supportNotQueryNormalForm = true;
return this;
}

public IndexFeatures build() {
return new IndexFeatures(supportsDocumentTTL, defaultStringMapping, ImmutableSet.copyOf(supportedMappings),
wildcardField, ImmutableSet.copyOf(supportedCardinalities), supportsNanoseconds, supportsCustomAnalyzer,
supportsGeoContains);
supportsGeoContains, supportNotQueryNormalForm);
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public IndexQuery(String store, Condition condition, ImmutableList<OrderEntry> o
Preconditions.checkNotNull(store);
Preconditions.checkNotNull(condition);
Preconditions.checkArgument(orders != null);
Preconditions.checkArgument(QueryUtil.isQueryNormalForm(condition));
this.condition = condition;
this.orders = orders;
this.store = store;
Expand Down Expand Up @@ -103,14 +102,14 @@ public boolean equals(Object other) {
if (this == other) return true;
else if (other == null) return false;
else if (!getClass().isInstance(other)) return false;
IndexQuery oth = (IndexQuery) other;
final IndexQuery oth = (IndexQuery) other;
return store.equals(oth.store) && orders.equals(oth.orders)
&& condition.equals(oth.condition) && getLimit() == oth.getLimit();
}

@Override
public String toString() {
StringBuilder b = new StringBuilder();
final StringBuilder b = new StringBuilder();
b.append("[").append(condition.toString()).append("]");
if (!orders.isEmpty()) b.append(orders);
if (hasLimit()) b.append("(").append(getLimit()).append(")");
Expand Down Expand Up @@ -155,7 +154,7 @@ public boolean equals(Object oth) {
if (this == oth) return true;
else if (oth == null) return false;
else if (!getClass().isInstance(oth)) return false;
OrderEntry o = (OrderEntry) oth;
final OrderEntry o = (OrderEntry) oth;
return key.equals(o.key) && order == o.order;
}

Expand Down
Loading

0 comments on commit 972c64b

Please sign in to comment.