// Path: src/main/java/crate/elasticsearch/action/searchinto/SearchIntoContext.java
// public class SearchIntoContext extends SearchContext {
// 
//     // currently we only support index targets
//     private String targetType = "index";
// 
//     private List<InetSocketTransportAddress> targetNodes;
// 
// 
//     public Map<String, String> outputNames() {
//         return outputNames;
//     }
// 
//     private final Map<String, String> outputNames = new HashMap<String,
//             String>();
// 
//     public SearchIntoContext(long id, ShardSearchRequest request,
//             SearchShardTarget shardTarget, Engine.Searcher engineSearcher,
//             IndexService indexService, IndexShard indexShard,
//             ScriptService scriptService, CacheRecycler cacheRecycler) {
//         super(id, request, shardTarget, engineSearcher, indexService,
//                 indexShard, scriptService, cacheRecycler);
//     }
// 
//     public String targetType() {
//         // this is currently the only type supported
//         return targetType;
//     }
// 
//     public List<InetSocketTransportAddress> targetNodes() {
//         if (targetNodes == null) {
//             targetNodes = Lists.newArrayList();
//         }
//         return targetNodes;
//     }
// 
//     public void emptyTargetNodes() {
//         this.targetNodes = ImmutableList.of();
//     }
// 
// }
// 
// Path: src/main/java/crate/elasticsearch/searchinto/mapping/MappedFields.java
// public class MappedFields {
// 
//     private final SearchIntoContext context;
//     private SearchHit hit;
//     private final List<OutputMapping> outputMappings;
// 
//     public MappedFields(SearchIntoContext context) {
//         this.context = context;
//         this.outputMappings = getOutputMappings();
//     }
// 
//     public void hit(SearchHit hit) {
//         this.hit = hit;
//     }
// 
//     private List<OutputMapping> getOutputMappings() {
//         List<OutputMapping> oms = new ArrayList<OutputMapping>(
//                 context.outputNames().size());
//         boolean indexDefined = false;
//         boolean typeDefined = false;
//         for (Map.Entry<String, String> e : context.outputNames().entrySet()) {
//             String srcName = e.getKey();
//             String trgName = e.getValue();
//             assert (trgName != null);
//             if (trgName.equals("_index")) {
//                 indexDefined = true;
//             } else if (trgName.equals("_type")) {
//                 typeDefined = true;
//             }
//             OutputMapping om = new OutputMapping(srcName, trgName);
//             oms.add(om);
//         }
//         if (!indexDefined) {
//             oms.add(new OutputMapping("_index", "_index"));
//         }
//         if (!typeDefined) {
//             oms.add(new OutputMapping("_type", "_type"));
//         }
// 
//         return oms;
//     }
// 
//     public IndexRequest newIndexRequest() {
//         IndexRequestBuilder builder = new IndexRequestBuilder();
//         for (OutputMapping om : outputMappings) {
//             om.setHit(hit);
//             builder = om.toRequestBuilder(builder);
//         }
//         return builder.build();
// 
//     }
// }


import crate.elasticsearch.action.searchinto.SearchIntoContext;
import crate.elasticsearch.searchinto.mapping.MappedFields;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.text.StringAndBytesText;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor;
import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
import org.elasticsearch.index.fieldvisitor.JustUidFieldsVisitor;
import org.elasticsearch.index.fieldvisitor.UidAndSourceFieldsVisitor;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.fetch.FetchSubPhase;
import org.elasticsearch.search.internal.InternalSearchHit;
import org.elasticsearch.search.internal.InternalSearchHitField;
import java.io.IOException;
import java.util.*;
import static org.elasticsearch.common.collect.Lists.newArrayList;
package crate.elasticsearch.searchinto;




public abstract class WriterCollector extends Collector {

