Search in sources :

Example 1 with HitField

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;
}
Also used : HitField(com.yahoo.prelude.hitfield.HitField) XMLString(com.yahoo.prelude.hitfield.XMLString)

Example 2 with HitField

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());
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) HitField(com.yahoo.prelude.hitfield.HitField) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) Test(org.junit.Test)

Example 3 with HitField

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());
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) HitField(com.yahoo.prelude.hitfield.HitField) Test(org.junit.Test)

Example 4 with HitField

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());
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) HitField(com.yahoo.prelude.hitfield.HitField) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) Test(org.junit.Test)

Example 5 with HitField

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());
}
Also used : HitField(com.yahoo.prelude.hitfield.HitField) Test(org.junit.Test)

Aggregations

HitField (com.yahoo.prelude.hitfield.HitField)12 Test (org.junit.Test)9 StringFieldPart (com.yahoo.prelude.hitfield.StringFieldPart)8 FieldPart (com.yahoo.prelude.hitfield.FieldPart)6 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 ImmutableFieldPart (com.yahoo.prelude.hitfield.ImmutableFieldPart)1 XMLString (com.yahoo.prelude.hitfield.XMLString)1 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)1 QuotingSearcher (com.yahoo.prelude.searcher.QuotingSearcher)1 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 Searcher (com.yahoo.search.Searcher)1 Hit (com.yahoo.search.result.Hit)1 Relevance (com.yahoo.search.result.Relevance)1 HashMap (java.util.HashMap)1