diff options
Diffstat (limited to 'modules/indexer/issues/internal/model.go')
-rw-r--r-- | modules/indexer/issues/internal/model.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/indexer/issues/internal/model.go b/modules/indexer/issues/internal/model.go index 31acd16bd4..2de1e0e2bf 100644 --- a/modules/indexer/issues/internal/model.go +++ b/modules/indexer/issues/internal/model.go @@ -56,7 +56,21 @@ type SearchResult struct { Hits []Match } -// SearchOptions represents search options +// SearchOptions represents search options. +// +// It has a slightly different design from database query options. +// In database query options, a field is never a pointer, so it could be confusing when it's zero value: +// Do you want to find data with a field value of 0, or do you not specify the field in the options? +// To avoid this confusion, db introduced db.NoConditionID(-1). +// So zero value means the field is not specified in the search options, and db.NoConditionID means "== 0" or "id NOT IN (SELECT id FROM ...)" +// It's still not ideal, it trapped developers many times. +// And sometimes -1 could be a valid value, like issue ID, negative numbers indicate exclusion. +// Since db.NoConditionID is for "db" (the package name is db), it makes sense not to use it in the indexer: +// Why do bleve/elasticsearch/meilisearch indexers need to know about db.NoConditionID? +// So in SearchOptions, we use pointer for fields which could be not specified, +// and always use the value to filter if it's not nil, even if it's zero or negative. +// It can handle almost all cases, if there is an exception, we can add a new field, like NoLabelOnly. +// Unfortunately, we still use db for the indexer and have to convert between db.NoConditionID and nil for legacy reasons. type SearchOptions struct { Keyword string // keyword to search |