google-site-search 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -7
- data/lib/google-site-search/search.rb +2 -2
- data/lib/google-site-search/version.rb +1 -1
- metadata +31 -17
data/README.rdoc
CHANGED
@@ -47,18 +47,25 @@ Since google only allows a max of 20 returned results I have added a method that
|
|
47
47
|
# has soon as a search doesn't have a next_results_url the method stops.
|
48
48
|
array_of_search_results = GoogleSiteSearch.query_multiple(5, *YOUR_URL*)
|
49
49
|
|
50
|
+
== Caching
|
51
|
+
|
52
|
+
To aid in caching I added a a *caching_key* method which sorts the query parameters, removes some unique parameters that google adds (i.e. an _ie_ parameter which has something to do with related searchs), and compresses the result. It should be a unique representation of a search url, and used to cache results.
|
53
|
+
|
50
54
|
== Blocks (and a caching example)
|
51
55
|
|
52
56
|
Both the query and query_multiple methods can take a block which executes for each Search object found.
|
53
57
|
|
54
|
-
# here is a rails example using
|
58
|
+
# here is a rails example using caching and supplying a block
|
55
59
|
url = GoogleSiteSearch::UrlBuilder.new("microsoft", "00255077836266642015:u-scht7a-8i")
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
|
61
|
+
@search = Rails.cache.fetch(GoogleSiteSearch::caching_key(url.to_s), :expires => 1.day) do |search|
|
62
|
+
GoogleSiteSearch.query(url, SearchResult) do |search|
|
63
|
+
# I can do something with the search objects.
|
64
|
+
# possibly some custom analytics for our searchs?
|
65
|
+
search.url # we can access the object
|
66
|
+
end
|
60
67
|
end
|
61
|
-
|
68
|
+
|
62
69
|
|
63
70
|
== Advanced Usage
|
64
71
|
|
@@ -87,7 +94,7 @@ See
|
|
87
94
|
|
88
95
|
== Pagination
|
89
96
|
|
90
|
-
The google search api does the work of pagination for us, supplying the next and previous urls. The urls are relative paths and contain the search engine id parameter. Since this is a security concern I strip out the search engine id when I store them in the Search.
|
97
|
+
The google search api does the work of pagination for us, supplying the next and previous urls. The urls are relative paths and contain the search engine id parameter. Since this is a security concern I strip out the search engine id when I store them in the Search.next_results_url and Search.previous_results_url methods. This makes them safe to put in links on views and it is why you must supply the search engine id again on the paginate call; so the full url can be rebuilt for the query call.
|
91
98
|
|
92
99
|
search2 = GoogleSiteSearch.query(GoogleSiteSearch.paginate(search1.next_results_url, "00255077836266642015:u-scht7a-8i"))
|
93
100
|
|
@@ -81,7 +81,7 @@ module GoogleSiteSearch
|
|
81
81
|
@previous_results_url = remove_search_engine_id(doc.find_first("RES/NB/PU").try(:content))
|
82
82
|
@search_query = doc.find_first("Q").try(:content)
|
83
83
|
rescue Exception => e
|
84
|
-
raise ParsingError, "#{e.message} URL:[#{@url}] XML:[#{@xml}]"
|
84
|
+
raise ParsingError, "#{e.message} Class:[#{e.class}] URL:[#{@url}] XML:[#{@xml}]"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -90,7 +90,7 @@ module GoogleSiteSearch
|
|
90
90
|
uri = URI.parse(url)
|
91
91
|
params = Rack::Utils::parse_query(uri.query)
|
92
92
|
params.delete("cx")
|
93
|
-
uri.query = params.
|
93
|
+
uri.query = params.to_query
|
94
94
|
uri.to_s
|
95
95
|
end
|
96
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-site-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: libxml-ruby
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rsmaz
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rack
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
description: A gem to aid in the consumption of the google site search service; querys
|
59
79
|
the service, populates a result object and has some related helper methods.
|
60
80
|
email:
|
@@ -92,21 +112,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
112
|
- - ! '>='
|
93
113
|
- !ruby/object:Gem::Version
|
94
114
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: -3596847305660679714
|
98
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
116
|
none: false
|
100
117
|
requirements:
|
101
118
|
- - ! '>='
|
102
119
|
- !ruby/object:Gem::Version
|
103
120
|
version: '0'
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
hash: -3596847305660679714
|
107
121
|
requirements: []
|
108
122
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.23
|
110
124
|
signing_key:
|
111
125
|
specification_version: 3
|
112
126
|
summary: A gem to aid in the consumption of the google site search service; querys
|