Skip to content

Commit

Permalink
make sure to remove the _FIELD_TYPE style suffixes from the fieldname…
Browse files Browse the repository at this point in the history
… in get fields and add a test case
  • Loading branch information
mdavis95 committed May 8, 2023
1 parent 96e26d9 commit 6c222a1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions zulia-common/src/main/java/io/zulia/ZuliaFieldConstants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.zulia;

import io.zulia.message.ZuliaIndex;

public interface ZuliaFieldConstants {

String TIMESTAMP_FIELD = "_ztsf_";
Expand Down Expand Up @@ -27,4 +29,13 @@ public interface ZuliaFieldConstants {
String LIST_LENGTH_BARS = "|||";
String CHAR_LENGTH_BAR = "|";

String NUMERIC_INT_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.NUMERIC_INT;
String NUMERIC_LONG_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.NUMERIC_LONG;
String NUMERIC_FLOAT_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.NUMERIC_FLOAT;
String NUMERIC_DOUBLE_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.NUMERIC_DOUBLE;

String DATE_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.DATE;

String BOOL_SUFFIX = "_" + ZuliaIndex.FieldConfig.FieldType.BOOL;

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,34 @@ public ZuliaServiceOuterClass.GetFieldNamesResponse getFields() {
for (LeafReaderContext subReaderContext : indexReader.leaves()) {
FieldInfos fieldInfos = subReaderContext.reader().getFieldInfos();
for (FieldInfo fi : fieldInfos) {
builder.addFieldName(fi.name);

if (fi.getPointDimensionCount() > 0) {

int matchedLength = 0;
if (fi.name.endsWith(ZuliaFieldConstants.NUMERIC_INT_SUFFIX)) {
matchedLength = ZuliaFieldConstants.NUMERIC_INT_SUFFIX.length();
}
else if (fi.name.endsWith(ZuliaFieldConstants.NUMERIC_LONG_SUFFIX)) {
matchedLength = ZuliaFieldConstants.NUMERIC_LONG_SUFFIX.length();
}
else if (fi.name.endsWith(ZuliaFieldConstants.NUMERIC_FLOAT_SUFFIX)) {
matchedLength = ZuliaFieldConstants.NUMERIC_FLOAT_SUFFIX.length();
}
else if (fi.name.endsWith(ZuliaFieldConstants.NUMERIC_DOUBLE_SUFFIX)) {
matchedLength = ZuliaFieldConstants.NUMERIC_DOUBLE_SUFFIX.length();
}
else if (fi.name.endsWith(ZuliaFieldConstants.BOOL_SUFFIX)) {
matchedLength = ZuliaFieldConstants.BOOL_SUFFIX.length();
}
else if (fi.name.endsWith(ZuliaFieldConstants.DATE_SUFFIX)) {
matchedLength = ZuliaFieldConstants.DATE_SUFFIX.length();
}
builder.addFieldName(fi.name.substring(0, fi.name.length() - matchedLength));

}
else {
builder.addFieldName(fi.name);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public void aliasSearchTest() throws Exception {

GetFieldsResult getFields = zuliaWorkPool.getFields("someAlias");
Assertions.assertEquals(3, getFields.getFieldNames().size());
Assertions.assertTrue(getFields.getFieldNames().contains("id"));
Assertions.assertTrue(getFields.getFieldNames().contains("title"));
Assertions.assertTrue(getFields.getFieldNames().contains("rating"));

GetTermsResult getTermsResult = zuliaWorkPool.execute(new GetTerms("someAlias", "title"));
Assertions.assertEquals(6, getTermsResult.getTerms().size());
Expand Down

0 comments on commit 6c222a1

Please sign in to comment.