unified-storage: restrict search to title of documents (#111842)
* restrict search to title of documents
This commit is contained in:
@@ -226,6 +226,29 @@ func RunTestSearchAndStorage(t *testing.T, ctx context.Context, backend resource
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, searchResp)
|
||||
require.Nil(t, searchResp.Error)
|
||||
// finding a document by its tag using the query field is not supported anymore, so should return nothing here
|
||||
// https://github.com/grafana/grafana/pull/111842
|
||||
require.Equal(t, int64(0), searchResp.TotalHits)
|
||||
|
||||
// this is the correct way of searching by tag
|
||||
searchResp, err = server.Search(ctx, &resourcepb.ResourceSearchRequest{
|
||||
Options: &resourcepb.ListOptions{
|
||||
Key: &resourcepb.ResourceKey{
|
||||
Group: "test.grafana.app",
|
||||
Resource: "testresources",
|
||||
Namespace: nsPrefix,
|
||||
},
|
||||
Fields: []*resourcepb.Requirement{{
|
||||
Key: "tags",
|
||||
Operator: "=",
|
||||
Values: []string{"hello"},
|
||||
}},
|
||||
},
|
||||
Limit: 10,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, searchResp)
|
||||
require.Nil(t, searchResp.Error)
|
||||
require.Equal(t, int64(3), searchResp.TotalHits)
|
||||
})
|
||||
|
||||
@@ -244,6 +267,29 @@ func RunTestSearchAndStorage(t *testing.T, ctx context.Context, backend resource
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, searchResp)
|
||||
require.Nil(t, searchResp.Error)
|
||||
// finding a document by its tag using the query field is not supported anymore, so should return nothing here
|
||||
// https://github.com/grafana/grafana/pull/111842
|
||||
require.Equal(t, int64(0), searchResp.TotalHits)
|
||||
|
||||
// this is the correct way of searching by tag
|
||||
searchResp, err = server.Search(ctx, &resourcepb.ResourceSearchRequest{
|
||||
Options: &resourcepb.ListOptions{
|
||||
Key: &resourcepb.ResourceKey{
|
||||
Group: "test.grafana.app",
|
||||
Resource: "testresources",
|
||||
Namespace: nsPrefix,
|
||||
},
|
||||
Fields: []*resourcepb.Requirement{{
|
||||
Key: "tags",
|
||||
Operator: "=",
|
||||
Values: []string{"tag1"},
|
||||
}},
|
||||
},
|
||||
Limit: 10,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, searchResp)
|
||||
require.Nil(t, searchResp.Error)
|
||||
require.Equal(t, int64(1), searchResp.TotalHits)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -164,14 +164,18 @@ func runTestResourceIndex(t *testing.T, backend resource.SearchBackend, nsPrefix
|
||||
Group: ns.Group,
|
||||
Resource: ns.Resource,
|
||||
},
|
||||
Fields: []*resourcepb.Requirement{{
|
||||
Key: "tags",
|
||||
Operator: "=",
|
||||
Values: []string{"tag3"},
|
||||
}},
|
||||
},
|
||||
Fields: []string{"title", "folder", "tags"},
|
||||
Query: "tag3",
|
||||
Limit: 10,
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
require.Equal(t, int64(1), resp.TotalHits) // Only doc3 should have tag3 now
|
||||
require.Equal(t, int64(1), resp.TotalHits) // Only doc2 should have tag3 now
|
||||
|
||||
// Search for Document
|
||||
resp, err = index.Search(ctx, nil, &resourcepb.ResourceSearchRequest{
|
||||
|
||||
Reference in New Issue
Block a user