Search in sources :

Example 1 with StringFieldPart

use of com.yahoo.prelude.hitfield.StringFieldPart 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 StringFieldPart

use of com.yahoo.prelude.hitfield.StringFieldPart 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 StringFieldPart

use of com.yahoo.prelude.hitfield.StringFieldPart 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 4 with StringFieldPart

use of com.yahoo.prelude.hitfield.StringFieldPart 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)

Example 5 with StringFieldPart

use of com.yahoo.prelude.hitfield.StringFieldPart 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)

Aggregations

StringFieldPart (com.yahoo.prelude.hitfield.StringFieldPart)8 FieldPart (com.yahoo.prelude.hitfield.FieldPart)6 HitField (com.yahoo.prelude.hitfield.HitField)5 Test (org.junit.Test)5 BoldCloseFieldPart (com.yahoo.prelude.hitfield.BoldCloseFieldPart)2 BoldOpenFieldPart (com.yahoo.prelude.hitfield.BoldOpenFieldPart)2 SeparatorFieldPart (com.yahoo.prelude.hitfield.SeparatorFieldPart)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImmutableFieldPart (com.yahoo.prelude.hitfield.ImmutableFieldPart)1