Search in sources :

Example 6 with FieldPart

use of com.yahoo.prelude.hitfield.FieldPart in project vespa by vespa-engine.

the class QuotingSearcher method quoteProperty.

private void quoteProperty(Hit hit, String fieldname, String toQuote, QuoteTable translations) {
    List<FieldPart> l = translate(toQuote, translations, true);
    if (l != null) {
        HitField hf = new HitField(fieldname, toQuote);
        hf.setTokenizedContent(l);
        hit.setField(fieldname, hf);
    }
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) ImmutableFieldPart(com.yahoo.prelude.hitfield.ImmutableFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) HitField(com.yahoo.prelude.hitfield.HitField)

Example 7 with FieldPart

use of com.yahoo.prelude.hitfield.FieldPart 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;
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) ImmutableFieldPart(com.yahoo.prelude.hitfield.ImmutableFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) ImmutableFieldPart(com.yahoo.prelude.hitfield.ImmutableFieldPart)

Example 8 with FieldPart

use of com.yahoo.prelude.hitfield.FieldPart in project vespa by vespa-engine.

the class TokenFieldIteratorTestCase method testTokenIteratorSet.

@Test
public void testTokenIteratorSet() {
    HitField hf = new HitField("boo", "hei paa deg");
    assertEquals(3, hf.getTokenizedContent().size());
    ListIterator<FieldPart> l = hf.tokenIterator();
    l.next();
    l.next();
    l.set(new StringFieldPart("aap", true));
    l.next();
    assertEquals(false, l.hasNext());
    l.previous();
    l.set(new StringFieldPart("ged", true));
    assertEquals("hei aap ged", 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 9 with FieldPart

use of com.yahoo.prelude.hitfield.FieldPart in project vespa by vespa-engine.

the class TokenFieldIteratorTestCase method testTokenIteratorPrevious.

@Test
public void testTokenIteratorPrevious() {
    HitField hf = new HitField("boo", "hei paa");
    ListIterator<?> l = hf.tokenIterator();
    FieldPart p = (FieldPart) l.next();
    assertEquals("hei", p.getContent());
    p = (FieldPart) l.next();
    assertEquals("paa", p.getContent());
    p = (FieldPart) l.previous();
    assertEquals("paa", p.getContent());
    p = (FieldPart) l.previous();
    assertEquals("hei", p.getContent());
}
Also used : FieldPart(com.yahoo.prelude.hitfield.FieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) HitField(com.yahoo.prelude.hitfield.HitField) Test(org.junit.Test)

Aggregations

FieldPart (com.yahoo.prelude.hitfield.FieldPart)9 StringFieldPart (com.yahoo.prelude.hitfield.StringFieldPart)9 HitField (com.yahoo.prelude.hitfield.HitField)6 Test (org.junit.Test)5 BoldCloseFieldPart (com.yahoo.prelude.hitfield.BoldCloseFieldPart)2 BoldOpenFieldPart (com.yahoo.prelude.hitfield.BoldOpenFieldPart)2 ImmutableFieldPart (com.yahoo.prelude.hitfield.ImmutableFieldPart)2 SeparatorFieldPart (com.yahoo.prelude.hitfield.SeparatorFieldPart)2