Browse Source

API: renamed SearchRequest.NoScore (bool) to Score (string)

Values for SearchRequest.Score include...

  ""     - basic TF/IDF scoring, and the default behavior.
  "none" - non-scoring search request.
Steve Yen 4 months ago
parent
commit
a1c886716c

+ 1 - 1
index_impl.go

@@ -458,7 +458,7 @@ func (i *indexImpl) SearchInContext(ctx context.Context, req *SearchRequest) (sr
 	searcher, err := req.Query.Searcher(indexReader, i.m, search.SearcherOptions{
 		Explain:            req.Explain,
 		IncludeTermVectors: req.IncludeLocations || req.Highlight != nil,
-		NoScore:            req.NoScore,
+		Score:              req.Score,
 	})
 	if err != nil {
 		return nil, err

+ 4 - 1
search.go

@@ -261,6 +261,7 @@ func (h *HighlightRequest) AddField(field string) {
 // Explain triggers inclusion of additional search
 // result score explanations.
 // Sort describes the desired order for the results to be returned.
+// Score controls the kind of scoring performed
 //
 // A special field named "*" can be used to return all fields.
 type SearchRequest struct {
@@ -273,7 +274,7 @@ type SearchRequest struct {
 	Explain          bool              `json:"explain"`
 	Sort             search.SortOrder  `json:"sort"`
 	IncludeLocations bool              `json:"includeLocations"`
-	NoScore          bool              `json:"noScore"`
+	Score            string            `json:"score,omitempty"`
 }
 
 func (r *SearchRequest) Validate() error {
@@ -323,6 +324,7 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error {
 		Explain          bool              `json:"explain"`
 		Sort             []json.RawMessage `json:"sort"`
 		IncludeLocations bool              `json:"includeLocations"`
+		Score            string            `json:"score"`
 	}
 
 	err := json.Unmarshal(input, &temp)
@@ -349,6 +351,7 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error {
 	r.Fields = temp.Fields
 	r.Facets = temp.Facets
 	r.IncludeLocations = temp.IncludeLocations
+	r.Score = temp.Score
 	r.Query, err = query.ParseQuery(temp.Q)
 	if err != nil {
 		return err

+ 1 - 1
search/search.go

@@ -280,7 +280,7 @@ type Searcher interface {
 type SearcherOptions struct {
 	Explain            bool
 	IncludeTermVectors bool
-	NoScore            bool
+	Score              string
 }
 
 // SearchContext represents the context around a single search

+ 2 - 1
search/searcher/search_conjunction.go

@@ -55,7 +55,8 @@ func NewConjunctionSearcher(indexReader index.IndexReader,
 
 	// attempt the "unadorned" conjunction optimization only when we
 	// do not need extra information like freq-norm's or term vectors
-	if len(searchers) > 1 && options.NoScore && !options.IncludeTermVectors {
+	if len(searchers) > 1 &&
+		options.Score == "none" && !options.IncludeTermVectors {
 		rv, err := optimizeCompositeSearcher("conjunction:unadorned",
 			indexReader, searchers, options)
 		if err != nil || rv != nil {

+ 1 - 1
search/searcher/search_disjunction.go

@@ -44,7 +44,7 @@ func newDisjunctionSearcher(indexReader index.IndexReader,
 	// do not need extra information like freq-norm's or term vectors
 	// and the requested min is simple
 	if len(qsearchers) > 1 && min <= 1 &&
-		options.NoScore && !options.IncludeTermVectors {
+		options.Score == "none" && !options.IncludeTermVectors {
 		rv, err := optimizeCompositeSearcher("disjunction:unadorned",
 			indexReader, qsearchers, options)
 		if err != nil || rv != nil {

+ 1 - 1
search/searcher/search_term.go

@@ -42,7 +42,7 @@ func NewTermSearcher(indexReader index.IndexReader, term string, field string, b
 }
 
 func NewTermSearcherBytes(indexReader index.IndexReader, term []byte, field string, boost float64, options search.SearcherOptions) (*TermSearcher, error) {
-	needFreqNorm := !options.NoScore
+	needFreqNorm := options.Score != "none"
 	reader, err := indexReader.TermFieldReader(term, field, needFreqNorm, needFreqNorm, options.IncludeTermVectors)
 	if err != nil {
 		return nil, err