Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/SOLR-18306-optimize-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: Optimize IndexSchema.getDynamicFieldType() by checking cached fields before matching dynamic patterns.
type: other

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"changed" for a performance improvement

authors:
- name: Pierre Salagnac
links:
- name: SOLR-18306
url: https://issues.apache.org/jira/browse/SOLR-18306

21 changes: 19 additions & 2 deletions solr/core/src/java/org/apache/solr/schema/IndexSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,12 @@ public boolean isDynamicField(String fieldName) {
return false;
}

// If a field with same name exists in the cache, don't match
// all dynamic field patterns.
if (dynamicFieldCache.getIfPresent(fieldName) != null) {
return true;
}

for (DynamicField df : dynamicFields) {
if (df.matches(fieldName)) return true;
}
Expand Down Expand Up @@ -1477,13 +1483,24 @@ public FieldType getFieldTypeNoEx(String fieldName) {
* @see #getFieldTypeNoEx
*/
public FieldType getDynamicFieldType(String fieldName) {
for (DynamicField df : dynamicFields) {
if (df.matches(fieldName)) return df.prototype.getType();
FieldType type = dynFieldType(fieldName);
if (type != null) {
return type;
}

throw new SolrException(ErrorCode.BAD_REQUEST, "undefined field " + fieldName);
}

private FieldType dynFieldType(String fieldName) {

// First, lookup for the field name in the dynamic field cache. In case it
// is available there, we save matching all the patterns by retrieving the
// type from it.
SchemaField field = dynamicFieldCache.getIfPresent(fieldName);
if (field != null) {
return field.getType();
}

for (DynamicField df : dynamicFields) {
if (df.matches(fieldName)) return df.prototype.getType();
}
Expand Down
Loading