Skip to content

Commit

Permalink
Merge pull request #30 from knadh/29-search-by-just-tags
Browse files Browse the repository at this point in the history
Allow searching by just tags without having to provide a search query
  • Loading branch information
knadh committed Aug 27, 2023
2 parents f9d58d0 + 4512631 commit ecff92e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 0 additions & 4 deletions cmd/dictpress/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ func getGlossaryWords(lang, initial string, pg paginator.Set, app *App) (*glossa
// validateSearchQuery does basic validation and sanity checks
// on data.Query (useful for params coming from the outside world).
func validateSearchQuery(q data.Query, langs data.LangMap) error {
if q.Query == "" {
return errors.New("empty search query")
}

for _, t := range q.Types {
if _, ok := langs[q.FromLang].Types[t]; !ok {
return fmt.Errorf("unknown type %s", t)
Expand Down
1 change: 1 addition & 0 deletions cmd/dictpress/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func initHTTPServer(app *App, ko *koanf.Koanf) *echo.Echo {
}

// Admin handlers and APIs.
a.GET("/api/entries/:fromLang/:toLang", handleSearch)
a.GET("/api/entries/:fromLang/:toLang/:q", handleSearch)
a.GET("/admin/static/*", echo.WrapHandler(app.fs.FileServer()))
a.GET("/admin", adminPage("index"))
Expand Down
6 changes: 4 additions & 2 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ directMatch AS (
($4 = '' OR lang=$4)
AND (COALESCE(CARDINALITY($5::TEXT[]), 0) = 0 OR tags && $5)
AND (
LOWER(SUBSTRING(content, 0, 50))=LOWER(SUBSTRING($1, 0, 50))
OR tokens @@ PLAINTO_TSQUERY('simple', $1)
CASE WHEN $1 = '' THEN TRUE ELSE
LOWER(SUBSTRING(content, 0, 50))=LOWER(SUBSTRING($1, 0, 50))
OR tokens @@ PLAINTO_TSQUERY('simple', $1)
END
)
AND (CASE WHEN $6 != '' THEN status = $6::entry_status ELSE TRUE END)
),
Expand Down

0 comments on commit ecff92e

Please sign in to comment.