|
|
|
@@ -68,7 +68,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
t.Run("and query is empty, sort documents by title instead of search score", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "bbb",
|
|
|
|
|
"name2": "aaa",
|
|
|
|
@@ -78,7 +78,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("will boost phrase match query over match query results", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "I want to say a hello",
|
|
|
|
|
"name2": "we want hello",
|
|
|
|
@@ -88,7 +88,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("will prioritize matches", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "Asserts Dashboards",
|
|
|
|
|
"name2": "New dashboard 10",
|
|
|
|
@@ -98,7 +98,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("all terms must match", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "Dashboard",
|
|
|
|
|
"name2": "New dashboard 10",
|
|
|
|
@@ -108,7 +108,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("will boost exact match query over match phrase query results", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "we want hello pls",
|
|
|
|
|
"name2": "we want hello",
|
|
|
|
@@ -118,7 +118,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title with numbers will match document", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "A123456",
|
|
|
|
|
})
|
|
|
|
@@ -132,7 +132,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title will match escaped characters", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "what\"s up",
|
|
|
|
|
"name2": "what\"s that",
|
|
|
|
@@ -143,7 +143,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title search will match document", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "I want to say a wonderfully Hello to the WORLD! Hello-world",
|
|
|
|
|
})
|
|
|
|
@@ -166,7 +166,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title search will NOT match documents", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "I want to say a wonderfully Hello to the WORLD! Hello-world",
|
|
|
|
|
"name2": "A0456",
|
|
|
|
@@ -182,7 +182,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title search with character will match one document", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "foo",
|
|
|
|
|
})
|
|
|
|
@@ -202,7 +202,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("title search will ignore terms < 3 characters", func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "new dashboard",
|
|
|
|
|
"name2": "new dash",
|
|
|
|
@@ -224,7 +224,7 @@ func TestCanSearchByTitle(t *testing.T) {
|
|
|
|
|
name = fmt.Sprintf(name, " NOT ")
|
|
|
|
|
}
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, 2, noop, useFullNgram)
|
|
|
|
|
index := newTestDashboardsIndex(t, threshold, 2, noop, useFullNgram)
|
|
|
|
|
indexDocumentsWithTitles(t, index, key, map[string]string{
|
|
|
|
|
"name1": "new dashboard",
|
|
|
|
|
"name2": "new dash",
|
|
|
|
@@ -271,7 +271,7 @@ func newQueryByTitle(query string) *resourcepb.ResourceSearchRequest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newTestDashboardsIndex(t testing.TB, threshold int64, size int64, batchSize int64, writer resource.BuildFn, useFullNgram bool) resource.ResourceIndex {
|
|
|
|
|
func newTestDashboardsIndex(t testing.TB, threshold int64, size int64, writer resource.BuildFn, useFullNgram bool) resource.ResourceIndex {
|
|
|
|
|
key := &resourcepb.ResourceKey{
|
|
|
|
|
Namespace: "default",
|
|
|
|
|
Group: "dashboard.grafana.app",
|
|
|
|
@@ -280,7 +280,6 @@ func newTestDashboardsIndex(t testing.TB, threshold int64, size int64, batchSize
|
|
|
|
|
backend, err := search.NewBleveBackend(search.BleveOptions{
|
|
|
|
|
Root: t.TempDir(),
|
|
|
|
|
FileThreshold: threshold, // use in-memory for tests
|
|
|
|
|
BatchSize: int(batchSize),
|
|
|
|
|
UseFullNgram: useFullNgram,
|
|
|
|
|
}, tracing.NewNoopTracerService(), nil)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|