77# ' `"google"` (default), `"bing"`, `"duckduckgo"`, `"startpage"`,
88# ' `"stackoverflow"`, `"rstudio community"`, `"github"`, and
99# ' `"bitbucket"`.
10- # ' @param query Contents of string to search. Default is the error message.
11- # ' @param rlang Search for results written in R. Default is `TRUE`
10+ # ' @param query Contents of string to search. Default is the error message.
11+ # ' @param rlang Search for results written in R. Default is `TRUE`
1212# '
1313# ' @return The generated search URL or an empty string.
1414# '
@@ -124,16 +124,23 @@ search_site = function(query,
124124# ' # On error, automatically search the message on google
125125# ' options(error = searcher("google"))
126126# ' }
127- searcher = function (site , rlang = TRUE , keyword = getOption(" searcher.default_keyword" , " base " )) {
127+ searcher = function (site , keyword = getOption(" searcher.default_keyword" )) {
128128
129- check_valid_site (site )
129+ entry = site_details (site )
130130
131- function (query = geterrmessage(), rlang = rlang ) {
132- search_site(query , site , rlang = rlang )
131+ function (query = geterrmessage(), rlang = TRUE ) {
132+
133+ if (! valid_query(query )) {
134+ message(" `query` must contain only 1 element that is not empty." )
135+ return (invisible (" " ))
136+ }
137+
138+ query = append_search_term_suffix(query , rlang , entry [[" keywords" ]][[keyword ]])
139+
140+ browse_url(entry $ site_url , query , entry $ suffix )
133141 }
134142}
135143
136-
137144# ########################## Start Search Engines
138145
139146# ' @rdname search_site
@@ -144,48 +151,21 @@ searcher = function(site, rlang = TRUE, keyword = getOption("searcher.default_ke
144151# '
145152# ' See \url{https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters}
146153# ' for details.
147- search_google = function (query = geterrmessage(), rlang = TRUE ) {
148- if (! valid_query(query )) {
149- message(" Please provide only 1 `query` term that is not empty." )
150- return (invisible (" " ))
151- }
152-
153- query = append_r_suffix(query , rlang = rlang )
154-
155- browse_url(" https://google.com/search?q=" , query )
156- }
154+ search_google = searcher(" google" )
157155
158156# ' @rdname search_site
159157# ' @export
160158# ' @section Bing Search:
161159# ' The `search_bing()` function searches [Bing](https://bing.com) using:
162160# ' `https://bing.com/search?q=<query>`
163- search_bing = function (query = geterrmessage(), rlang = TRUE ) {
164- if (! valid_query(query )) {
165- message(" Please provide only 1 `query` term that is not empty." )
166- return (invisible (" " ))
167- }
168-
169- query = append_r_suffix(query , rlang = rlang )
170-
171- browse_url(" https://bing.com/search?q=" , query )
172- }
161+ search_bing = searcher(" bing" )
173162
174163# ' @rdname search_site
175164# ' @export
176165# ' @section DuckDuckGo Search:
177166# ' The `search_duckduckgo()` and `search_ddg()` functions both search
178167# ' [DuckDuckGo](https://duckduckgo.com) using: `https://duckduckgo.com/?q=<query>`
179- search_duckduckgo = function (query = geterrmessage(), rlang = TRUE ) {
180- if (! valid_query(query )) {
181- message(" Please provide only 1 `query` term that is not empty." )
182- return (invisible (" " ))
183- }
184-
185- query = append_r_suffix(query , rlang = rlang )
186-
187- browse_url(" https://duckduckgo.com/?q=" , query )
188- }
168+ search_duckduckgo = searcher(" ddg" )
189169
190170# ' @rdname search_site
191171# ' @export
@@ -208,16 +188,7 @@ search_ixquick = function(query = geterrmessage(), rlang = TRUE) {
208188# ' For additional details regarding [startpage](https://startpage.com)'s
209189# ' search interface please see:
210190# ' \url{https://support.startpage.com/index.php?/Knowledgebase/Article/View/1261/0/add-familystartpagecom-as-the-default-search-engine-in-chrome}
211- search_startpage = function (query = geterrmessage(), rlang = TRUE ) {
212- if (! valid_query(query )) {
213- message(" Please provide only 1 `query` term that is not empty." )
214- return (invisible (" " ))
215- }
216-
217- query = append_r_suffix(query , rlang = rlang )
218-
219- browse_url(" https://startpage.com/do/dsearch?query=" , query )
220- }
191+ search_startpage = searcher(" sp" )
221192
222193# ' @rdname search_site
223194# ' @export
@@ -238,16 +209,7 @@ search_sp = search_startpage
238209# ' For additional details regarding [StackOverflow](https://stackoverflow.com)'s
239210# ' search interface please see:
240211# ' \url{https://stackoverflow.com/help/advanced-search-parameters-jobs}
241- search_stackoverflow = function (query = geterrmessage(), rlang = TRUE ) {
242- if (! valid_query(query )) {
243- message(" Please provide only 1 `query` term that is not empty." )
244- return (invisible (" " ))
245- }
246-
247- query = append_r_suffix(query , rlang = rlang , " [r]" )
248-
249- browse_url(" https://stackoverflow.com/search?q=" , query )
250- }
212+ search_stackoverflow = searcher(" so" )
251213
252214# ' @rdname search_site
253215# ' @export
@@ -263,17 +225,7 @@ search_so = search_stackoverflow
263225# ' For additional details regarding [RStudio Community](https://community.rstudio.com/)'s
264226# ' search interface please see the [Discourse](https://discourse.org) API documentation:
265227# ' \url{https://docs.discourse.org/#tag/Search}
266- search_rstudio_community = function (query = geterrmessage(), rlang = TRUE ) {
267- if (! valid_query(query )) {
268- message(" Please provide only 1 `query` term that is not empty." )
269- return (invisible (" " ))
270- }
271-
272- # Disable using a query check
273- # query = append_r_suffix(query, rlang = rlang, "[r]")
274-
275- browse_url(" https://community.rstudio.com/search?q=" , query )
276- }
228+ search_rstudio_community = searcher(" rscom" )
277229
278230# ' @rdname search_site
279231# ' @export
@@ -294,16 +246,7 @@ search_rscom = search_rstudio_community
294246# ' search interface please see:
295247# ' \url{https://help.github.com/categories/searching-for-information-on-github/}
296248# ' and \url{https://help.github.com/articles/searching-code/}
297- search_github = function (query = geterrmessage(), rlang = TRUE ) {
298- if (! valid_query(query )) {
299- message(" Please provide only 1 `query` term that is not empty." )
300- return (invisible (" " ))
301- }
302-
303- query = append_r_suffix(query , rlang = rlang , " language:r type:issue" )
304-
305- browse_url(" https://github.com/search?q=" , query , " &type=Issues" )
306- }
249+ search_github = searcher(" gh" )
307250
308251# ' @rdname search_site
309252# ' @export
@@ -319,16 +262,7 @@ search_gh = search_github
319262# ' For additional details regarding [BitBucket](https://bitbucket.com)'s
320263# ' search interface please see:
321264# ' \url{https://confluence.atlassian.com/bitbucket/code-search-in-bitbucket-873876782.html}
322- search_bitbucket = function (query = geterrmessage(), rlang = TRUE ) {
323- if (! valid_query(query )) {
324- message(" Please provide only 1 `query` term that is not empty." )
325- return (invisible (" " ))
326- }
327-
328- query = append_r_suffix(query , rlang = rlang , " lang:r" )
329-
330- browse_url(" https://bitbucket.com/search?q=" , query )
331- }
265+ search_bitbucket = searcher(" bb" )
332266
333267# ' @rdname search_site
334268# ' @export
0 commit comments