func (s *ConjunctionQueryScorer) Score(ctx *search.SearchContext, constituents []*search.DocumentMatch) *search.DocumentMatch { var sum float64 var childrenExplanations []*search.Explanation if s.explain { childrenExplanations = make([]*search.Explanation, len(constituents)) } locations := []search.FieldTermLocationMap{} for i, docMatch := range constituents { sum += docMatch.Score if s.explain { childrenExplanations[i] = docMatch.Expl } if docMatch.Locations != nil { locations = append(locations, docMatch.Locations) } } newScore := sum var newExpl *search.Explanation if s.explain { newExpl = &search.Explanation{Value: sum, Message: "sum of:", Children: childrenExplanations} } // reuse constituents[0] as the return value rv := constituents[0] rv.Score = newScore rv.Expl = newExpl if len(locations) == 1 { rv.Locations = locations[0] } else if len(locations) > 1 { rv.Locations = search.MergeLocations(locations) } return rv }
func (s *ConjunctionQueryScorer) Score(constituents []*search.DocumentMatch) *search.DocumentMatch { rv := search.DocumentMatch{ ID: constituents[0].ID, } var sum float64 var childrenExplanations []*search.Explanation if s.explain { childrenExplanations = make([]*search.Explanation, len(constituents)) } locations := []search.FieldTermLocationMap{} for i, docMatch := range constituents { sum += docMatch.Score if s.explain { childrenExplanations[i] = docMatch.Expl } if docMatch.Locations != nil { locations = append(locations, docMatch.Locations) } } rv.Score = sum if s.explain { rv.Expl = &search.Explanation{Value: sum, Message: "sum of:", Children: childrenExplanations} } if len(locations) == 1 { rv.Locations = locations[0] } else if len(locations) > 1 { rv.Locations = search.MergeLocations(locations) } return &rv }
func (s *DisjunctionQueryScorer) Score(ctx *search.SearchContext, constituents []*search.DocumentMatch, countMatch, countTotal int) *search.DocumentMatch { var sum float64 var childrenExplanations []*search.Explanation if s.explain { childrenExplanations = make([]*search.Explanation, len(constituents)) } locations := []search.FieldTermLocationMap{} for i, docMatch := range constituents { sum += docMatch.Score if s.explain { childrenExplanations[i] = docMatch.Expl } if docMatch.Locations != nil { locations = append(locations, docMatch.Locations) } } var rawExpl *search.Explanation if s.explain { rawExpl = &search.Explanation{Value: sum, Message: "sum of:", Children: childrenExplanations} } coord := float64(countMatch) / float64(countTotal) newScore := sum * coord var newExpl *search.Explanation if s.explain { ce := make([]*search.Explanation, 2) ce[0] = rawExpl ce[1] = &search.Explanation{Value: coord, Message: fmt.Sprintf("coord(%d/%d)", countMatch, countTotal)} newExpl = &search.Explanation{Value: newScore, Message: "product of:", Children: ce} } // reuse constituents[0] as the return value rv := constituents[0] rv.Score = newScore rv.Expl = newExpl if len(locations) == 1 { rv.Locations = locations[0] } else if len(locations) > 1 { rv.Locations = search.MergeLocations(locations) } return rv }