2022-07-28 16:58:04 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-07-28 16:58:04 +00:00
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
|
|
|
"xorm.io/builder"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
|
|
|
|
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
|
|
|
|
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
|
2023-03-07 10:51:06 +00:00
|
|
|
if setting.Database.Type.IsSQLite3() {
|
2022-07-28 16:58:04 +00:00
|
|
|
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
|
|
|
|
}
|
|
|
|
return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
|
|
|
|
}
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 06:28:53 +00:00
|
|
|
|
|
|
|
// BuildCaseInsensitiveIn returns a condition to check if the given value is in the given values case-insensitively.
|
|
|
|
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
|
|
|
|
func BuildCaseInsensitiveIn(key string, values []string) builder.Cond {
|
|
|
|
uppers := make([]string, 0, len(values))
|
|
|
|
if setting.Database.Type.IsSQLite3() {
|
|
|
|
for _, value := range values {
|
|
|
|
uppers = append(uppers, util.ToUpperASCII(value))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, value := range values {
|
|
|
|
uppers = append(uppers, strings.ToUpper(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.In("UPPER("+key+")", uppers)
|
|
|
|
}
|