use of com.yahoo.prelude.hitfield.FieldPart 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.FieldPart 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.FieldPart in project vespa by vespa-engine.
the class TokenFieldIteratorTestCase method testTokenIteratorNext.
@Test
public void testTokenIteratorNext() {
HitField hf = new HitField("boo", "hei paa deg");
assertEquals(3, hf.getTokenizedContent().size());
ListIterator<?> l = hf.tokenIterator();
FieldPart p = (FieldPart) l.next();
assertEquals("hei", p.getContent());
p = (FieldPart) l.next();
assertEquals("paa", p.getContent());
p = (FieldPart) l.next();
assertEquals("deg", p.getContent());
assertEquals(false, l.hasNext());
}
use of com.yahoo.prelude.hitfield.FieldPart 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.FieldPart 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());
}
}
}
}
Aggregations