M admin/routes.go => admin/routes.go +1 -1
@@ 64,7 64,7 @@ func (s *Service) Autocomplete(c echo.Context) error {
org := c.QueryParam("org")
items := []Item{}
if org != "" {
- s := links.ParseSearch(org)
+ s := links.ParseSearch(org, true)
opts := &database.FilterOptions{
Filter: sq.And{
sq.Expr(`to_tsvector('simple', o.name || ' ' || o.slug) @@ websearch_to_tsquery('simple', ?)`, s),
M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +7 -7
@@ 40,7 40,7 @@ import (
"golang.org/x/image/draw"
"golang.org/x/net/idna"
"netlandish.com/x/gobwebs"
- "netlandish.com/x/gobwebs-oauth2"
+ oauth2 "netlandish.com/x/gobwebs-oauth2"
gaccounts "netlandish.com/x/gobwebs/accounts"
"netlandish.com/x/gobwebs/crypto"
"netlandish.com/x/gobwebs/database"
@@ 4238,7 4238,7 @@ func (r *queryResolver) GetUsers(ctx context.Context, input *model.GetUserInput)
if input.Search != nil && *input.Search != "" {
// We want to search for partial match
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
opts.Filter = sq.And{
opts.Filter,
sq.Expr(`to_tsvector('simple', u.full_name || ' ' || u.email || ' ' || o.slug)
@@ 4383,7 4383,7 @@ func (r *queryResolver) GetOrganizations(ctx context.Context, input *model.GetOr
// OrderBy: "o.created_on ASC",
//}
if input.Search != nil && *input.Search != "" {
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
opts.Filter = sq.And{
opts.Filter,
sq.Expr(`to_tsvector('simple', o.name || ' ' || o.slug )
@@ 4832,7 4832,7 @@ func (r *queryResolver) GetOrgLinks(ctx context.Context, input *model.GetLinkInp
}
if input.Search != nil && *input.Search != "" {
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
linkOpts.Filter = sq.And{
linkOpts.Filter,
sq.Expr(`to_tsvector('simple', ol.title || ' ' || ol.description || ' ' || ol.url)
@@ 6113,7 6113,7 @@ func (r *queryResolver) GetFeed(ctx context.Context, input *model.GetFeedInput)
}
if input.Search != nil && *input.Search != "" {
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
linkOpts.Filter = sq.And{
linkOpts.Filter,
sq.Expr(`to_tsvector('simple', ol.title || ' ' || ol.description || ' ' || ol.url)
@@ 6255,7 6255,7 @@ func (r *queryResolver) GetAdminOrganizations(ctx context.Context, input *model.
if input.Search != nil && *input.Search != "" {
// We want to search for partial match
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
opts.Filter = sq.And{
opts.Filter,
sq.Expr(`to_tsvector('simple', o.name || ' ' || o.slug )
@@ 6543,7 6543,7 @@ func (r *queryResolver) GetAdminDomains(ctx context.Context, input *model.GetAdm
if input.Search != nil && *input.Search != "" {
// NOTE: full text search (FTS) only support partial prefix search :*
// it does not support preffix based search
- s := links.ParseSearch(*input.Search)
+ s := links.ParseSearch(*input.Search, true)
opts.Filter = sq.And{
opts.Filter,
sq.Or{
M api/loaders/loaders.go => api/loaders/loaders.go +1 -1
@@ 72,7 72,7 @@ func getPopularLinks(ctx context.Context) func(key []string) ([][]*models.BaseUR
}
if q != "" {
- s := links.ParseSearch(q)
+ s := links.ParseSearch(q, true)
opts.Filter = sq.And{
opts.Filter,
sq.Expr(`to_tsvector('simple', b.title || ' ' || b.url)
M core/routes.go => core/routes.go +2 -2
@@ 3271,9 3271,9 @@ func (s *Service) TagAutocomplete(c echo.Context) error {
var tags []*models.Tag
var err error
if q != "" {
- s := links.ParseSearch(q)
+ s := links.ParseSearch(q, false)
opts := &database.FilterOptions{
- Filter: sq.Expr(`to_tsvector('simple', t.name) @@ websearch_to_tsquery('simple', ?)`, s),
+ Filter: sq.Expr(`to_tsvector('simple', t.name) @@ to_tsquery('simple', ?)`, s),
}
if orgID != "" {
opts.Filter = sq.And{
M helpers.go => helpers.go +10 -10
@@ 799,16 799,16 @@ func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []inte
}
// We need to do some parsing to avoid systax error
-// for some string chars
-//
-// Moved search to use websearch_to_tsquery so we shouldn't add any formatting to the search
-// This should probably be removed in the future.
-func ParseSearch(s string) string {
- //s = strings.TrimSpace(s)
- //s = strings.Replace(s, ":", "\\:", -1)
- //return strings.Replace(s, " ", ":* & ", -1) + ":*"
-
- return s
+// for some string chars for non websearch queries
+func ParseSearch(s string, forWeb bool) string {
+ if forWeb {
+ return s
+ }
+
+ // This is used for to_tsquery searches (tag autocomplete)
+ s = strings.TrimSpace(s)
+ s = strings.Replace(s, ":", "\\:", -1)
+ return strings.Replace(s, " ", ":* & ", -1) + ":*"
}
func AddQueryElement(q template.URL, param, val string) template.URL {