use of com.yahoo.prelude.hitfield.StringFieldPart in project vespa by vespa-engine.
the class JuniperSearcher method addSeparator.
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) {
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);
}
}
use of com.yahoo.prelude.hitfield.StringFieldPart in project vespa by vespa-engine.
the class TokenFieldIteratorTestCase method testTokenIteratorRemove.
@Test
public void testTokenIteratorRemove() {
HitField hf = new HitField("boo", "hei paa deg");
ListIterator<FieldPart> l = hf.tokenIterator();
l.next();
l.next();
l.remove();
l.add(new StringFieldPart("hallo", true));
assertEquals(3, hf.getTokenizedContent().size());
assertEquals("hei hallo deg", hf.getContent());
l.next();
l.previous();
l.previous();
l.remove();
assertEquals("hei deg", hf.getContent());
l.add(new StringFieldPart("paa", true));
assertEquals("hei paa deg", hf.getContent());
}
use of com.yahoo.prelude.hitfield.StringFieldPart in project vespa by vespa-engine.
the class TokenFieldIteratorTestCase method testTokenIteratorAdd.
@Test
public void testTokenIteratorAdd() {
HitField hf = new HitField("boo", "hei paa deg");
assertEquals(3, hf.getTokenizedContent().size());
ListIterator<FieldPart> l = hf.tokenIterator();
l.add(new StringFieldPart("a", true));
l.next();
l.next();
l.add(new StringFieldPart("b", true));
l.next();
l.add(new StringFieldPart("c", true));
assertEquals(false, l.hasNext());
assertEquals("ahei paab degc", hf.getContent());
}
use of com.yahoo.prelude.hitfield.StringFieldPart in project vespa by vespa-engine.
the class JuniperSearcher method insertTags.
private void insertTags(final HitField oldProperty, final boolean bolding, final boolean dynteaser) {
boolean insideHighlight = false;
for (final ListIterator<FieldPart> i = oldProperty.listIterator(); i.hasNext(); ) {
final FieldPart f = i.next();
if (f instanceof SeparatorFieldPart) {
setSeparatorString(bolding, (SeparatorFieldPart) f);
}
if (f.isFinal()) {
continue;
}
final 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);
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;
}
}
if (previous > 0 && previous < toQuote.length()) {
newFieldParts.add(new StringFieldPart(toQuote.substring(previous), f.isToken()));
}
if (newFieldParts != null) {
i.remove();
for (final Iterator<FieldPart> j = newFieldParts.iterator(); j.hasNext(); ) {
i.add(j.next());
}
}
}
}
use of com.yahoo.prelude.hitfield.StringFieldPart in project vespa by vespa-engine.
the class QuotingSearcher method translate.
private List<FieldPart> translate(String toQuote, QuoteTable translations, boolean isToken) {
List<FieldPart> newFieldParts = null;
int lastIdx = 0;
for (int i = 0; i < toQuote.length(); i++) {
String quote = translations.get(toQuote.charAt(i));
if (quote != null) {
if (newFieldParts == null) {
newFieldParts = new ArrayList<>();
}
if (lastIdx != i) {
newFieldParts.add(new StringFieldPart(toQuote.substring(lastIdx, i), isToken));
}
String initContent = Character.toString(toQuote.charAt(i));
newFieldParts.add(new ImmutableFieldPart(initContent, quote, isToken));
lastIdx = i + 1;
}
}
if (lastIdx > 0 && lastIdx < toQuote.length()) {
newFieldParts.add(new StringFieldPart(toQuote.substring(lastIdx), isToken));
}
return newFieldParts;
}
Aggregations