use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.
the class CollationField method createFields.
@Override
public List<IndexableField> createFields(SchemaField field, Object value) {
if (field.hasDocValues()) {
List<IndexableField> fields = new ArrayList<>();
fields.add(createField(field, value));
final BytesRef bytes = getCollationKey(field.getName(), value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
}
return fields;
} else {
return Collections.singletonList(createField(field, value));
}
}
use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.
the class BasicFunctionalityTest method testTermVectorFields.
@Test
public void testTermVectorFields() {
IndexSchema ischema = IndexSchemaFactory.buildIndexSchema(getSchemaFile(), solrConfig);
// Solr field type
SchemaField f;
// Lucene field
IndexableField luf;
f = ischema.getField("test_basictv");
luf = f.createField("test");
assertTrue(f.storeTermVector());
assertTrue(luf.fieldType().storeTermVectors());
f = ischema.getField("test_notv");
luf = f.createField("test");
assertTrue(!f.storeTermVector());
assertTrue(!luf.fieldType().storeTermVectors());
f = ischema.getField("test_postv");
luf = f.createField("test");
assertTrue(f.storeTermVector() && f.storeTermPositions());
assertTrue(luf.fieldType().storeTermVectorPositions());
f = ischema.getField("test_offtv");
luf = f.createField("test");
assertTrue(f.storeTermVector() && f.storeTermOffsets());
assertTrue(luf.fieldType().storeTermVectorOffsets());
f = ischema.getField("test_posofftv");
luf = f.createField("test");
assertTrue(f.storeTermVector() && f.storeTermPositions() && f.storeTermOffsets());
assertTrue(luf.fieldType().storeTermVectorOffsets() && luf.fieldType().storeTermVectorPositions());
f = ischema.getField("test_posoffpaytv");
luf = f.createField("test");
assertTrue(f.storeTermVector() && f.storeTermPositions() && f.storeTermOffsets() && f.storeTermPayloads());
assertTrue(luf.fieldType().storeTermVectorOffsets() && luf.fieldType().storeTermVectorPositions() && luf.fieldType().storeTermVectorPayloads());
}
use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.
the class BasicFunctionalityTest method testLazyField.
@Test
public void testLazyField() throws IOException {
assertU(adoc("id", "7777", "title", "keyword", "test_hlt", mkstr(10000), "test_hlt", mkstr(20000), "test_hlt", mkstr(30000), "test_hlt", mkstr(40000)));
assertU(commit());
SolrCore core = h.getCore();
// initial request
SolrQueryRequest req = req("q", "id:7777", "fl", "id,title");
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
DocIterator di = dl.iterator();
Document d1 = req.getSearcher().doc(di.nextDoc());
IndexableField[] values1 = null;
// ensure fl field is non lazy, and non-fl field is lazy
assertFalse(d1.getField("title") instanceof LazyDocument.LazyField);
assertFalse(d1.getField("id") instanceof LazyDocument.LazyField);
values1 = d1.getFields("test_hlt");
assertEquals(4, values1.length);
for (int i = 0; i < values1.length; i++) {
assertTrue(values1[i] instanceof LazyDocument.LazyField);
LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i];
assertFalse(f.hasBeenLoaded());
}
req.close();
// followup request, different fl
req = req("q", "id:7777", "fl", "id,test_hlt");
rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
dl = ((ResultContext) rsp.getResponse()).getDocList();
di = dl.iterator();
Document d2 = req.getSearcher().doc(di.nextDoc());
// ensure same doc, same lazy field now
assertTrue("Doc was not cached", d1 == d2);
IndexableField[] values2 = d2.getFields("test_hlt");
assertEquals(values1.length, values2.length);
for (int i = 0; i < values1.length; i++) {
assertSame("LazyField wasn't reused", values1[i], values2[i]);
LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i];
// still not a real boy, no response writer in play
assertFalse(f.hasBeenLoaded());
}
// actuallize one value
assertNotNull(values2[0].stringValue());
for (int i = 0; i < values2.length; i++) {
// now all values for this field should be loaded & cached
LazyDocument.LazyField f = (LazyDocument.LazyField) values2[i];
assertTrue(f.hasBeenLoaded());
}
req.close();
}
use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.
the class DocumentBuilderTest method testMoveLargestLast.
public void testMoveLargestLast() {
SolrInputDocument inDoc = new SolrInputDocument();
// not stored. It won't be moved. This value is the longest, however.
String TEXT_FLD = "text";
inDoc.addField(TEXT_FLD, "NOT STORED|" + RandomStrings.randomAsciiOfLength(random(), 4 * DocumentBuilder.MIN_LENGTH_TO_MOVE_LAST));
// stored, multiValued
String CAT_FLD = "cat";
inDoc.addField(CAT_FLD, "STORED V1|");
// pretty long value
inDoc.addField(CAT_FLD, "STORED V2|" + RandomStrings.randomAsciiOfLength(random(), 2 * DocumentBuilder.MIN_LENGTH_TO_MOVE_LAST));
inDoc.addField(CAT_FLD, "STORED V3|" + RandomStrings.randomAsciiOfLength(random(), DocumentBuilder.MIN_LENGTH_TO_MOVE_LAST));
// stored. This value is long, but not long enough.
String SUBJECT_FLD = "subject";
inDoc.addField(SUBJECT_FLD, "2ndplace|" + RandomStrings.randomAsciiOfLength(random(), DocumentBuilder.MIN_LENGTH_TO_MOVE_LAST));
Document outDoc = DocumentBuilder.toDocument(inDoc, h.getCore().getLatestSchema());
// filter outDoc by stored fields; convert to list.
List<IndexableField> storedFields = StreamSupport.stream(outDoc.spliterator(), false).filter(f -> f.fieldType().stored()).collect(Collectors.toList());
// clip to last 3. We expect these to be for CAT_FLD
storedFields = storedFields.subList(storedFields.size() - 3, storedFields.size());
Iterator<IndexableField> fieldIterator = storedFields.iterator();
IndexableField field;
// Test that we retained the particular value ordering, even though though the 2nd of three was longest
assertTrue(fieldIterator.hasNext());
field = fieldIterator.next();
assertEquals(CAT_FLD, field.name());
assertTrue(field.stringValue().startsWith("STORED V1|"));
assertTrue(fieldIterator.hasNext());
field = fieldIterator.next();
assertEquals(CAT_FLD, field.name());
assertTrue(field.stringValue().startsWith("STORED V2|"));
assertTrue(fieldIterator.hasNext());
field = fieldIterator.next();
assertEquals(CAT_FLD, field.name());
assertTrue(field.stringValue().startsWith("STORED V3|"));
}
use of org.apache.lucene.index.IndexableField in project lucene-solr by apache.
the class LargeFieldTest method assertLazyLoaded.
private void assertLazyLoaded(Document d, String fieldName) {
IndexableField field = d.getField(fieldName);
if (fieldName == BIG_FIELD) {
assertTrue(field instanceof SolrDocumentFetcher.LargeLazyField);
assertTrue(((SolrDocumentFetcher.LargeLazyField) field).hasBeenLoaded());
} else {
assertTrue(field instanceof LazyDocument.LazyField);
assertTrue(((LazyDocument.LazyField) field).hasBeenLoaded());
}
}
Aggregations