Search in sources :

Example 56 with Document

use of org.apache.lucene.document.Document in project elasticsearch by elastic.

the class GeoFieldDataTests method fillSingleValueAllSet.

@Override
protected void fillSingleValueAllSet() throws Exception {
    Document d = new Document();
    d.add(new StringField("_id", "1", Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    writer.addDocument(d);
    d = new Document();
    d.add(new StringField("_id", "2", Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    writer.addDocument(d);
    d = new Document();
    d.add(new StringField("_id", "3", Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    writer.addDocument(d);
}
Also used : StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document)

Example 57 with Document

use of org.apache.lucene.document.Document in project elasticsearch by elastic.

the class GeoFieldDataTests method fillExtendedMvSet.

@Override
protected void fillExtendedMvSet() throws Exception {
    Document d;
    final int maxDocs = randomInt(10);
    for (int i = 0; i < maxDocs; ++i) {
        d = new Document();
        d.add(new StringField("_id", i + "", Field.Store.NO));
        int maxVals = randomInt(5);
        for (int v = 0; v < maxVals; ++v) {
            d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
        }
        writer.addDocument(d);
        if (randomBoolean()) {
            writer.commit();
        }
    }
}
Also used : StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document)

Example 58 with Document

use of org.apache.lucene.document.Document in project elasticsearch by elastic.

the class GeoFieldDataTests method fillMultiValueWithMissing.

@Override
protected void fillMultiValueWithMissing() throws Exception {
    Document d = new Document();
    d.add(new StringField("_id", "1", Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    writer.addDocument(d);
    // missing
    d = new Document();
    d.add(new StringField("_id", "2", Field.Store.NO));
    writer.addDocument(d);
    d = new Document();
    d.add(new StringField("_id", "3", Field.Store.NO));
    d.add(randomGeoPointField(FIELD_NAME, Field.Store.NO));
    writer.addDocument(d);
}
Also used : StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document)

Example 59 with Document

use of org.apache.lucene.document.Document in project elasticsearch by elastic.

the class IndexFieldDataServiceTests method testFieldDataCacheListener.

public void testFieldDataCacheListener() throws Exception {
    final IndexService indexService = createIndex("test");
    final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    // copy the ifdService since we can set the listener only once.
    final IndexFieldDataService ifdService = new IndexFieldDataService(indexService.getIndexSettings(), indicesService.getIndicesFieldDataCache(), indicesService.getCircuitBreakerService(), indexService.mapperService());
    final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
    final MappedFieldType mapper1 = new TextFieldMapper.Builder("s").fielddata(true).build(ctx).fieldType();
    final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer()));
    Document doc = new Document();
    doc.add(new StringField("s", "thisisastring", Store.NO));
    writer.addDocument(doc);
    DirectoryReader open = DirectoryReader.open(writer);
    final boolean wrap = randomBoolean();
    final IndexReader reader = wrap ? ElasticsearchDirectoryReader.wrap(open, new ShardId("test", "_na_", 1)) : open;
    final AtomicInteger onCacheCalled = new AtomicInteger();
    final AtomicInteger onRemovalCalled = new AtomicInteger();
    ifdService.setListener(new IndexFieldDataCache.Listener() {

        @Override
        public void onCache(ShardId shardId, String fieldName, Accountable ramUsage) {
            if (wrap) {
                assertEquals(new ShardId("test", "_na_", 1), shardId);
            } else {
                assertNull(shardId);
            }
            onCacheCalled.incrementAndGet();
        }

        @Override
        public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) {
            if (wrap) {
                assertEquals(new ShardId("test", "_na_", 1), shardId);
            } else {
                assertNull(shardId);
            }
            onRemovalCalled.incrementAndGet();
        }
    });
    IndexFieldData<?> ifd = ifdService.getForField(mapper1);
    LeafReaderContext leafReaderContext = reader.getContext().leaves().get(0);
    AtomicFieldData load = ifd.load(leafReaderContext);
    assertEquals(1, onCacheCalled.get());
    assertEquals(0, onRemovalCalled.get());
    reader.close();
    load.close();
    writer.close();
    assertEquals(1, onCacheCalled.get());
    assertEquals(1, onRemovalCalled.get());
    ifdService.clear();
}
Also used : IndexService(org.elasticsearch.index.IndexService) Matchers.containsString(org.hamcrest.Matchers.containsString) Document(org.apache.lucene.document.Document) ShardId(org.elasticsearch.index.shard.ShardId) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) ElasticsearchDirectoryReader(org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader) DirectoryReader(org.apache.lucene.index.DirectoryReader) Accountable(org.apache.lucene.util.Accountable) IndicesService(org.elasticsearch.indices.IndicesService) ContentPath(org.elasticsearch.index.mapper.ContentPath) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriter(org.apache.lucene.index.IndexWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringField(org.apache.lucene.document.StringField) IndexReader(org.apache.lucene.index.IndexReader) BuilderContext(org.elasticsearch.index.mapper.Mapper.BuilderContext) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 60 with Document

use of org.apache.lucene.document.Document in project elasticsearch by elastic.

the class AbstractFieldDataTestCase method testEmpty.

public void testEmpty() throws Exception {
    Document d = new Document();
    d.add(new StringField("field", "value", Field.Store.NO));
    writer.addDocument(d);
    refreshReader();
    IndexFieldData fieldData = getForField("non_existing_field");
    int max = randomInt(7);
    for (LeafReaderContext readerContext : readerContexts) {
        AtomicFieldData previous = null;
        for (int i = 0; i < max; i++) {
            AtomicFieldData current = fieldData.load(readerContext);
            assertThat(current.ramBytesUsed(), equalTo(0L));
            if (previous != null) {
                assertThat(current, not(sameInstance(previous)));
            }
            previous = current;
        }
    }
}
Also used : StringField(org.apache.lucene.document.StringField) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Document(org.apache.lucene.document.Document)

Aggregations

Document (org.apache.lucene.document.Document)2344 Directory (org.apache.lucene.store.Directory)1374 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)798 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)752 IndexReader (org.apache.lucene.index.IndexReader)598 Field (org.apache.lucene.document.Field)480 IndexSearcher (org.apache.lucene.search.IndexSearcher)470 Term (org.apache.lucene.index.Term)456 BytesRef (org.apache.lucene.util.BytesRef)415 StringField (org.apache.lucene.document.StringField)403 TextField (org.apache.lucene.document.TextField)389 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)325 IndexWriter (org.apache.lucene.index.IndexWriter)312 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)278 TopDocs (org.apache.lucene.search.TopDocs)270 TermQuery (org.apache.lucene.search.TermQuery)237 FieldType (org.apache.lucene.document.FieldType)231 DirectoryReader (org.apache.lucene.index.DirectoryReader)226 Test (org.junit.Test)222 RAMDirectory (org.apache.lucene.store.RAMDirectory)211