use of com.yahoo.prelude.hitfield.HitField in project vespa by vespa-engine.
the class Hit method buildHitField.
public HitField buildHitField(String key, boolean forceNoPreTokenize, boolean forceStringHandling) {
Object o = getField(key);
if (o == null) {
return null;
}
if (o instanceof HitField) {
return (HitField) o;
}
HitField h;
if (forceNoPreTokenize) {
if (o instanceof XMLString && !forceStringHandling) {
h = new HitField(key, (XMLString) o, false);
} else {
h = new HitField(key, o.toString(), false);
}
} else {
if (o instanceof XMLString && !forceStringHandling) {
h = new HitField(key, (XMLString) o);
} else {
h = new HitField(key, o.toString());
}
}
h.setOriginal(o);
getFieldMap().put(key, h);
return h;
}
use of com.yahoo.prelude.hitfield.HitField 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.HitField 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.HitField 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.HitField in project vespa by vespa-engine.
the class HitFieldTestCase method testAnnotateField.
@Test
public void testAnnotateField() {
HitField hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(11, hf.getTokenizedContent().size());
hf = new HitField("boo", "\uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "clude\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(5, hf.getTokenizedContent().size());
hf = new HitField("boo", "\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(5, hf.getTokenizedContent().size());
hf = new HitField("boo", "cludes\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(5, hf.getTokenizedContent().size());
hf = new HitField("boo", "\uFFFB the <hi>Eclipse</hi> Platform");
assertEquals(5, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincl");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFA");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9incl");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9");
assertEquals(6, hf.getTokenizedContent().size());
hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> \uFFF9platform\uFFFAPlatforms\uFFFB test");
assertEquals(12, hf.getTokenizedContent().size());
}
Aggregations