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

org.redkalex.source.search.HitResult Maven / Gradle / Ivy

There is a newer version: 2.7.7
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.redkalex.source.search;

import java.util.*;
import org.redkale.util.Attribute;
import org.redkale.util.Utility;

/**
 * @author zhangjx
 * @param  T
 */
public class HitResult extends BaseBean {

    public HitTotal total;

    public Float max_score; // 返回值会有null

    public HitEntity[] hits;

    public List list(final SearchInfo info) {
        List vals = new ArrayList();
        if (Utility.isEmpty(hits)) {
            return vals;
        }
        Attribute highlightAttrId = info.getHighlightAttributeId();
        Attribute highlightAttrIndex = info.getHighlightAttributeIndex();
        for (HitEntity item : hits) {
            T obj = item._source;
            vals.add(obj);
            if (highlightAttrId != null) highlightAttrId.set(obj, item._id);
            if (highlightAttrIndex != null) highlightAttrIndex.set(obj, item._index);
            if (obj != null && item.highlight != null) {
                item.highlight.forEach((t, v) -> {
                    Attribute attr = info.getHighlightAttribute(t);
                    if (attr != null) attr.set(obj, v[0]);
                });
            }
        }
        return vals;
    }

    public static class HitTotal extends BaseBean {

        public int value;

        public String relation;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy