Repository: blevesearch/bleve
Pull request #2019 (2024-04-22 17:16:16)

Fix search cost unit test
- Fix the BytesRead and BytesStored unit tests to pass when using the `vectors` tag. The following commands can be used to validate that all UTs now pass.
    - go test -tags=vectors -race ./...
    - go test -race ./...

CascadingRadium: the test has been failing for many months now ...
mainly its because the SectionVectorIndex is locked under the 
vectors build tag so without the tag only 1 section is there

i am not sure if there is a better way to validate the cost 
other than a hard coded value...

Patch:
diff --git a/search_knn.go b/search_knn.go
index 36f74970..cbeb3b45 100644
--- a/search_knn.go
+++ b/search_knn.go
@@ -30,6 +30,8 @@ import (
 	index "github.com/blevesearch/bleve_index_api"
 )
 
+const supportForVectorSearch = true
+
 type knnOperator string
 
 // Must be updated only at init
diff --git a/search_no_knn.go b/search_no_knn.go
index aff82611..bb72e15a 100644
--- a/search_no_knn.go
+++ b/search_no_knn.go
@@ -28,6 +28,8 @@ import (
 	index "github.com/blevesearch/bleve_index_api"
 )
 
+const supportForVectorSearch = false
+
 // A SearchRequest describes all the parameters
 // needed to search the index.
 // Query is required.


Test patch:
diff --git a/index_test.go b/index_test.go
index c6cc0793..e5094440 100644
--- a/index_test.go
+++ b/index_test.go
@@ -401,9 +401,15 @@ func TestBytesRead(t *testing.T) {
 	}
 	stats, _ := idx.StatsMap()["index"].(map[string]interface{})
 	prevBytesRead, _ := stats["num_bytes_read_at_query_time"].(uint64)
-	if prevBytesRead != 21639 && res.Cost == prevBytesRead {
-		t.Fatalf("expected bytes read for query string 21639, got %v",
-			prevBytesRead)
+
+	expectedBytesRead := uint64(21639)
+	if supportForVectorSearch {
+		expectedBytesRead = 22049
+	}
+
+	if prevBytesRead != expectedBytesRead && res.Cost == prevBytesRead {
+		t.Fatalf("expected bytes read for query string %v, got %v",
+			expectedBytesRead, prevBytesRead)
 	}
 
 	// subsequent queries on the same field results in lesser amount
@@ -553,8 +559,14 @@ func TestBytesReadStored(t *testing.T) {
 
 	stats, _ := idx.StatsMap()["index"].(map[string]interface{})
 	bytesRead, _ := stats["num_bytes_read_at_query_time"].(uint64)
-	if bytesRead != 11501 && bytesRead == res.Cost {
-		t.Fatalf("expected the bytes read stat to be around 11501, got %v", bytesRead)
+
+	expectedBytesRead := uint64(11501)
+	if supportForVectorSearch {
+		expectedBytesRead = 11911
+	}
+
+	if bytesRead != expectedBytesRead && bytesRead == res.Cost {
+		t.Fatalf("expected the bytes read stat to be around %v, got %v", expectedBytesRead, bytesRead)
 	}
 	prevBytesRead := bytesRead
 
@@ -624,8 +636,14 @@ func TestBytesReadStored(t *testing.T) {
 
 	stats, _ = idx1.StatsMap()["index"].(map[string]interface{})
 	bytesRead, _ = stats["num_bytes_read_at_query_time"].(uint64)
-	if bytesRead != 3687 && bytesRead == res.Cost {
-		t.Fatalf("expected the bytes read stat to be around 3687, got %v", bytesRead)
+
+	expectedBytesRead = uint64(3687)
+	if supportForVectorSearch {
+		expectedBytesRead = 4097
+	}
+
+	if bytesRead != expectedBytesRead && bytesRead == res.Cost {
+		t.Fatalf("expected the bytes read stat to be around %v, got %v", expectedBytesRead, bytesRead)
 	}
 	prevBytesRead = bytesRead