github.com/weaviate/weaviate@v1.24.6/entities/search/result.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package search
    13  
    14  import (
    15  	"github.com/go-openapi/strfmt"
    16  	"github.com/weaviate/weaviate/entities/models"
    17  )
    18  
    19  // Result contains some info of a concept (kind), but not all. For
    20  // additional info the ID can be used to retrieve the full concept from the
    21  // connector storage
    22  type Result struct {
    23  	ID                   strfmt.UUID
    24  	DocID                *uint64
    25  	ClassName            string
    26  	Score                float32
    27  	SecondarySortValue   float32
    28  	ExplainScore         string
    29  	Dist                 float32
    30  	Vector               []float32
    31  	Vectors              models.Vectors
    32  	Beacon               string
    33  	Certainty            float32
    34  	Schema               models.PropertySchema
    35  	Created              int64
    36  	Updated              int64
    37  	AdditionalProperties models.AdditionalProperties
    38  	VectorWeights        map[string]string
    39  	IsConsistent         bool
    40  	Tenant               string
    41  	// Vectors              map[string][]float32
    42  
    43  	// Dimensions in case search was vector-based, 0 otherwise
    44  	Dims int
    45  }
    46  
    47  type Results []Result
    48  
    49  func (r Result) Object() *models.Object {
    50  	return r.ObjectWithVector(true)
    51  }
    52  
    53  func (r Result) ObjectWithVector(includeVector bool) *models.Object {
    54  	schema, ok := r.Schema.(map[string]interface{})
    55  	if ok {
    56  		delete(schema, "id")
    57  	}
    58  
    59  	t := &models.Object{
    60  		Class:              r.ClassName,
    61  		ID:                 r.ID,
    62  		Properties:         schema,
    63  		CreationTimeUnix:   r.Created,
    64  		LastUpdateTimeUnix: r.Updated,
    65  		VectorWeights:      r.VectorWeights,
    66  		Tenant:             r.Tenant,
    67  	}
    68  
    69  	if r.AdditionalProperties != nil {
    70  		t.Additional = r.AdditionalProperties
    71  	}
    72  
    73  	if includeVector {
    74  		t.Vector = r.Vector
    75  		t.Vectors = r.Vectors
    76  	}
    77  
    78  	return t
    79  }
    80  
    81  func (rs Results) Objects() []*models.Object {
    82  	return rs.ObjectsWithVector(true)
    83  }
    84  
    85  func (rs Results) ObjectsWithVector(includeVector bool) []*models.Object {
    86  	objects := make([]*models.Object, len(rs))
    87  	for i, res := range rs {
    88  		objects[i] = res.ObjectWithVector(includeVector)
    89  	}
    90  
    91  	return objects
    92  }