use of org.apache.lucene.index.IndexableField in project neo4j by neo4j.
the class PartitionedLuceneLabelScanWriter method readLabelBitMapsInRange.
private Map<Long, /*range*/
Bitmap> readLabelBitMapsInRange(IndexSearcher searcher, long range) throws IOException {
Map<Long, Bitmap> /*label*/
fields = new HashMap<>();
Term documentTerm = format.rangeTerm(range);
TermQuery query = new TermQuery(documentTerm);
FirstHitCollector hitCollector = new FirstHitCollector();
searcher.search(query, hitCollector);
if (hitCollector.hasMatched()) {
Document document = searcher.doc(hitCollector.getMatchedDoc());
for (IndexableField field : document.getFields()) {
if (!format.isRangeOrLabelField(field)) {
Long label = Long.valueOf(field.name());
fields.put(label, format.readBitmap(field));
}
}
}
return fields;
}
use of org.apache.lucene.index.IndexableField in project crate by crate.
the class ArrayMapperTest method testCopyToFieldsOfInnerMapping.
@Test
public void testCopyToFieldsOfInnerMapping() throws Exception {
// @formatter:off
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("string_array").field("type", ArrayMapper.CONTENT_TYPE).startObject(ArrayMapper.INNER).field("type", "string").field("index", "analyzed").field("copy_to", "string_array_ft").endObject().endObject().endObject().endObject().endObject().string();
// @formatter:on
DocumentMapper mapper = mapper(INDEX, TYPE, mapping);
FieldMapper arrayMapper = mapper.mappers().getMapper("string_array");
assertThat(arrayMapper, is(instanceOf(ArrayMapper.class)));
assertThat(arrayMapper.copyTo().copyToFields(), contains("string_array_ft"));
// @formatter:on
ParsedDocument doc = mapper.parse(INDEX, TYPE, "1", XContentFactory.jsonBuilder().startObject().startArray("string_array").value("foo").value("bar").endArray().endObject().bytes());
// @formatter:off
List<String> copyValues = new ArrayList<>();
for (IndexableField field : doc.docs().get(0).getFields()) {
if (field.name().equals("string_array_ft")) {
copyValues.add(field.stringValue());
}
}
assertThat(copyValues, containsInAnyOrder("foo", "bar"));
}
use of org.apache.lucene.index.IndexableField in project textdb by TextDB.
the class StorageUtils method getLuceneField.
public static IndexableField getLuceneField(AttributeType attributeType, String attributeName, Object fieldValue) {
IndexableField luceneField = null;
switch(attributeType) {
// _ID_TYPE is currently same as STRING
case _ID_TYPE:
case STRING:
luceneField = new org.apache.lucene.document.StringField(attributeName, (String) fieldValue, Store.YES);
break;
case INTEGER:
luceneField = new org.apache.lucene.document.IntField(attributeName, (Integer) fieldValue, Store.YES);
break;
case DOUBLE:
double value = (Double) fieldValue;
luceneField = new org.apache.lucene.document.DoubleField(attributeName, value, Store.YES);
break;
case DATE:
String dateString = DateTools.dateToString((Date) fieldValue, Resolution.MILLISECOND);
luceneField = new org.apache.lucene.document.StringField(attributeName, dateString, Store.YES);
break;
case TEXT:
// By default we enable positional indexing in Lucene so that we can
// return
// information about character offsets and token offsets
org.apache.lucene.document.FieldType luceneFieldType = new org.apache.lucene.document.FieldType();
luceneFieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
luceneFieldType.setStored(true);
luceneFieldType.setStoreTermVectors(true);
luceneFieldType.setStoreTermVectorOffsets(true);
luceneFieldType.setStoreTermVectorPayloads(true);
luceneFieldType.setStoreTermVectorPositions(true);
luceneFieldType.setTokenized(true);
luceneField = new org.apache.lucene.document.Field(attributeName, (String) fieldValue, luceneFieldType);
break;
case LIST:
// WARNING! This case should never be reached.
break;
}
return luceneField;
}
use of org.apache.lucene.index.IndexableField in project gerrit by GerritCodeReview.
the class LuceneChangeIndex method decodeProtos.
private static <T> List<T> decodeProtos(ListMultimap<String, IndexableField> doc, String fieldName, ProtobufCodec<T> codec) {
Collection<IndexableField> fields = doc.get(fieldName);
if (fields.isEmpty()) {
return Collections.emptyList();
}
List<T> result = new ArrayList<>(fields.size());
for (IndexableField f : fields) {
BytesRef r = f.binaryValue();
result.add(codec.decode(r.bytes, r.offset, r.length));
}
return result;
}
use of org.apache.lucene.index.IndexableField in project gerrit by GerritCodeReview.
the class LuceneChangeIndex method decodeStar.
private void decodeStar(ListMultimap<String, IndexableField> doc, ChangeData cd) {
Collection<IndexableField> star = doc.get(STAR_FIELD);
ListMultimap<Account.Id, String> stars = MultimapBuilder.hashKeys().arrayListValues().build();
for (IndexableField r : star) {
StarredChangesUtil.StarField starField = StarredChangesUtil.StarField.parse(r.stringValue());
if (starField != null) {
stars.put(starField.accountId(), starField.label());
}
}
cd.setStars(stars);
}
Aggregations