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
1=== modified file 'snappy/converge.go'
2--- snappy/converge.go 2015-05-07 16:29:23 +0000
3+++ snappy/converge.go 2015-05-08 15:22:57 +0000
4@@ -54,8 +54,9 @@
5 }
6
7 type listFilter struct {
8- Types []string
9- InstalledOnly bool
10+ types []string
11+ installedOnly bool
12+ query string
13 }
14
15 // for easier stubbing during testing
16@@ -97,24 +98,39 @@
17
18 typeFilter := func(string) bool { return true }
19
20- if len(filter.Types) != 0 {
21- regex, err := regexp.Compile("^(?:" + strings.Join(filter.Types, "|") + ")")
22+ if len(filter.types) != 0 {
23+ regex, err := regexp.Compile("^(?:" + strings.Join(filter.types, "|") + ")")
24 if err != nil {
25 return nil, err
26 }
27 typeFilter = regex.MatchString
28 }
29
30+ queryFilter := func(string) bool { return true }
31+
32+ if filter.query != "" {
33+ regex, err := regexp.Compile("^(?:" + filter.query + ")")
34+ if err != nil {
35+ return nil, err
36+ }
37+ queryFilter = regex.MatchString
38+ }
39+
40 installedSnapQs := make([]snapPkg, 0, len(installedSnaps))
41 for i := range installedSnaps {
42 if !typeFilter(string(installedSnaps[i].Type())) {
43 continue
44 }
45+
46+ if !queryFilter(installedSnaps[i].Name()) {
47+ continue
48+ }
49+
50 installedSnapQs = append(installedSnapQs, h.snapQueryToPayload(installedSnaps[i]))
51 }
52
53 mStore := snappy.NewUbuntuStoreSnapRepository()
54- remoteSnaps, err := mStore.Search("*")
55+ remoteSnaps, err := mStore.Search(filter.query)
56 if err != nil {
57 return nil, err
58 }
59@@ -137,7 +153,7 @@
60 }
61 }
62
63- return mergeSnaps(installedSnapQs, remoteSnapQs, filter.InstalledOnly), nil
64+ return mergeSnaps(installedSnapQs, remoteSnapQs, filter.installedOnly), nil
65 }
66
67 func (h *Handler) doRemovePackage(progress *webprogress.WebProgress, ID string) {
68
69=== modified file 'snappy/handlers.go'
70--- snappy/handlers.go 2015-05-07 16:29:23 +0000
71+++ snappy/handlers.go 2015-05-08 15:22:57 +0000
72@@ -20,7 +20,6 @@
73 import (
74 "encoding/json"
75 "fmt"
76- "io"
77 "log"
78 "net/http"
79 "strings"
80@@ -54,17 +53,11 @@
81 func (h *Handler) getAll(w http.ResponseWriter, r *http.Request) {
82 w.Header().Set("Content-Type", "application/json")
83 enc := json.NewEncoder(w)
84- dec := json.NewDecoder(r.Body)
85
86 filter := listFilter{
87- InstalledOnly: installedOnly(r.FormValue("installed_only")),
88- Types: types(r.FormValue("types")),
89- }
90-
91- if err := dec.Decode(&filter); err != nil && err != io.EOF {
92- w.WriteHeader(http.StatusInternalServerError)
93- enc.Encode(fmt.Sprintf("Error: %s", err))
94- return
95+ installedOnly: installedOnly(r.FormValue("installed_only")),
96+ types: types(r.FormValue("types")),
97+ query: r.FormValue("q"),
98 }
99
100 payload, err := h.allPackages(&filter)

Subscribers

People subscribed via source and target branches