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

View File

@ -27,6 +27,9 @@ gem 'jbuilder', '~> 2.7'
# Authentication gem (uses bcrypt by default) # Authentication gem (uses bcrypt by default)
gem 'devise', '4.7.1' gem 'devise', '4.7.1'
gem 'httparty', '0.18.0'
gem 'faraday', '1.0.1'
# Needed to encrypt passwords with something else than bcrypt # Needed to encrypt passwords with something else than bcrypt
gem 'devise-encryptable', '0.2.0' gem 'devise-encryptable', '0.2.0'

View File

@ -84,10 +84,15 @@ GEM
devise-encryptable (0.2.0) devise-encryptable (0.2.0)
devise (>= 2.1.0) devise (>= 2.1.0)
erubi (1.9.0) erubi (1.9.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.12.2)
ffi (1.12.2-x64-mingw32) ffi (1.12.2-x64-mingw32)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
httparty (0.18.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.2) i18n (1.8.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jbuilder (2.10.0) jbuilder (2.10.0)
@ -100,12 +105,17 @@ GEM
marcel (0.3.3) marcel (0.3.3)
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
method_source (1.0.0) method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
mimemagic (0.3.4) mimemagic (0.3.4)
mini_mime (1.0.2) mini_mime (1.0.2)
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.0) minitest (5.14.0)
msgpack (1.3.3) msgpack (1.3.3)
msgpack (1.3.3-x64-mingw32) msgpack (1.3.3-x64-mingw32)
multi_xml (0.6.0)
multipart-post (2.1.1)
nio4r (2.5.2) nio4r (2.5.2)
nokogiri (1.10.9) nokogiri (1.10.9)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
@ -217,6 +227,8 @@ DEPENDENCIES
capybara (>= 2.15) capybara (>= 2.15)
devise (= 4.7.1) devise (= 4.7.1)
devise-encryptable (= 0.2.0) devise-encryptable (= 0.2.0)
faraday (= 1.0.1)
httparty (= 0.18.0)
jbuilder (~> 2.7) jbuilder (~> 2.7)
puma (~> 4.1) puma (~> 4.1)
rails (= 6.0.2.1) rails (= 6.0.2.1)

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/

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/

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/

View File

@ -1,4 +1,5 @@
class CoursesController < ApplicationController class CoursesController < TissCrawlerController
def index def index
end end
@ -19,4 +20,5 @@ class CoursesController < ApplicationController
def destroy def destroy
end end
end end

View File

@ -1,4 +1,5 @@
class PeopleController < ApplicationController class PeopleController < TissCrawlerController
def index def index
end end
@ -19,4 +20,5 @@ class PeopleController < ApplicationController
def destroy def destroy
end end
end end

View File

@ -1,4 +1,5 @@
class ProjectsController < ApplicationController class ProjectsController < TissCrawlerController
def index def index
end end
@ -19,4 +20,5 @@ class ProjectsController < ApplicationController
def destroy def destroy
end end
end end

View File

@ -1,4 +1,5 @@
class ThesesController < ApplicationController class ThesesController < TissCrawlerController
def index def index
end end
@ -19,4 +20,5 @@ class ThesesController < ApplicationController
def destroy def destroy
end end
end end

View File

@ -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

View File

@ -0,0 +1,2 @@
module TissCrawlerHelper
end

View File

@ -1,2 +0,0 @@
<h1>Login#create</h1>
<p>Find me in app/views/login/create.html.erb</p>

View File

@ -1,2 +0,0 @@
<h1>Login#destroy</h1>
<p>Find me in app/views/login/destroy.html.erb</p>

View File

@ -1,2 +0,0 @@
<h1>Login#edit</h1>
<p>Find me in app/views/login/edit.html.erb</p>

View File

@ -1,2 +1,2 @@
<h1>Login#index</h1> <h1>Successfully logged in</h1>
<p>Find me in app/views/login/index.html.erb</p> <p>Now you can crawl Tiss</p>

View File

@ -1,2 +0,0 @@
<h1>Login#new</h1>
<p>Find me in app/views/login/new.html.erb</p>

View File

@ -1,2 +0,0 @@
<h1>Login#show</h1>
<p>Find me in app/views/login/show.html.erb</p>

View File

@ -1,2 +0,0 @@
<h1>Login#update</h1>
<p>Find me in app/views/login/update.html.erb</p>

View File

@ -1,2 +1,11 @@
<h1>People#index</h1> <h1>People#index</h1>
<p>Find me in app/views/people/index.html.erb</p> <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 %>

View File

@ -0,0 +1 @@
<% render @response %>

View File

@ -36,6 +36,9 @@ Rails.application.routes.draw do
get 'courses/update' get 'courses/update'
get 'courses/destroy' get 'courses/destroy'
get 'login/index' get 'login/index'
get 'tisscrawler/search', :to => 'tiss_crawler#search'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root 'login#index' root 'login#index'
end end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class DetailsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class SearchControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class TissCrawlerControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end