summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-05-27 22:04:05 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-05-27 22:04:05 +0200
commit5c87d16c1b6d3ce02e7942c5e7e731584c16fdae (patch)
tree6887cac0342bb3ab087e0371ac99924faa4c8627 /container-search
parentda7b3afc9a294dd5512db1fa8716449f9bd03b70 (diff)
Iterate over indexes for juniper searcher.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java108
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java4
2 files changed, 48 insertions, 64 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java
index ca87c0c1d46..5c56379efc0 100644
--- a/container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java
@@ -78,13 +78,13 @@ public class JuniperSearcher extends Searcher {
@Override
public void fill(Result result, String summaryClass, Execution execution) {
Result workResult = result;
- final int worstCase = workResult.getHitCount();
- final List<Hit> hits = new ArrayList<>(worstCase);
- for (final Iterator<Hit> i = workResult.hits().deepIterator(); i.hasNext();) {
- final Hit sniffHit = i.next();
+ int worstCase = workResult.getHitCount();
+ List<Hit> hits = new ArrayList<>(worstCase);
+ for (Iterator<Hit> i = workResult.hits().deepIterator(); i.hasNext();) {
+ Hit sniffHit = i.next();
if ( ! (sniffHit instanceof FastHit)) continue;
- final FastHit hit = (FastHit) sniffHit;
+ FastHit hit = (FastHit) sniffHit;
if (hit.isFilled(summaryClass)) continue;
hits.add(hit);
@@ -105,54 +105,46 @@ public class JuniperSearcher extends Searcher {
Object searchDefinitionField = hit.getField(MAGIC_FIELD);
if (searchDefinitionField == null) continue;
- String searchDefinitionName = searchDefinitionField.toString();
-
- // TODO: Switch to iterate over indexes in the outer loop:
- //for (Index index : indexFacts.getIndexes(searchDefinitionName())) {
- // if (index.getDynamicSummary() || index.getHighlightSummary()) {
- // insertTags(hit.buildHitField(index.getName(), true, true), bolding, index.getDynamicSummary());
- // }
- //}
- for (String fieldName : hit.fields().keySet()) {
- Index index = indexFacts.getIndex(fieldName, searchDefinitionName);
- if (index.getDynamicSummary() || index.getHighlightSummary())
- insertTags(hit.buildHitField(fieldName, true, true), bolding, index.getDynamicSummary());
+
+ for (Index index : indexFacts.getIndexes(searchDefinitionField.toString())) {
+ if (index.getDynamicSummary() || index.getHighlightSummary()) {
+ HitField fieldValue = hit.buildHitField(index.getName(), true, true);
+ if (fieldValue != null)
+ insertTags(fieldValue, bolding, index.getDynamicSummary());
+ }
}
}
}
- private void insertTags(final HitField oldProperty, final boolean bolding, final boolean dynteaser) {
+ private void insertTags(HitField oldProperty, boolean bolding, boolean dynteaser) {
boolean insideHighlight = false;
- for (final ListIterator<FieldPart> i = oldProperty.listIterator(); i.hasNext();) {
- final FieldPart f = i.next();
- if (f instanceof SeparatorFieldPart) {
+ for (ListIterator<FieldPart> i = oldProperty.listIterator(); i.hasNext();) {
+ FieldPart f = i.next();
+ if (f instanceof SeparatorFieldPart)
setSeparatorString(bolding, (SeparatorFieldPart) f);
- }
- if (f.isFinal()) {
- continue;
- }
+ if (f.isFinal()) continue;
- final String toQuote = f.getContent();
+ String toQuote = f.getContent();
List<FieldPart> newFieldParts = null;
int previous = 0;
for (int j = 0; j < toQuote.length(); j++) {
- final char key = toQuote.charAt(j);
+ char key = toQuote.charAt(j);
switch (key) {
- case RAW_HIGHLIGHT_CHAR:
- newFieldParts = initFieldParts(newFieldParts);
- addBolding(bolding, insideHighlight, f, toQuote, newFieldParts, previous, j);
- previous = j + 1;
- insideHighlight = !insideHighlight;
- break;
- case RAW_SEPARATOR_CHAR:
- newFieldParts = initFieldParts(newFieldParts);
- addSeparator(bolding, dynteaser, f, toQuote, newFieldParts,
- previous, j);
- previous = j + 1;
- break;
- default:
- // no action
- break;
+ case RAW_HIGHLIGHT_CHAR:
+ newFieldParts = initFieldParts(newFieldParts);
+ addBolding(bolding, insideHighlight, f, toQuote, newFieldParts, previous, j);
+ previous = j + 1;
+ insideHighlight = !insideHighlight;
+ break;
+ case RAW_SEPARATOR_CHAR:
+ newFieldParts = initFieldParts(newFieldParts);
+ addSeparator(bolding, dynteaser, f, toQuote, newFieldParts,
+ previous, j);
+ previous = j + 1;
+ break;
+ default:
+ // no action
+ break;
}
}
if (previous > 0 && previous < toQuote.length()) {
@@ -160,37 +152,30 @@ public class JuniperSearcher extends Searcher {
}
if (newFieldParts != null) {
i.remove();
- for (final Iterator<FieldPart> j = newFieldParts.iterator(); j.hasNext();) {
+ for (Iterator<FieldPart> j = newFieldParts.iterator(); j.hasNext();) {
i.add(j.next());
}
}
}
}
- private void setSeparatorString(final boolean bolding,final SeparatorFieldPart f) {
- if (bolding) {
+ private void setSeparatorString(boolean bolding, SeparatorFieldPart f) {
+ if (bolding)
f.setContent(separatorTag);
- } else {
+ else
f.setContent(ELLIPSIS);
- }
}
- private void addSeparator(final boolean bolding, final boolean dynteaser,
- final FieldPart f, final String toQuote,
- final List<FieldPart> newFieldParts, final int previous, final int j) {
- if (previous != j) {
+ private void addSeparator(boolean bolding, boolean dynteaser, FieldPart f, String toQuote,
+ List<FieldPart> newFieldParts, int previous, int j) {
+ if (previous != j)
newFieldParts.add(new StringFieldPart(toQuote.substring(previous, j), f.isToken()));
- }
- if (dynteaser) {
- final FieldPart s = (bolding ? new SeparatorFieldPart(separatorTag) : new SeparatorFieldPart(ELLIPSIS));
- newFieldParts.add(s);
- }
+ if (dynteaser)
+ newFieldParts.add(bolding ? new SeparatorFieldPart(separatorTag) : new SeparatorFieldPart(ELLIPSIS));
}
- private void addBolding(final boolean bolding,
- final boolean insideHighlight, final FieldPart f,
- final String toQuote, final List<FieldPart> newFieldParts,
- final int previous, final int j) {
+ private void addBolding(boolean bolding, boolean insideHighlight, FieldPart f, String toQuote,
+ List<FieldPart> newFieldParts, int previous, int j) {
if (previous != j) {
newFieldParts.add(new StringFieldPart(toQuote.substring(previous, j), f.isToken()));
}
@@ -209,9 +194,8 @@ public class JuniperSearcher extends Searcher {
}
private List<FieldPart> initFieldParts(List<FieldPart> newFieldParts) {
- if (newFieldParts == null) {
+ if (newFieldParts == null)
newFieldParts = new ArrayList<>();
- }
return newFieldParts;
}
diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java
index f71c0803ce8..9f4a12d24e6 100644
--- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java
@@ -28,9 +28,9 @@ import java.util.List;
import java.util.Map;
/**
- * Tests conversion of juniper highlighting to XML
+ * Tests juniper highlighting
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
public class JuniperSearcherTestCase {