aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-05-22 12:53:31 +0200
committerJon Bratseth <bratseth@oath.com>2018-05-22 12:53:31 +0200
commit618f7be3e8c38c9fd29fb4ade6bc048488f86276 (patch)
tree4a14a49a4be9261c852cccb0048d3ef732bf7d70
parentc9bad532ed114e57594f975fdb1f697e4a288910 (diff)
Iterate over indexes not fields
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/searcher/JuniperSearcher.java108
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/templates/SearchRendererAdaptor.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/result/Templating.java4
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java4
4 files changed, 53 insertions, 65 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/main/java/com/yahoo/prelude/templates/SearchRendererAdaptor.java b/container-search/src/main/java/com/yahoo/prelude/templates/SearchRendererAdaptor.java
index 31e133d22d5..a639a6b97ec 100644
--- a/container-search/src/main/java/com/yahoo/prelude/templates/SearchRendererAdaptor.java
+++ b/container-search/src/main/java/com/yahoo/prelude/templates/SearchRendererAdaptor.java
@@ -21,8 +21,10 @@ import java.util.Iterator;
* Renders a search result using the old templates API.
*
* @author tonytv
+ * @deprecated do not use
*/
@SuppressWarnings({ "rawtypes", "deprecation", "unchecked" })
+@Deprecated // TODO: Remove on Vespa 7
public final class SearchRendererAdaptor extends Renderer {
private final LogExceptionUserTemplateDelegator templates;
diff --git a/container-search/src/main/java/com/yahoo/search/result/Templating.java b/container-search/src/main/java/com/yahoo/search/result/Templating.java
index 47f40f3c7f5..9e191a1219c 100644
--- a/container-search/src/main/java/com/yahoo/search/result/Templating.java
+++ b/container-search/src/main/java/com/yahoo/search/result/Templating.java
@@ -15,8 +15,10 @@ import com.yahoo.search.query.Presentation;
* Helper methods and data store for result attributes geared towards result
* rendering and presentation.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
+ * @deprecated do not use
*/
+@Deprecated // TODO: Remove on Vespa 7
public class Templating {
private final Result result;
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 {