Browse Source

Include freq/norm information when IncludeTermVectors:true

Fixes: https://github.com/blevesearch/bleve/issues/1194
abhinavdangeti 5 months ago
parent
commit
9dcbc5c71a
3 changed files with 50 additions and 2 deletions
  1. 3 1
      search/scorer/scorer_term.go
  2. 1 1
      search/searcher/search_term.go
  3. 46 0
      search_test.go

+ 3 - 1
search/scorer/scorer_term.go

@@ -159,7 +159,9 @@ func (s *TermQueryScorer) Score(ctx *search.SearchContext, termMatch *index.Term
 
 	rv := ctx.DocumentMatchPool.Get()
 	rv.IndexInternalID = append(rv.IndexInternalID, termMatch.ID...)
-	rv.Score = score
+	if s.options.Score != "none" {
+		rv.Score = score
+	}
 	if s.options.Explain {
 		rv.Expl = scoreExplanation
 	}

+ 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.Score != "none"
+	needFreqNorm := options.IncludeTermVectors || options.Score != "none"
 	reader, err := indexReader.TermFieldReader(term, field, needFreqNorm, needFreqNorm, options.IncludeTermVectors)
 	if err != nil {
 		return nil, err

+ 46 - 0
search_test.go

@@ -1548,3 +1548,49 @@ func TestBooleanSearchBug1185(t *testing.T) {
 		t.Fatalf("expected same number of hits, got: %d and %d", len(res.Hits), len(res2.Hits))
 	}
 }
+
+func TestSearchScoreNone(t *testing.T) {
+	idx, err := NewUsing("testidx", NewIndexMapping(), scorch.Name, Config.DefaultKVStore, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	defer func() {
+		err := os.RemoveAll("testidx")
+		if err != nil {
+			t.Fatal(err)
+		}
+	}()
+
+	doc := map[string]interface{}{
+		"field1": "asd fgh jkl",
+		"field2": "more content blah blah",
+		"id":     "doc",
+	}
+
+	if err = idx.Index("doc", doc); err != nil {
+		t.Fatal(err)
+	}
+
+	q := NewQueryStringQuery("content")
+	sr := NewSearchRequest(q)
+	sr.IncludeLocations = true
+	sr.Score = "none"
+
+	res, err := idx.Search(sr)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if len(res.Hits) != 1 {
+		t.Fatal("unexpected number of hits")
+	}
+
+	if len(res.Hits[0].Locations) != 1 {
+		t.Fatal("unexpected locations for the hit")
+	}
+
+	if res.Hits[0].Score != 0 {
+		t.Fatal("unexpected score for the hit")
+	}
+}