Skip to content

Commit

Permalink
Fixes #9020
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Oct 2, 2019
1 parent 16d4da5 commit 269ab6f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.Sort;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static com.orientechnologies.lucene.builder.OLuceneIndexType.createField;
import static com.orientechnologies.lucene.builder.OLuceneIndexType.createFields;
Expand All @@ -52,10 +54,7 @@ public Document newBuild(OIndexDefinition indexDefinition, Object key, OIdentifi
return null;
}

public Document build(OIndexDefinition definition,
Object key,
OIdentifiable value,
Map<String, Boolean> fieldsToStore,
public Document build(OIndexDefinition definition, Object key, OIdentifiable value, Map<String, Boolean> fieldsToStore,
ODocument metadata) {

Document doc = new Document();
Expand All @@ -75,12 +74,12 @@ public Document build(OIndexDefinition definition,
i++;
if (val != null) {
// doc.add(createField(field, val, Field.Store.YES));
createFields(field, val, Field.Store.YES)
.forEach(f -> doc.add(f));

Boolean sorted = isSorted(field, metadata);
createFields(field, val, Field.Store.YES, sorted).forEach(f -> doc.add(f));

//for cross class index
createFields(definition.getClassName() + "." + field, val, Field.Store.YES)
.forEach(f -> doc.add(f));
createFields(definition.getClassName() + "." + field, val, Field.Store.YES, sorted).forEach(f -> doc.add(f));

}
}
Expand Down Expand Up @@ -110,4 +109,28 @@ private List<Object> formatKeys(OIndexDefinition definition, Object key) {
protected Field.Store isToStore(String f, Map<String, Boolean> collectionFields) {
return collectionFields.get(f) ? Field.Store.YES : Field.Store.NO;
}

protected Boolean isSorted(String field, ODocument metadata) {

if (metadata == null)
return true;

Boolean sorted = true;
try {

Boolean localSorted = metadata.field("*_index_sorted");

if (localSorted == null) {
localSorted = metadata.field(field + "_index_sorted");
}
if (localSorted != null) {
sorted = localSorted;
}
} catch (Exception e) {

}

return sorted;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Field createField(String fieldName, Object value, Field.Store stor
return new TextField(fieldName, value.toString(), Field.Store.YES);
}

public static List<Field> createFields(String fieldName, Object value, Field.Store store /*,Field.Index index*/) {
public static List<Field> createFields(String fieldName, Object value, Field.Store store ,Boolean sort) {

List<Field> fields = new ArrayList<>();

Expand Down Expand Up @@ -80,7 +80,9 @@ public static List<Field> createFields(String fieldName, Object value, Field.Sto
return fields;
}

fields.add(new SortedDocValuesField(fieldName, new BytesRef(value.toString())));
if(Boolean.TRUE.equals(sort)) {
fields.add(new SortedDocValuesField(fieldName, new BytesRef(value.toString())));
}
fields.add(new TextField(fieldName, value.toString(), Field.Store.YES));

return fields;
Expand Down

Large diffs are not rendered by default.

0 comments on commit 269ab6f

Please sign in to comment.