setup abstract search

This commit is contained in:
Marco Zeisler
2020-04-20 18:21:19 +02:00
parent bb0e7b5272
commit e2f0bd7237
24 changed files with 151 additions and 18 deletions
+3
View File
@@ -0,0 +1,3 @@
// Place all the styles related to the details controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
+3
View File
@@ -0,0 +1,3 @@
// Place all the styles related to the search controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
+3
View File
@@ -0,0 +1,3 @@
// Place all the styles related to the tiss_crawler controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
+3 -1
View File
@@ -1,4 +1,5 @@
class CoursesController < ApplicationController
class CoursesController < TissCrawlerController
def index
end
@@ -19,4 +20,5 @@ class CoursesController < ApplicationController
def destroy
end
end
+3 -1
View File
@@ -1,4 +1,5 @@
class PeopleController < ApplicationController
class PeopleController < TissCrawlerController
def index
end
@@ -19,4 +20,5 @@ class PeopleController < ApplicationController
def destroy
end
end
+3 -1
View File
@@ -1,4 +1,5 @@
class ProjectsController < ApplicationController
class ProjectsController < TissCrawlerController
def index
end
@@ -19,4 +20,5 @@ class ProjectsController < ApplicationController
def destroy
end
end
+3 -1
View File
@@ -1,4 +1,5 @@
class ThesesController < ApplicationController
class ThesesController < TissCrawlerController
def index
end
@@ -19,4 +20,5 @@ class ThesesController < ApplicationController
def destroy
end
end
@@ -0,0 +1,77 @@
class TissCrawlerController < ApplicationController
require 'httparty'
$host = 'https://tiss.tuwien.ac.at'
def search
url = _build_search_url(params)
context = _get_context(params)
response = HTTParty.get(url)
case context
when 'People'
_search_people_result(response)
else
flash.now[:alert] = 'Unknown Tiss Crawler Context'
end
end
def _build_search_url(params)
if params[:api].blank?
flash.now[:alert] = 'No api configured!'
return
else
# get the api ... e.g. /'api/person/v22/psuche'
api = params[:api]
end
if params[:search_parameter].blank?
flash.now[:alert] = 'No search_parameter configured!'
return
else
# get the search param ... e.g. 'q'
search_parameter = params[:search_parameter]
end
if params[:search_term].blank?
flash.now[:alert] = 'No search_term configured!'
return
else
# get and parameterize search term q, replace whitespaces with +
search_term = params[:search_term].parameterize(separator: '+')
end
# concat and return the api call url ... e.g. https://tiss.tuwien.ac.at/api/person/v22/psuche?q=max+mustermann
$host + api + '?' + search_parameter + '=' + search_term
end
def _get_context(params)
if params[:context].blank?
flash.now[:alert] = 'No context configured!'
else
# return the context
params[:context]
end
end
def _search_people_result(response)
# redirect_to(controller: 'people', :action => 'show', flash: {response: response})
@response = "Test"
puts('got here', response)
end
def details
end
end
+2
View File
@@ -0,0 +1,2 @@
module TissCrawlerHelper
end
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#create</h1>
<p>Find me in app/views/login/create.html.erb</p>
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#destroy</h1>
<p>Find me in app/views/login/destroy.html.erb</p>
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#edit</h1>
<p>Find me in app/views/login/edit.html.erb</p>
+2 -2
View File
@@ -1,2 +1,2 @@
<h1>Login#index</h1>
<p>Find me in app/views/login/index.html.erb</p>
<h1>Successfully logged in</h1>
<p>Now you can crawl Tiss</p>
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#new</h1>
<p>Find me in app/views/login/new.html.erb</p>
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#show</h1>
<p>Find me in app/views/login/show.html.erb</p>
-2
View File
@@ -1,2 +0,0 @@
<h1>Login#update</h1>
<p>Find me in app/views/login/update.html.erb</p>
+9
View File
@@ -1,2 +1,11 @@
<h1>People#index</h1>
<p>Find me in app/views/people/index.html.erb</p>
<%= form_tag('/tisscrawler/search', :method => "get") do %>
<%= hidden_field_tag(:context, 'People') %>
<%= hidden_field_tag(:api, '/api/person/v22/psuche') %>
<%= hidden_field_tag(:search_parameter, 'q') %>
<%= label_tag(:search_term, "Search for:") %>
<%= text_field_tag(:search_term) %>
<%= submit_tag("Search") %>
<% end %>
+1
View File
@@ -0,0 +1 @@
<% render @response %>