Skip to content

Commit

Permalink
#4051 Fix search extraction for Elastic indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Mar 12, 2024
1 parent 6bdba45 commit ec40ee4
Show file tree
Hide file tree
Showing 37 changed files with 125 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void testFindIndexedFields() {
final QueryField expected = QueryField
.builder()
.name("Action")
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(actual.getConditionSet())
.queryable(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public static QueryField buildDsField(final Column column) {
return QueryField
.builder()
.name(column.getName())
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(ConditionSet.BASIC_TEXT)
.queryable(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ private void changeField(final FieldInfo field, final Condition condition, final
conditionListBox.setValue(selected);
changeCondition(field, selected);

if (field != null && field.getFieldType() != null) {
fieldTypeLabel.setText(field.getFieldType().getShortTypeName());
fieldTypeLabel.setTitle(field.getFieldType().getDescription());
if (field != null && field.getType() != null) {
fieldTypeLabel.setText(field.getType().getShortTypeName());
fieldTypeLabel.setTitle(field.getType().getDescription());
fieldTypeLabel.setVisible(true);
} else {
fieldTypeLabel.setVisible(false);
Expand All @@ -263,7 +263,7 @@ private List<Condition> getConditions(final FieldInfo field) {
} else {
FieldType fieldType = null;
if (field != null) {
fieldType = field.getFieldType();
fieldType = field.getType();
}
conditions = ConditionSet.getUiDefaultConditions(fieldType);
}
Expand All @@ -275,8 +275,8 @@ private void changeCondition(final FieldInfo field,
final Condition condition) {
final FieldInfo selectedField = fieldListBox.getValue();
FieldType indexFieldType = null;
if (selectedField != null && selectedField.getFieldType() != null) {
indexFieldType = selectedField.getFieldType();
if (selectedField != null && selectedField.getType() != null) {
indexFieldType = selectedField.getType();
}

if (indexFieldType == null) {
Expand Down Expand Up @@ -351,7 +351,7 @@ private void enterDocRefMode(final FieldInfo field, final Condition condition) {
} else if (Condition.IN_FOLDER.equals(condition)) {
docSelectionBoxPresenter.setIncludedTypes("Folder");
docSelectionBoxPresenter.setAllowFolderSelection(true);
} else if (FieldType.DOC_REF.equals(field.getFieldType())) {
} else if (FieldType.DOC_REF.equals(field.getType())) {
docSelectionBoxPresenter.setIncludedTypes(field.getDocRefType());
}
docSelectionBoxPresenter.setSelectedEntityReference(term.getDocRef());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private static Column convertFieldInfo(final FieldInfo fieldInfo) {
final Builder columnBuilder = Column.builder();
columnBuilder.name(indexFieldName);

final FieldType fieldType = fieldInfo.getFieldType();
final FieldType fieldType = fieldInfo.getType();
if (fieldType != null) {
switch (fieldType) {
case DATE:
Expand All @@ -309,7 +309,7 @@ private static Column convertFieldInfo(final FieldInfo fieldInfo) {
// Turn 'annotation:.*' fields into annotation links that make use of either the special
// eventId/streamId fields (so event results can link back to annotations) OR
// the annotation:Id field so Annotations datasource results can link back.
expression = buildAnnotationFieldExpression(fieldInfo.getFieldType(), indexFieldName);
expression = buildAnnotationFieldExpression(fieldInfo.getType(), indexFieldName);
columnBuilder.expression(expression);
} else {
expression = ParamSubstituteUtil.makeParam(indexFieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FieldEditPresenter(final EventBus eventBus, final FieldEditView view) {

public void read(final QueryField field, final Set<String> otherFieldNames) {
this.otherFieldNames = otherFieldNames;
getView().setFieldType(field.getFieldType());
getView().setFieldType(field.getType());
getView().setName(field.getName());
}

Expand Down Expand Up @@ -90,7 +90,7 @@ private QueryField create(final FieldType type, final String name) {
return QueryField
.builder()
.name(name)
.fieldType(type)
.type(type)
.queryable(true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void addTypeColumn() {
dataGrid.addResizableColumn(new Column<QueryField, String>(new TextCell()) {
@Override
public String getValue(final QueryField row) {
return row.getFieldType().getTypeName();
return row.getType().getTypeName();
}
}, "Type", 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:form="urn:import:stroom.widget.form.client">
<g:FlowPanel styleName="max form">
<form:FormGroup identity="solrIndexFieldUse" label="Field Use">
<l:SelectionBox ui:field="fieldUse" addStyleNames="w-100"/>
<l:SelectionBox ui:field="type" addStyleNames="w-100"/>
</form:FormGroup>
<form:FormGroup identity="solrIndexFieldName" label="Field Name">
<g:TextBox ui:field="fieldName" addStyleNames="w-100"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
package stroom.index.shared;

import stroom.datasource.api.v2.Field;
import stroom.datasource.api.v2.FieldType;

public interface IndexField extends Field {

FieldType getType();

default AnalyzerType getAnalyzerType() {
return AnalyzerType.KEYWORD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class IndexShardFields {
public static final String FIELD_NAME_LAST_COMMIT = "Last Commit";

public static final QueryField FIELD_NODE = QueryField.createText(FIELD_NAME_NODE);
public static final QueryField FIELD_INDEX = QueryField.byUuid(LuceneIndexDoc.DOCUMENT_TYPE, FIELD_NAME_INDEX);
public static final QueryField FIELD_INDEX_NAME = QueryField.byNonUniqueName(
public static final QueryField FIELD_INDEX = QueryField.createDocRefByUuid(LuceneIndexDoc.DOCUMENT_TYPE, FIELD_NAME_INDEX);
public static final QueryField FIELD_INDEX_NAME = QueryField.createDocRefByNonUniqueName(
LuceneIndexDoc.DOCUMENT_TYPE, FIELD_NAME_INDEX_NAME);
public static final QueryField FIELD_VOLUME_PATH = QueryField.createText(FIELD_NAME_VOLUME_PATH);
public static final QueryField FIELD_VOLUME_GROUP = QueryField.createText(FIELD_NAME_VOLUME_GROUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ public static LuceneIndexField createDateField(final String fieldName) {
.build();
}

@Override
public String getName() {
return name;
}

@Override
public FieldType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class MetaFields {

// Non grouped fields
// Maps to the docref name (which is unique)
public static final QueryField FEED = QueryField.byUniqueName("Feed", "Feed");
public static final QueryField FEED = QueryField.createDocRefByUniqueName("Feed", "Feed");

// Maps to the docref uuid
public static final QueryField PIPELINE = QueryField.byUuid(
public static final QueryField PIPELINE = QueryField.createDocRefByUuid(
PipelineDoc.DOCUMENT_TYPE,
"Pipeline");

// Maps to the docref name (which is not unique)
public static final QueryField PIPELINE_NAME = QueryField.byNonUniqueName(
public static final QueryField PIPELINE_NAME = QueryField.createDocRefByNonUniqueName(
PipelineDoc.DOCUMENT_TYPE,
"Pipeline Name");

Expand Down Expand Up @@ -74,7 +74,7 @@ public class MetaFields {
public static final QueryField PARENT_ID = QueryField.createId("Parent Id");
public static final QueryField PARENT_STATUS = QueryField.createText("Parent Status");
public static final QueryField PARENT_CREATE_TIME = QueryField.createDate("Parent Create Time");
public static final QueryField PARENT_FEED = QueryField.byUniqueName("Feed", FIELD_PARENT_FEED);
public static final QueryField PARENT_FEED = QueryField.createDocRefByUniqueName("Feed", FIELD_PARENT_FEED);

static {
// Non grouped fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public class ReferenceDataFields {
public static final QueryField FEED_NAME_FIELD = QueryField
.builder()
.name("Feed Name")
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(ConditionSet.REF_DATA_TEXT)
.queryable(true)
.build();
public static final QueryField KEY_FIELD = QueryField
.builder()
.name("Key")
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(ConditionSet.REF_DATA_TEXT)
.queryable(true)
.build();
public static final QueryField VALUE_FIELD = QueryField
.builder()
.name("Value")
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(ConditionSet.REF_DATA_TEXT)
.queryable(true)
.build();
Expand All @@ -40,7 +40,7 @@ public class ReferenceDataFields {
public static final QueryField MAP_NAME_FIELD = QueryField
.builder()
.name("Map Name")
.fieldType(FieldType.TEXT)
.type(FieldType.TEXT)
.conditionSet(ConditionSet.REF_DATA_TEXT)
.queryable(true)
.build();
Expand All @@ -53,7 +53,7 @@ public class ReferenceDataFields {
public static final QueryField PIPELINE_FIELD = QueryField
.builder()
.name("Reference Loader Pipeline")
.fieldType(FieldType.DOC_REF)
.type(FieldType.DOC_REF)
.conditionSet(ConditionSet.REF_DATA_DOC_REF)
.docRefType(PipelineDoc.DOCUMENT_TYPE)
.queryable(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class ProcessorFields {

public static final QueryField ID = QueryField.createId("Processor Id");
public static final QueryField PROCESSOR_TYPE = QueryField.createText("Processor Type");
public static final QueryField PIPELINE = QueryField.byUuid(
public static final QueryField PIPELINE = QueryField.createDocRefByUuid(
PipelineDoc.DOCUMENT_TYPE, "Processor Pipeline");
public static final QueryField ANALYTIC_RULE = QueryField.byUuid(
public static final QueryField ANALYTIC_RULE = QueryField.createDocRefByUuid(
AnalyticRuleDoc.DOCUMENT_TYPE, "Analytic Rule");
public static final QueryField ENABLED = QueryField.createBoolean("Processor Enabled");
public static final QueryField DELETED = QueryField.createBoolean("Processor Deleted");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class ProcessorTaskFields {
public static final QueryField STATUS_TIME = QueryField.createDate("Status Time");
public static final QueryField META_ID = QueryField.createId("Meta Id");
public static final QueryField NODE_NAME = QueryField.createText("Node");
public static final QueryField PIPELINE = QueryField.byUuid(PipelineDoc.DOCUMENT_TYPE, FIELD_PIPELINE);
public static final QueryField PIPELINE_NAME = QueryField.byNonUniqueName(
public static final QueryField PIPELINE = QueryField.createDocRefByUuid(PipelineDoc.DOCUMENT_TYPE, FIELD_PIPELINE);
public static final QueryField PIPELINE_NAME = QueryField.createDocRefByNonUniqueName(
PipelineDoc.DOCUMENT_TYPE, FIELD_PIPELINE_NAME);
public static final QueryField PROCESSOR_FILTER_ID = QueryField.createId("Processor Filter Id");
public static final QueryField PROCESSOR_FILTER_PRIORITY = QueryField.createLong("Processor Filter Priority");
public static final QueryField PROCESSOR_ID = QueryField.createId("Processor Id");
public static final QueryField FEED = QueryField.byUniqueName("Feed", "Feed");
public static final QueryField FEED = QueryField.createDocRefByUniqueName("Feed", "Feed");
public static final QueryField STATUS = QueryField.createText("Status");
public static final QueryField TASK_ID = QueryField.createId("Task Id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ private static String convertLegacyNativeType(final String nativeType, final Str
return nativeType;
}

@Override
public String getName() {
return name;
}

@Override
public FieldType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static QueryField convert(final SolrIndexField field) {
return QueryField
.builder()
.name(field.getName())
.fieldType(field.getType())
.type(field.getType())
.conditionSet(ConditionSet.getSolr(field.getType()))
.queryable(field.isIndexed())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public static SolrIndexField createIdField(final String fieldName) {
.build();
}

@Override
public String getName() {
return name;
}
Expand All @@ -234,6 +235,7 @@ public void setName(final String name) {
this.name = name;
}

@Override
public FieldType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public Optional<Condition> innerApply(final ExpressionItem item) {
if (!abstractField.supportsCondition(term.getCondition())) {
LOGGER.debug(() -> LogUtil.message(
"Condition '{}' is not supported by field '{}' of type {}. Term: {}",
term.getCondition(), fieldName, abstractField.getFieldType().getTypeName(), term));
if (FieldType.DOC_REF.equals(abstractField.getFieldType())) {
term.getCondition(), fieldName, abstractField.getType().getTypeName(), term));
if (FieldType.DOC_REF.equals(abstractField.getType())) {
// https://github.com/gchq/stroom/issues/3074 removed some conditions from DocRefField
// instances so log an error
LOGGER.error("Condition '{}' is not supported by field '{}' of type {}. Term: {}",
term.getCondition(), fieldName, abstractField.getFieldType(), term);
term.getCondition(), fieldName, abstractField.getType(), term);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private Condition isInDictionary(final DocRef docRef) {
private Condition isInFolder(final ExpressionTerm term, final DocRef docRef) {
Condition condition = field.in(Collections.emptyList());

if (FieldType.DOC_REF.equals(dataSourceField.getFieldType())) {
if (FieldType.DOC_REF.equals(dataSourceField.getType())) {
final String type = dataSourceField.getDocRefType();
if (type != null && collectionService != null) {
final Set<DocRef> descendants = collectionService.getDescendants(docRef, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ public boolean validateExpressionTerms(final ExpressionItem expressionItem) {
"of type {}. Term: {}",
term.getCondition(),
term.getField(),
field.getFieldType().getTypeName(), term));
field.getType().getTypeName(), term));
} else {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static Map<String, Object> createAttributeMap(final Meta meta, final Map<String,
final String value = attributeMap.get(field.getName());
if (value != null) {
try {
switch (field.getFieldType()) {
switch (field.getType()) {
case TEXT:
map.put(field.getName(), value);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ private Predicate<RefStoreEntry> convertExpressionTerm(final ExpressionTerm expr
// field => fieldType
QueryField abstractField = FIELD_NAME_TO_FIELD_MAP.get(expressionTerm.getField());

return switch (abstractField.getFieldType()) {
return switch (abstractField.getType()) {
case TEXT -> buildTextFieldPredicate(expressionTerm, refStoreEntry ->
(String) FIELD_TO_EXTRACTOR_MAP.get(expressionTerm.getField()).apply(refStoreEntry));
case LONG -> buildLongFieldPredicate(expressionTerm, refStoreEntry ->
Expand Down Expand Up @@ -1067,12 +1067,12 @@ private boolean docRefsEqualOnUuid(final DocRef docRef1, final DocRef docRef2) {
}

private Val convertToVal(final Object object, final QueryField field) {
return switch (field.getFieldType()) {
return switch (field.getType()) {
case TEXT -> ValString.create((String) object);
case INTEGER -> ValInteger.create((Integer) object);
case LONG, ID, DATE -> ValLong.create((long) object);
case DOC_REF -> getPipelineNameAsVal((DocRef) object);
default -> throw new RuntimeException("Unexpected field type " + field.getFieldType());
default -> throw new RuntimeException("Unexpected field type " + field.getType());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ private boolean validateExpressionTerms(final ExpressionItem expressionItem) {
"of type {}. Term: {}",
term.getCondition(),
term.getField(),
field.getFieldType(), term));
field.getType(), term));
} else {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import stroom.docref.HasDisplayValue;

public interface Field extends HasDisplayValue, Comparable<Field> {

String getName();

FieldType getType();
}
Loading

0 comments on commit ec40ee4

Please sign in to comment.