Search in sources :

Example 51 with IndexableField

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) TermQuery(org.apache.lucene.search.TermQuery) Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) HashMap(java.util.HashMap) FirstHitCollector(org.neo4j.kernel.api.impl.index.collector.FirstHitCollector) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document)

Example 52 with IndexableField

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"));
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) ArrayList(java.util.ArrayList) StringFieldMapper(org.elasticsearch.index.mapper.core.StringFieldMapper) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 53 with IndexableField

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField)

Example 54 with IndexableField

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) PROJECT(com.google.gerrit.server.index.change.ChangeField.PROJECT) ArrayList(java.util.ArrayList) BytesRef(org.apache.lucene.util.BytesRef)

Example 55 with IndexableField

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);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil)

Aggregations

IndexableField (org.apache.lucene.index.IndexableField)276 Document (org.apache.lucene.document.Document)90 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)75 Matchers.containsString (org.hamcrest.Matchers.containsString)57 BytesRef (org.apache.lucene.util.BytesRef)53 ArrayList (java.util.ArrayList)50 Field (org.apache.lucene.document.Field)34 Test (org.junit.Test)28 IOException (java.io.IOException)27 HashMap (java.util.HashMap)24 IndexReader (org.apache.lucene.index.IndexReader)24 Directory (org.apache.lucene.store.Directory)23 Map (java.util.Map)22 TopDocs (org.apache.lucene.search.TopDocs)22 Term (org.apache.lucene.index.Term)21 HashSet (java.util.HashSet)20 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)20 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)20 Query (org.apache.lucene.search.Query)19 Analyzer (org.apache.lucene.analysis.Analyzer)18