mlangenberg-googlesearch 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/googlesearch.gemspec +2 -2
- data/lib/googlesearch.rb +155 -2
- data/spec/google_search_spec.rb +1 -1
- metadata +2 -1
data/googlesearch.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'googlesearch'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.date = '2009-01-21'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.has_rdoc = false
|
7
7
|
s.summary = 'Google CSE implementation'
|
8
8
|
s.description = 'Abstraction of the Google CSE XML API'
|
9
|
-
s.authors = ["Rene Heino", "Matthijs Langenberg"]
|
9
|
+
s.authors = ["Rene Heino", "Matthijs Langenberg", "Robin Janse"]
|
10
10
|
s.email = 'rails@newminds.nl'
|
11
11
|
s.files = [ "googlesearch.gemspec",
|
12
12
|
"lib/googlesearch.rb",
|
data/lib/googlesearch.rb
CHANGED
@@ -12,7 +12,160 @@ class GoogleSearch
|
|
12
12
|
attr_reader :response
|
13
13
|
|
14
14
|
def initialize(o = {}, search_request = SearchRequest.new)
|
15
|
-
|
15
|
+
|
16
|
+
#o[:as_epq] ||= ""
|
17
|
+
# Optional. The as_epq parameter identifies a phrase that all documents in the search results must contain. You can also use the phrase search query term to search for a phrase.
|
18
|
+
# Examples: as_epq=abraham+lincoln
|
19
|
+
|
20
|
+
|
21
|
+
#o[:as_eq] ||= ""
|
22
|
+
# Optional. The as_eq parameter identifies a word or phrase that should not appear in any documents in the search results. You can also use the exclude query term to ensure that a particular word or phrase will not appear in the documents in a set of search results.
|
23
|
+
# Examples: This example shows a search for the word "bass", where all pages in the search results do not contain the word "music": q=bass&as_eq=music
|
24
|
+
|
25
|
+
|
26
|
+
#o[:as_lq] ||= ""
|
27
|
+
# Optional. The as_lq parameter specifies that all search results should contain a link to a particular URL. You can also use the link: query term for this type of query.
|
28
|
+
# Examples: This example shows a search for pages that link to www.google.com: as_lq=www.google.com
|
29
|
+
|
30
|
+
|
31
|
+
#o[:as_occt] ||= "any"
|
32
|
+
# Specifies where the search engine is to look for the query terms on the page: anywhere on the page, in the title, or in the URL.
|
33
|
+
# any: anywhere on the page
|
34
|
+
# title: in the title of the page
|
35
|
+
# URL: in the URL for the page
|
36
|
+
|
37
|
+
|
38
|
+
#o[:as_sitesearch] ||= "oprey.shop-r.nl"
|
39
|
+
# Limits search results to documents in the specified domain
|
40
|
+
# Example: &as_sitesearch=www.mycompany.com
|
41
|
+
|
42
|
+
|
43
|
+
#o[:entqr] ||= 0
|
44
|
+
# This parameter sets the query expansion policy according to the following valid values:
|
45
|
+
#
|
46
|
+
# 0 -- None
|
47
|
+
# 1 -- Standard
|
48
|
+
# 2 -- Local
|
49
|
+
# 3 -- Full
|
50
|
+
# If this parameter is omitted, the query expansion value specified for the front end is used.
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
#o[:entsp] ||= 0
|
55
|
+
# This parameter controls the use of advanced relevance scoring according to the following valid values:
|
56
|
+
#
|
57
|
+
# 0 -- Standard
|
58
|
+
# a -- Advanced scoring
|
59
|
+
#
|
60
|
+
# Advanced scoring uses the parameters set under Result Biasing. If the value is omitted, the value specified for the front end is used.
|
61
|
+
|
62
|
+
|
63
|
+
#o[:access] ||= "p"
|
64
|
+
# Specifies whether to search public content, secure content, or both.
|
65
|
+
# Possible values for the access parameter are:
|
66
|
+
# p - search only public content
|
67
|
+
# s - search only secure content
|
68
|
+
# a - search all content, both public and secure
|
69
|
+
|
70
|
+
|
71
|
+
#o[:as_dt] ||= "i"
|
72
|
+
# Modifies the as_sitesearch parameter as follows: i: Include, e: Exclude
|
73
|
+
|
74
|
+
|
75
|
+
#o[:as_oq] ||= ""
|
76
|
+
# Optional. The as_oq parameter provides additional search terms to check for in a document, where each document in the search results must contain at least one of the additional search terms. You can also use the Boolean OR query term for this type of query.
|
77
|
+
# Examples: This example shows a search for pages that contain the word "vacation" and either the word "London" or "Paris": q=vacation&as_oq=London+Paris
|
78
|
+
|
79
|
+
|
80
|
+
#o[:as_q] ||= ""
|
81
|
+
# Optional. The as_q parameter provides search terms to check for in a document. This parameter is also commonly used to allow users to specify additional terms to search for within a set of search results.
|
82
|
+
|
83
|
+
|
84
|
+
#o[:as_rq] ||= ""
|
85
|
+
# Optional. The as_rq parameter specifies that all search results should be pages that are related to the specified URL. The parameter value should be a URL. You can also use the related: query term for this type of query.
|
86
|
+
# Examples: This example shows a search for pages that are related to www.google.com: as_rq=www.google.com
|
87
|
+
|
88
|
+
|
89
|
+
#o[:c2off] ||= 0
|
90
|
+
# Optional. The c2coff parameter enables or disables the Simplified and Traditional Chinese Search feature.
|
91
|
+
|
92
|
+
|
93
|
+
o[:client] ||= "google-csbe"
|
94
|
+
# Required!!! The client parameter must be set to google-csbe if you use Google Custom Search Service.
|
95
|
+
|
96
|
+
|
97
|
+
o[:cr] = "lang_#{o[:cr]}" if o[:cr]
|
98
|
+
# Optional. The cr parameter restricts search results to documents originating in a particular country.
|
99
|
+
|
100
|
+
|
101
|
+
o[:cx] ||= ""
|
102
|
+
# Required!!! The cx parameter specifies a unique code that identifies a custom search engine. You must specify a Custom Search Engine using the cx parameter to retrieve search results from that CSE.
|
103
|
+
|
104
|
+
|
105
|
+
#o[:filter] ||= 1
|
106
|
+
# Optional. The filter parameter activates or deactivates the automatic filtering of Google search results. See the Automatic Filtering section of this document for more information about Google's search results filters.
|
107
|
+
|
108
|
+
|
109
|
+
#o[:gl] ||= "nl"
|
110
|
+
# Optional. The gl parameter value is a two-letter country code (uk or nl). For WebSearch results, the gl parameter boosts search results whose country of origin matches the parameter value
|
111
|
+
|
112
|
+
|
113
|
+
#o[:hl] ||= "nl"
|
114
|
+
# Optional. The hl parameter specifies the interface language (host language) of your user interface. To improve the performance and the quality of your search results, you are strongly encouraged to set this parameter explicitly.
|
115
|
+
|
116
|
+
|
117
|
+
#o[:ie] ||= "utf8"
|
118
|
+
# Optional. The ie parameter sets the character encoding scheme that should be used to interpret the query string. The default ie value is latin1.
|
119
|
+
|
120
|
+
o[:lr] = "lang_#{o[:lr]}" if o[:lr]
|
121
|
+
# Optional. The lr (language restrict) parameter restricts search results to documents written in a particular language.
|
122
|
+
|
123
|
+
|
124
|
+
o[:num] ||= 10
|
125
|
+
# Optional. The num parameter identifies the number of search results to return. The default num value is 10, and the maximum value is 20. If you request more than 20 results, only 20 results will be returned.
|
126
|
+
|
127
|
+
|
128
|
+
#o[:numgm] ||= 3
|
129
|
+
# Number of KeyMatch results to return with the results. A value between 0 to 5 can be specified for this option.
|
130
|
+
|
131
|
+
|
132
|
+
#o[:oe] ||= "utf8"
|
133
|
+
# Optional. The oe parameter sets the character encoding scheme that should be used to decode the XML result. The default oe value is latin1.
|
134
|
+
|
135
|
+
o[:output] ||= "xml_no_dtd"
|
136
|
+
# Required. The output parameter specifies the format of the XML results. The only valid values for this parameter are xml and xml_no_dtd. The chart below explains how these parameter values differ.
|
137
|
+
|
138
|
+
|
139
|
+
o[:q] ||= ""
|
140
|
+
# Optional. The q parameter specifies the search query entered by the user. Even though this parameter is optional, you must specify a value for at least one of the query parameters (as_epq, as_lq, as_oq, as_q, as_rq) to get search results.
|
141
|
+
|
142
|
+
|
143
|
+
#o[:safe] ||= "off"
|
144
|
+
# Optional. The safe parameter indicates how search results should be filtered for adult and pornographic content. The default value for the safe parameter is off. Valid parameter values are: off, medium or high
|
145
|
+
|
146
|
+
|
147
|
+
o[:start] ||= 10
|
148
|
+
# Optional. The start parameter indicates the first matching result that should be included in the search results. The start parameter uses a zero-based index, meaning the first result is 0, the second result is 1 and so forth.
|
149
|
+
|
150
|
+
|
151
|
+
#o[:ud] ||= 0
|
152
|
+
#Optional. The ud parameter indicates whether the XML response should include the IDN-encoded URL for the search result. IDN (International Domain Name) encoding allows domains to be displayed using local languages: http://www.花井鮨.com. Valid values for this parameter are 1, meaning the XML result should include IDN-encoded URLs, and 0, meaning the XML result should not include IDN-encoded URLs. The default value for this parameter is 0. If the ud parameter is set to 1, the IDN-encoded URL will appear in the UD tag in your XML results. If the ud parameter is set to 0, the URL in the example above would be displayed as: http://www.xn--elq438j.com.
|
153
|
+
|
154
|
+
|
155
|
+
#o[:getfields] ||= ""
|
156
|
+
# Indicates that the names and values of the specified meta tags should be returned with each search result, when available. See Meta Tags for more information.
|
157
|
+
|
158
|
+
|
159
|
+
#o[:sort] ||= ""
|
160
|
+
# Specifies a sorting method. Results can be sorted by date
|
161
|
+
# http://code.google.com/intl/nl/apis/searchappliance/documentation/52/xml_reference.html#request_sort
|
162
|
+
|
163
|
+
|
164
|
+
# And finally:
|
165
|
+
@response = SearchResponse.new(
|
166
|
+
search_request.get("http://www.google.com/search?" + o.map {|key, value| "#{key}=#{value}"}.join('&')), o[:num], o[:start]
|
167
|
+
)
|
168
|
+
|
16
169
|
end
|
17
170
|
end
|
18
171
|
|
@@ -20,4 +173,4 @@ class SearchRequest
|
|
20
173
|
def get(uri)
|
21
174
|
open(uri)
|
22
175
|
end
|
23
|
-
end
|
176
|
+
end
|
data/spec/google_search_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe GoogleSearch do
|
|
4
4
|
it "should be able to create a search query" do
|
5
5
|
request_mock = mock('request')
|
6
6
|
request_mock.should_receive(:get).with(
|
7
|
-
'http://www.google.com/search
|
7
|
+
'http://www.google.com/search?cx=unique-cse-id&cr=lang_nl&output=xml_no_dtd&q=adres&lr=lang_nl&client=google-csbe&start=0&num=10'
|
8
8
|
).and_return('wat_xml')
|
9
9
|
|
10
10
|
SearchResponse.should_receive(:new).with('wat_xml', 10, 0).and_return('search-response-object')
|
metadata
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mlangenberg-googlesearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rene Heino
|
8
8
|
- Matthijs Langenberg
|
9
|
+
- Robin Janse
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|