FindByPartial + tests
This commit is contained in:
@@ -124,3 +124,33 @@ func (i Indexer) Delete(t interface{}) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i Indexer) FindByPartial(t interface{}, field string, pattern string) ([]string, error) {
|
||||||
|
typeName := getTypeFQN(t)
|
||||||
|
resultPaths := make([]string, 0)
|
||||||
|
if fields, ok := i.indices[typeName]; ok {
|
||||||
|
for _, idx := range fields.indicesByField[field] {
|
||||||
|
res, err := idx.Search(pattern)
|
||||||
|
if err != nil {
|
||||||
|
if IsNotFoundErr(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultPaths = append(resultPaths, res...)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0, len(resultPaths))
|
||||||
|
for _, v := range resultPaths {
|
||||||
|
result = append(result, path.Base(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -89,6 +89,31 @@ func TestIndexer_DeleteWithNonUniqueIndex(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIndexer_SearchWithNonUniqueIndex(t *testing.T) {
|
||||||
|
dataDir := writeIndexTestData(t, testData, "Id")
|
||||||
|
indexer := NewIndex(&Config{
|
||||||
|
DataDir: dataDir,
|
||||||
|
IndexRootDirName: "index.disk",
|
||||||
|
Log: zerolog.Logger{},
|
||||||
|
})
|
||||||
|
|
||||||
|
indexer.AddNonUniqueIndex(&TestPet{}, "Name", "Id", "pets")
|
||||||
|
|
||||||
|
pet1 := TestPet{Id: "goefe-789", Kind: "Hog", Color: "Green", Name: "Dicky"}
|
||||||
|
pet2 := TestPet{Id: "xadaf-189", Kind: "Hog", Color: "Green", Name: "Ricky"}
|
||||||
|
|
||||||
|
err := indexer.Add(pet1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
err = indexer.Add(pet2)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
res, err := indexer.FindByPartial(pet2, "Name", "*ky")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
t.Log(res)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func TestManagerQueryMultipleIndices(t *testing.T) {
|
func TestManagerQueryMultipleIndices(t *testing.T) {
|
||||||
dataDir := writeIndexTestData(t, testData, "Id")
|
dataDir := writeIndexTestData(t, testData, "Id")
|
||||||
|
|||||||
Reference in New Issue
Block a user