mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
lucene 4: make sure to apply doc boost only once per field name
This commit is contained in:
parent
7ecfa9c35f
commit
bec0ffa623
@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
@ -41,10 +42,7 @@ import org.elasticsearch.index.mapper.object.ObjectMapper;
|
|||||||
import org.elasticsearch.index.mapper.object.RootObjectMapper;
|
import org.elasticsearch.index.mapper.object.RootObjectMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
@ -522,10 +520,15 @@ public class DocumentMapper implements ToXContent {
|
|||||||
}
|
}
|
||||||
// apply doc boost
|
// apply doc boost
|
||||||
if (context.docBoost() != 1.0f) {
|
if (context.docBoost() != 1.0f) {
|
||||||
|
Set<String> encounteredFields = Sets.newHashSet();
|
||||||
for (Document doc : context.docs()) {
|
for (Document doc : context.docs()) {
|
||||||
|
encounteredFields.clear();
|
||||||
for (IndexableField field : doc) {
|
for (IndexableField field : doc) {
|
||||||
if (field.fieldType().indexed() && !field.fieldType().omitNorms()) {
|
if (field.fieldType().indexed() && !field.fieldType().omitNorms()) {
|
||||||
((Field) field).setBoost(context.docBoost() * field.boost());
|
if (!encounteredFields.contains(field.name())) {
|
||||||
|
((Field) field).setBoost(context.docBoost() * field.boost());
|
||||||
|
encounteredFields.add(field.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user