    private List<String> extractFieldNames;
    protected FieldsVisitor fieldsVisitor;
    protected SearchIntoContext context;
// Path: src/main/java/crate/elasticsearch/action/searchinto/SearchIntoContext.java
// public class SearchIntoContext extends SearchContext {
// 
//     // currently we only support index targets
//     private String targetType = "index";
// 
//     private List<InetSocketTransportAddress> targetNodes;
// 
// 
//     public Map<String, String> outputNames() {
//         return outputNames;
//     }
// 
//     private final Map<String, String> outputNames = new HashMap<String,
//             String>();
// 
//     public SearchIntoContext(long id, ShardSearchRequest request,
//             SearchShardTarget shardTarget, Engine.Searcher engineSearcher,
//             IndexService indexService, IndexShard indexShard,
//             ScriptService scriptService, CacheRecycler cacheRecycler) {
//         super(id, request, shardTarget, engineSearcher, indexService,
//                 indexShard, scriptService, cacheRecycler);
//     }
// 
//     public String targetType() {
//         // this is currently the only type supported
//         return targetType;
//     }
// 
//     public List<InetSocketTransportAddress> targetNodes() {
//         if (targetNodes == null) {
//             targetNodes = Lists.newArrayList();
//         }
//         return targetNodes;
//     }
// 
//     public void emptyTargetNodes() {
//         this.targetNodes = ImmutableList.of();
//     }
// 
// }
// 
// Path: src/main/java/crate/elasticsearch/searchinto/mapping/MappedFields.java
// public class MappedFields {
// 
//     private final SearchIntoContext context;
//     private SearchHit hit;
//     private final List<OutputMapping> outputMappings;
// 
//     public MappedFields(SearchIntoContext context) {
//         this.context = context;
//         this.outputMappings = getOutputMappings();
//     }
// 
//     public void hit(SearchHit hit) {
//         this.hit = hit;
//     }
// 
//     private List<OutputMapping> getOutputMappings() {
//         List<OutputMapping> oms = new ArrayList<OutputMapping>(
//                 context.outputNames().size());
//         boolean indexDefined = false;
//         boolean typeDefined = false;
//         for (Map.Entry<String, String> e : context.outputNames().entrySet()) {
//             String srcName = e.getKey();
//             String trgName = e.getValue();
//             assert (trgName != null);
//             if (trgName.equals("_index")) {
//                 indexDefined = true;
//             } else if (trgName.equals("_type")) {
//                 typeDefined = true;
//             }
//             OutputMapping om = new OutputMapping(srcName, trgName);
//             oms.add(om);
//         }
//         if (!indexDefined) {
//             oms.add(new OutputMapping("_index", "_index"));
//         }
//         if (!typeDefined) {
//             oms.add(new OutputMapping("_type", "_type"));
//         }
// 
//         return oms;
//     }
// 
//     public IndexRequest newIndexRequest() {
//         IndexRequestBuilder builder = new IndexRequestBuilder();
//         for (OutputMapping om : outputMappings) {
//             om.setHit(hit);
//             builder = om.toRequestBuilder(builder);
//         }
//         return builder.build();
// 
//     }
// }


// Path: src/main/java/crate/elasticsearch/searchinto/WriterCollector.java
import crate.elasticsearch.action.searchinto.SearchIntoContext;
import crate.elasticsearch.searchinto.mapping.MappedFields;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.text.StringAndBytesText;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor;
import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
import org.elasticsearch.index.fieldvisitor.JustUidFieldsVisitor;
import org.elasticsearch.index.fieldvisitor.UidAndSourceFieldsVisitor;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.fetch.FetchSubPhase;
import org.elasticsearch.search.internal.InternalSearchHit;
import org.elasticsearch.search.internal.InternalSearchHitField;
import java.io.IOException;
import java.util.*;
import static org.elasticsearch.common.collect.Lists.newArrayList;

package crate.elasticsearch.searchinto;




public abstract class WriterCollector extends Collector {

    private List<String> extractFieldNames;
    protected FieldsVisitor fieldsVisitor;
    protected SearchIntoContext context;
    protected MappedFields mappedFields;