fix(filters): make "in" filter comparator work with Typesense
This commit is contained in:
parent
d0e3062bee
commit
4f2796ac58
@ -251,6 +251,35 @@ type typesenseTaskSearcher struct {
|
|||||||
s *xorm.Session
|
s *xorm.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertFilterValues(value interface{}) string {
|
||||||
|
if _, is := value.([]interface{}); is {
|
||||||
|
filter := []string{}
|
||||||
|
for _, v := range value.([]interface{}) {
|
||||||
|
filter = append(filter, convertFilterValues(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(filter, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value.(type) {
|
||||||
|
case string:
|
||||||
|
return value.(string)
|
||||||
|
case int:
|
||||||
|
return strconv.Itoa(value.(int))
|
||||||
|
case int64:
|
||||||
|
return strconv.FormatInt(value.(int64), 10)
|
||||||
|
case bool:
|
||||||
|
if value.(bool) {
|
||||||
|
return "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Errorf("Unknown search type for value %v", value)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (t *typesenseTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCount int64, err error) {
|
func (t *typesenseTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCount int64, err error) {
|
||||||
|
|
||||||
var sortbyFields []string
|
var sortbyFields []string
|
||||||
@ -288,17 +317,14 @@ func (t *typesenseTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task,
|
|||||||
|
|
||||||
if f.field == "reminders" {
|
if f.field == "reminders" {
|
||||||
f.field = "reminders.reminder"
|
f.field = "reminders.reminder"
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.field == "assignees" {
|
if f.field == "assignees" {
|
||||||
f.field = "assignees.username"
|
f.field = "assignees.username"
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.field == "labels" || f.field == "label_id" {
|
if f.field == "labels" || f.field == "label_id" {
|
||||||
f.field = "labels.id"
|
f.field = "labels.id"
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filter := f.field
|
filter := f.field
|
||||||
@ -318,29 +344,18 @@ func (t *typesenseTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task,
|
|||||||
filter += ":<="
|
filter += ":<="
|
||||||
case taskFilterComparatorLike:
|
case taskFilterComparatorLike:
|
||||||
filter += ":"
|
filter += ":"
|
||||||
//case taskFilterComparatorIn:
|
case taskFilterComparatorIn:
|
||||||
//filter += "["
|
filter += ":["
|
||||||
case taskFilterComparatorInvalid:
|
case taskFilterComparatorInvalid:
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
default:
|
default:
|
||||||
filter += ":="
|
filter += ":="
|
||||||
}
|
}
|
||||||
|
|
||||||
switch f.value.(type) {
|
filter += convertFilterValues(f.value)
|
||||||
case string:
|
|
||||||
filter += f.value.(string)
|
if f.comparator == taskFilterComparatorIn {
|
||||||
case int:
|
filter += "]"
|
||||||
filter += strconv.Itoa(f.value.(int))
|
|
||||||
case int64:
|
|
||||||
filter += strconv.FormatInt(f.value.(int64), 10)
|
|
||||||
case bool:
|
|
||||||
if f.value.(bool) {
|
|
||||||
filter += "true"
|
|
||||||
} else {
|
|
||||||
filter += "false"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
log.Errorf("Unknown search type %s=%v", f.field, f.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filterBy = append(filterBy, filter)
|
filterBy = append(filterBy, filter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user