All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qwazr.search.index.ResultDocumentMap Maven / Gradle / Ivy

Go to download

A Search Engine microservice with indexing and search features based on Apache Lucene

There is a newer version: 1.5.2
Show newest version
/*
 * Copyright 2015-2017 Emmanuel Keller / QWAZR
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.qwazr.search.index; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.qwazr.search.field.Converters.ValueConverter; import org.apache.lucene.search.ScoreDoc; import java.io.IOException; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class ResultDocumentMap extends ResultDocumentAbstract { final public LinkedHashMap fields; @JsonCreator public ResultDocumentMap(@JsonProperty("score") Float score, @JsonProperty("pos") Integer pos, @JsonProperty("doc") Integer doc, @JsonProperty("shard_index") Integer shardIndex, @JsonProperty("highlights") Map highlights, @JsonProperty("fields") LinkedHashMap fields) { super(score, pos, doc, shardIndex, highlights); this.fields = fields; } ResultDocumentMap(Builder builder) { super(builder); fields = builder.fields; } public LinkedHashMap getFields() { return fields; } final static class Builder extends ResultDocumentBuilder { private final LinkedHashMap fields; Builder(final int pos, final ScoreDoc scoreDoc) { super(pos, scoreDoc); this.fields = new LinkedHashMap<>(); } @Override final ResultDocumentMap build() { return new ResultDocumentMap(this); } @Override final void setDocValuesField(final String fieldName, final ValueConverter converter) throws IOException { fields.put(fieldName, converter.convert(scoreDoc.doc)); } @Override void setStoredFieldString(String fieldName, List values) { if (values.size() == 1) fields.put(fieldName, values.get(0)); else fields.put(fieldName, values); } @Override void setStoredFieldBytes(String fieldName, List values) { if (values.size() == 1) fields.put(fieldName, values.get(0)); else fields.put(fieldName, values); } @Override void setStoredFieldInteger(String fieldName, int[] values) { if (values.length == 1) fields.put(fieldName, values[0]); else fields.put(fieldName, values); } @Override void setStoredFieldLong(String fieldName, long[] values) { if (values.length == 1) fields.put(fieldName, values[0]); else fields.put(fieldName, values); } @Override void setStoredFieldFloat(String fieldName, float[] values) { if (values.length == 1) fields.put(fieldName, values[0]); else fields.put(fieldName, values); } @Override void setStoredFieldDouble(String fieldName, double[] values) { if (values.length == 1) fields.put(fieldName, values[0]); else fields.put(fieldName, values); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy