Merge lp:~sergiusens/snapweb/queryPackageNames into lp:~snappy-dev/snapweb/trunk

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 139
Merged at revision: 146
Proposed branch: lp:~sergiusens/snapweb/queryPackageNames
Merge into: lp:~snappy-dev/snapweb/trunk
Diff against target: 100 lines (+25/-16)
2 files modified
snappy/converge.go (+22/-6)
snappy/handlers.go (+3/-10)
To merge this branch: bzr merge lp:~sergiusens/snapweb/queryPackageNames
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
Stephen Stewart (community) Approve
John Lenton Pending
Review via email: mp+258640@code.launchpad.net

This proposal supersedes a proposal from 2015-05-08.

Commit message

Adding support for package name queries (with some polish along the way).

To post a comment you must log in.
139. By Sergio Schvezov

Don't do useless operations when we have the availability of someone else doing it for us.

Revision history for this message
Stephen Stewart (stephen-stewart) wrote :

I see the same results no matter what the query. Have I got the format correct?

http://webdm.local:4200/api/v2/packages/?q=8nzc1x4iim2xj1g2ul64

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Querying for 8nzc1x4iim2xj1g2ul64 as in http://webdm.local:4200/api/v2/packages/?q=8nzc1x4iim2xj1g2ul64 is not the best test subject.

10:18 < nessita> sergiusens, try this https://search.apps.ubuntu.com/api/v1/search?q=%228nzc1x4iim2xj1g2ul64%22
10:18 < nessita> ie, with double quotes, I'll explain why
10:21 < nessita> sergiusens, our package index performs analysis for both the data being indexed, and the search term. The
                 analysis, among other things, try to parse the given string to take out the most relevant part and also search for
                 derivates
10:23 < nessita> sergiusens, using quotes all the time is a bad idea, quotes mean exact match
10:24 < sergiusens> nessita: right, so then beowulf using the strange package name for searching is a bad idea
10:24 < sergiusens> for testing it at least
10:24 < sergiusens> as in eyeball testing
10:25 < nessita> sergiusens, indeed. Ideally, a user will search for keywords, such as "news" and we want to include results for
                 "newspaper" for example

Revision history for this message
Stephen Stewart (stephen-stewart) wrote :

\o/

review: Approve
Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'snappy/converge.go'
--- snappy/converge.go 2015-05-07 16:29:23 +0000
+++ snappy/converge.go 2015-05-08 15:22:57 +0000
@@ -54,8 +54,9 @@
54}54}
5555
56type listFilter struct {56type listFilter struct {
57 Types []string57 types []string
58 InstalledOnly bool58 installedOnly bool
59 query string
59}60}
6061
61// for easier stubbing during testing62// for easier stubbing during testing
@@ -97,24 +98,39 @@
9798
98 typeFilter := func(string) bool { return true }99 typeFilter := func(string) bool { return true }
99100
100 if len(filter.Types) != 0 {101 if len(filter.types) != 0 {
101 regex, err := regexp.Compile("^(?:" + strings.Join(filter.Types, "|") + ")")102 regex, err := regexp.Compile("^(?:" + strings.Join(filter.types, "|") + ")")
102 if err != nil {103 if err != nil {
103 return nil, err104 return nil, err
104 }105 }
105 typeFilter = regex.MatchString106 typeFilter = regex.MatchString
106 }107 }
107108
109 queryFilter := func(string) bool { return true }
110
111 if filter.query != "" {
112 regex, err := regexp.Compile("^(?:" + filter.query + ")")
113 if err != nil {
114 return nil, err
115 }
116 queryFilter = regex.MatchString
117 }
118
108 installedSnapQs := make([]snapPkg, 0, len(installedSnaps))119 installedSnapQs := make([]snapPkg, 0, len(installedSnaps))
109 for i := range installedSnaps {120 for i := range installedSnaps {
110 if !typeFilter(string(installedSnaps[i].Type())) {121 if !typeFilter(string(installedSnaps[i].Type())) {
111 continue122 continue
112 }123 }
124
125 if !queryFilter(installedSnaps[i].Name()) {
126 continue
127 }
128
113 installedSnapQs = append(installedSnapQs, h.snapQueryToPayload(installedSnaps[i]))129 installedSnapQs = append(installedSnapQs, h.snapQueryToPayload(installedSnaps[i]))
114 }130 }
115131
116 mStore := snappy.NewUbuntuStoreSnapRepository()132 mStore := snappy.NewUbuntuStoreSnapRepository()
117 remoteSnaps, err := mStore.Search("*")133 remoteSnaps, err := mStore.Search(filter.query)
118 if err != nil {134 if err != nil {
119 return nil, err135 return nil, err
120 }136 }
@@ -137,7 +153,7 @@
137 }153 }
138 }154 }
139155
140 return mergeSnaps(installedSnapQs, remoteSnapQs, filter.InstalledOnly), nil156 return mergeSnaps(installedSnapQs, remoteSnapQs, filter.installedOnly), nil
141}157}
142158
143func (h *Handler) doRemovePackage(progress *webprogress.WebProgress, ID string) {159func (h *Handler) doRemovePackage(progress *webprogress.WebProgress, ID string) {
144160
=== modified file 'snappy/handlers.go'
--- snappy/handlers.go 2015-05-07 16:29:23 +0000
+++ snappy/handlers.go 2015-05-08 15:22:57 +0000
@@ -20,7 +20,6 @@
20import (20import (
21 "encoding/json"21 "encoding/json"
22 "fmt"22 "fmt"
23 "io"
24 "log"23 "log"
25 "net/http"24 "net/http"
26 "strings"25 "strings"
@@ -54,17 +53,11 @@
54func (h *Handler) getAll(w http.ResponseWriter, r *http.Request) {53func (h *Handler) getAll(w http.ResponseWriter, r *http.Request) {
55 w.Header().Set("Content-Type", "application/json")54 w.Header().Set("Content-Type", "application/json")
56 enc := json.NewEncoder(w)55 enc := json.NewEncoder(w)
57 dec := json.NewDecoder(r.Body)
5856
59 filter := listFilter{57 filter := listFilter{
60 InstalledOnly: installedOnly(r.FormValue("installed_only")),58 installedOnly: installedOnly(r.FormValue("installed_only")),
61 Types: types(r.FormValue("types")),59 types: types(r.FormValue("types")),
62 }60 query: r.FormValue("q"),
63
64 if err := dec.Decode(&filter); err != nil && err != io.EOF {
65 w.WriteHeader(http.StatusInternalServerError)
66 enc.Encode(fmt.Sprintf("Error: %s", err))
67 return
68 }61 }
6962
70 payload, err := h.allPackages(&filter)63 payload, err := h.allPackages(&filter)

Subscribers

People subscribed via source and target branches