Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search cost unit test #2019

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions search_knn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
index "github.com/blevesearch/bleve_index_api"
)

const supportForVectorSearch = true

type knnOperator string

// Must be updated only at init
Expand Down
2 changes: 2 additions & 0 deletions search_no_knn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading