Search in sources :

Example 1 with FieldPart

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);
    }
}
Also used : BoldCloseFieldPart(com.yahoo.prelude.hitfield.BoldCloseFieldPart) SeparatorFieldPart(com.yahoo.prelude.hitfield.SeparatorFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) BoldOpenFieldPart(com.yahoo.prelude.hitfield.BoldOpenFieldPart) FieldPart(com.yahoo.prelude.hitfield.FieldPart) SeparatorFieldPart(com.yahoo.prelude.hitfield.SeparatorFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart)

Example 2 with FieldPart

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());
}
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 FieldPart

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());
}
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 FieldPart

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());
}
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 FieldPart

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());
            }
        }
    }
}
Also used : BoldCloseFieldPart(com.yahoo.prelude.hitfield.BoldCloseFieldPart) SeparatorFieldPart(com.yahoo.prelude.hitfield.SeparatorFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart) BoldOpenFieldPart(com.yahoo.prelude.hitfield.BoldOpenFieldPart) FieldPart(com.yahoo.prelude.hitfield.FieldPart) SeparatorFieldPart(com.yahoo.prelude.hitfield.SeparatorFieldPart) StringFieldPart(com.yahoo.prelude.hitfield.StringFieldPart)

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