diff --git a/README.md b/README.md index 7e2c95a..144e302 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,15 @@ You can run `radium --help` to see the list of available commands. ### Querying from command-line ```bash -radium query "append file" --tag language:go --tag color:yes +radium query "append file" --attr language:go --attr color:yes -radium query dir --tag platform:windows +radium query dir --attr platform:windows radium query go ``` -> `--tag` is not part of radium framework but part of the source -> implementation itself. For example `--tag color:yes` does not +> `--attr` is not part of radium framework but part of the source +> implementation itself. For example `--attr color:yes` does not > work always and works with only results returned by `CheatSh` > source. @@ -46,7 +46,7 @@ curl "localhost:8080/search?q=go" ``` > When using http api, all query parameters except `q` will be -> assumed to be tags +> assumed to be attributes ### Running as Clipboard Monitor diff --git a/cmd/radium/query.go b/cmd/radium/query.go index 53f305f..9b7a941 100644 --- a/cmd/radium/query.go +++ b/cmd/radium/query.go @@ -18,20 +18,20 @@ func newQueryCmd(cfg *config) *cobra.Command { Args: cobra.ExactArgs(1), } - var tags []string - cmd.Flags().StringSliceVarP(&tags, "tag", "t", []string{}, "Tags to narrow the search scope") + var attribs []string + cmd.Flags().StringSliceVarP(&attribs, "attr", "a", []string{}, "Attributes to narrow the search scope") cmd.Run = func(_ *cobra.Command, args []string) { query := radium.Query{} query.Text = args[0] - query.Tags = map[string]string{} + query.Attribs = map[string]string{} - for _, tag := range tags { - parts := strings.Split(tag, ":") + for _, attrib := range attribs { + parts := strings.Split(attrib, ":") if len(parts) == 2 { - query.Tags[parts[0]] = parts[1] + query.Attribs[parts[0]] = parts[1] } else { - fmt.Println("Err: invalid tag format. must be :") + fmt.Println("Err: invalid attrib format. must be :") os.Exit(1) } } diff --git a/models.go b/models.go index 60372a3..c6dc3e3 100644 --- a/models.go +++ b/models.go @@ -21,8 +21,8 @@ type Article struct { // should be one of markdown, json, yaml, html ContentType string `json:"content_type"` - // Tags can contain type of the article, keywords etc. - Tags map[string]string `json:"tags"` + // Attribs can contain type of the article, keywords etc. + Attribs map[string]string `json:"attribs"` // License can contain name of the license if applicable License string `json:"license"` @@ -50,9 +50,9 @@ type Query struct { // use this to find relevant results Text string `json:"text"` - // Tags can be used by sources to further filter down + // Attribs can be used by sources to further filter down // the results - Tags map[string]string `json:"tags"` + Attribs map[string]string `json:"attribs"` } // Validate for empty or invalid queries diff --git a/server.go b/server.go index 054fb43..44059ab 100644 --- a/server.go +++ b/server.go @@ -36,11 +36,11 @@ func (srv Server) handleSearch(wr http.ResponseWriter, req *http.Request) { query := Query{} query.Text = req.FormValue("q") - query.Tags = map[string]string{} + query.Attribs = map[string]string{} for key, val := range req.URL.Query() { if key != "q" && len(val) > 0 { - query.Tags[key] = val[0] + query.Attribs[key] = val[0] } } diff --git a/sources/cheatsh.go b/sources/cheatsh.go index b512198..fd380f3 100644 --- a/sources/cheatsh.go +++ b/sources/cheatsh.go @@ -28,9 +28,9 @@ type CheatSh struct { func (csh CheatSh) Search(query radium.Query) ([]radium.Article, error) { var results []radium.Article - if lang, found := query.Tags["language"]; found { + if lang, found := query.Attribs["language"]; found { color := false - if val, found := query.Tags["color"]; found { + if val, found := query.Attribs["color"]; found { if val == "yes" || val == "true" { color = true } @@ -78,7 +78,7 @@ func (csh CheatSh) makeLangRequest(q string, lang string, color bool) (*radium.A result.Content = string(data) result.ContentType = "plaintext" result.Title = q - result.Tags = map[string]string{ + result.Attribs = map[string]string{ "language": lang, } return result, nil diff --git a/sources/learnxiny.go b/sources/learnxiny.go index 06c7a1f..223a97d 100644 --- a/sources/learnxiny.go +++ b/sources/learnxiny.go @@ -66,7 +66,7 @@ func (lxy LearnXInY) getLanguageMarkdown(language string) (*radium.Article, erro result.Content = string(data) result.ContentType = "markdown" result.Title = language - result.Tags = map[string]string{} + result.Attribs = map[string]string{} result.License = "CC BY-SA 3.0" return result, nil } diff --git a/sources/radium.go b/sources/radium.go index e4d731a..3c9448e 100644 --- a/sources/radium.go +++ b/sources/radium.go @@ -42,7 +42,7 @@ func (rad Radium) Search(query radium.Query) ([]radium.Article, error) { urlQuery.Set("q", query.Text) - for name, val := range query.Tags { + for name, val := range query.Attribs { urlQuery.Set(name, val) } diff --git a/sources/tldr.go b/sources/tldr.go index 8170b2d..353338d 100644 --- a/sources/tldr.go +++ b/sources/tldr.go @@ -30,7 +30,7 @@ func (tldr TLDR) Search(query radium.Query) ([]radium.Article, error) { tool := strings.Replace(query.Text, " ", "-", -1) platform := "common" - if val, found := query.Tags["platform"]; found { + if val, found := query.Attribs["platform"]; found { platform = val } @@ -72,7 +72,7 @@ func (tldr TLDR) getPlatformToolInfo(tool, platform string) (*radium.Article, er result.Content = string(data) result.ContentType = "markdown" result.Title = tool - result.Tags = map[string]string{ + result.Attribs = map[string]string{ "platform": platform, } result.License = "The MIT License (MIT)"