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