-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathsearch.rb
144 lines (137 loc) · 6.52 KB
/
search.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'grape'
require 'grape-entity'
module Srch
class Search < Grape::API
# Endpoint definitions
resource :srch do
# Request URL should be /api/srch/all?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of all available resources', hidden: false,
is_array: false,
nickname: 'srchGetAll'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :all do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_all(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# Request URL should be /api/srch/profiles?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of profiles', hidden: false,
is_array: false,
nickname: 'srchGetProfiles'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :profiles do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_profiles(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# Request URL should be /api/srch/notes?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of research notes', hidden: false,
is_array: false,
nickname: 'srchGetNotes'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :notes do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_notes(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# Request URL should be /api/srch/questions?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of questions tables', hidden: false,
is_array: false,
nickname: 'srchGetQuestions'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :questions do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_questions(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# Request URL should be /api/srch/tags?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of documents associated with tags within the system', hidden: false,
is_array: false,
nickname: 'srchGetByTags'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :tags do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0
sservice = SearchService.new
sresult = sservice.textSearch_tags(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# Request URL should be /api/srch/locations?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Note: Query(QRY as above) must have latitude and longitude as srchString=lat,lon
desc 'Perform a search of documents having nearby latitude and longitude tag values',
hidden: false,
is_array: false,
nickname: 'srchGetLocations'
params do
requires :srchString, type: String, documentation: { example: 'Spec' }
optional :seq, type: Integer, documentation: { example: 995 }
optional :showCount, type: Integer, documentation: { example: 3 }
optional :pageNum, type: Integer, documentation: { example: 0 }
end
get :locations do
sresult = DocList.new
unless params[:srchString].nil? || params[:srchString] == 0 || !(params[:srchString].include? ",")
sservice = SearchService.new
sresult = sservice.nearbyNodes(params[:srchString])
end
sparms = SearchRequest.fromRequest(params)
sresult.srchParams = sparms
sresult
end
# end endpoint definitions
end
end
end