infopark_fiona_connector 6.8.0.beta.200.891.647580e
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/README +5 -0
- data/lib/comment.rb +4 -0
- data/lib/infopark_fiona_connector.rb +23 -0
- data/lib/rails_connector/attr_dict.rb +146 -0
- data/lib/rails_connector/attr_value_provider.bundle +0 -0
- data/lib/rails_connector/attr_value_provider.so +0 -0
- data/lib/rails_connector/attr_value_provider64.so +0 -0
- data/lib/rails_connector/attr_value_provider_loader.rb +11 -0
- data/lib/rails_connector/blob.rb +67 -0
- data/lib/rails_connector/blob_mysql.rb +42 -0
- data/lib/rails_connector/blob_oracle.rb +39 -0
- data/lib/rails_connector/cache_middleware.rb +13 -0
- data/lib/rails_connector/cms_base_model.rb +45 -0
- data/lib/rails_connector/date_attribute.rb +28 -0
- data/lib/rails_connector/default_search_request.rb +6 -0
- data/lib/rails_connector/errors.rb +8 -0
- data/lib/rails_connector/link.rb +135 -0
- data/lib/rails_connector/lucene_search_request.rb +107 -0
- data/lib/rails_connector/named_link.rb +76 -0
- data/lib/rails_connector/news.rb +16 -0
- data/lib/rails_connector/obj.rb +517 -0
- data/lib/rails_connector/permission.rb +41 -0
- data/lib/rails_connector/rack_middlewares.rb +6 -0
- data/lib/rails_connector/ses/verity_accessor.rb +130 -0
- data/lib/rails_connector/verity_search_request.rb +84 -0
- data/lib/rating.rb +2 -0
- metadata +149 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
# The permissions assigned to an Obj.
|
4
|
+
class Permission < CmsBaseModel
|
5
|
+
belongs_to :object, :class_name => 'Obj', :foreign_key => 'object_id'
|
6
|
+
|
7
|
+
# Returns the Array of the names of the user groups to which read permission has been granted.
|
8
|
+
def self.read
|
9
|
+
user_groups_for_permission_type(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns the Array of the names of the user groups to which write permission has been granted
|
13
|
+
def self.write
|
14
|
+
user_groups_for_permission_type(2)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the Array of the names of the user groups to which root permission has been granted
|
18
|
+
def self.root
|
19
|
+
user_groups_for_permission_type(3)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the Array of the names of the user groups to which the children creation permission has been granted.
|
23
|
+
def self.create_children
|
24
|
+
user_groups_for_permission_type(4)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the Array of the names of the user groups to which live read permission has been granted.
|
28
|
+
def self.live
|
29
|
+
user_groups_for_permission_type(5)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.user_groups_for_permission_type(permission_type)
|
35
|
+
# Field name "user_login" is a legacy from CM tables.
|
36
|
+
# Actually the field contains the user group.
|
37
|
+
select(:user_login).where(:permission_type => permission_type).map(&:user_login)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require "builder"
|
2
|
+
|
3
|
+
module RailsConnector
|
4
|
+
|
5
|
+
module SES
|
6
|
+
|
7
|
+
class VerityAccessor # :nodoc:
|
8
|
+
require 'net/http'
|
9
|
+
require 'uri'
|
10
|
+
require "rexml/document"
|
11
|
+
|
12
|
+
#--
|
13
|
+
# Options: see VeritySearchRequest
|
14
|
+
#++
|
15
|
+
def initialize(query, options = {})
|
16
|
+
@query = query
|
17
|
+
@options = {
|
18
|
+
:host => 'localhost',
|
19
|
+
:port => 3011,
|
20
|
+
:offset => 0,
|
21
|
+
:limit => 10,
|
22
|
+
:min_relevance => 50,
|
23
|
+
:max_docs => 'unlimited',
|
24
|
+
:parser => 'simple',
|
25
|
+
:sort_order => [["score", "desc"], ["name", "asc"]],
|
26
|
+
:collections => ['cm-contents'],
|
27
|
+
:base_query => nil
|
28
|
+
}.merge(options)
|
29
|
+
@options[:collections] = options[:collection].to_a.flatten if options.has_key?(:collection)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Queries the SES and returns a SearchResult.
|
33
|
+
#
|
34
|
+
# Exceptions:
|
35
|
+
# * SearchError - SES reported an error.
|
36
|
+
#
|
37
|
+
def search
|
38
|
+
parse_response_payload(send_to_ses(build_request_payload))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def build_request_payload
|
44
|
+
x = Builder::XmlMarkup.new
|
45
|
+
x.instruct!
|
46
|
+
x.tag!('ses-payload', 'payload-id' => 'd-1f6a64dec16aa328-00000020-i', 'timestamp' => Time.now.to_iso, 'version' => '6') {
|
47
|
+
x.tag!('ses-header') {
|
48
|
+
x.tag!('ses-sender', 'sender-id' => '42', 'name' => 'infopark-rails-connector')
|
49
|
+
}
|
50
|
+
x.tag!('ses-request', 'request-id' => 'd-1f6a64dec16aa328-00000021-j-1', 'preclusive' => 'false') {
|
51
|
+
x.tag!('ses-search') {
|
52
|
+
x.query @query, :parser => @options[:parser]
|
53
|
+
x.resultRecord {
|
54
|
+
x.resultField 'objId'
|
55
|
+
x.resultField 'score'
|
56
|
+
}
|
57
|
+
x.offset {
|
58
|
+
x.start @options[:offset].to_i + 1
|
59
|
+
x.length @options[:limit]
|
60
|
+
}
|
61
|
+
x.minRelevance @options[:min_relevance]
|
62
|
+
x.maxDocs @options[:max_docs]
|
63
|
+
|
64
|
+
unless @options[:sort_order].blank?
|
65
|
+
x.sortOrder {
|
66
|
+
@options[:sort_order].each do |attribute, direction|
|
67
|
+
x.sortField attribute, :direction => direction
|
68
|
+
end
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
x.searchBase {
|
73
|
+
@options[:collections].each {|item| x.collection item }
|
74
|
+
x.query @options[:base_query], :parser => @options[:parser] if @options[:base_query]
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def send_to_ses(payload)
|
82
|
+
res = Net::HTTP.new(@options[:host], @options[:port].to_i).start do |http|
|
83
|
+
req = Net::HTTP::Post.new('/xml')
|
84
|
+
req.body = payload
|
85
|
+
http.request(req)
|
86
|
+
end
|
87
|
+
res.body
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_response_payload(response)
|
91
|
+
xml = REXML::Document.new(response)
|
92
|
+
if xml.elements['/ses-payload/ses-response/ses-code'].attributes['numeric'] == "200"
|
93
|
+
build_successful_result(xml)
|
94
|
+
else
|
95
|
+
handle_error(xml)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def build_successful_result(response)
|
100
|
+
result = SearchResult.new(response.elements['/ses-payload/ses-response/ses-code/searchResults'].attributes['hits'].to_i)
|
101
|
+
response.elements.to_a('/ses-payload/ses-response/ses-code/searchResults/record').each do |record|
|
102
|
+
hit = Hit.new(record.elements['objId'].text.to_i, record.elements['score'].text.to_f)
|
103
|
+
if hit.obj.present?
|
104
|
+
result << hit
|
105
|
+
else
|
106
|
+
Rails.logger.warn("OBJ with ID ##{record.elements['objId'].text.to_i} not found: This search result will not be shown")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
result
|
110
|
+
end
|
111
|
+
|
112
|
+
# SES raises these errors:
|
113
|
+
# 100171: ERROR_SYSTEM_SES_INTERNALVERITYERROR_DS
|
114
|
+
# 100230: ERROR_SYSTEM_SES_VERITYERROR_DS
|
115
|
+
# 100099: ERROR_SYSTEM_SES_DUPLICATECOLLETION_S
|
116
|
+
# 100173: ERROR_SYSTEM_SES_OPENCOLLECTIONFAILED
|
117
|
+
# 100103: ERROR_SYSTEM_SEARCHENGINE_SESSIONNEWFAILED
|
118
|
+
# 100177: ERROR_SYSTEM_SEARCHENGINE_BULKSUBMITFAILED
|
119
|
+
def handle_error(response)
|
120
|
+
msg = ""
|
121
|
+
response.elements.each('/ses-payload/ses-response/ses-code/errorStack/error') do |error|
|
122
|
+
msg << error.elements['phrase'].text
|
123
|
+
msg << "\n"
|
124
|
+
end
|
125
|
+
raise SearchError, msg
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
# This class provides an implementation for accessing the Verity based search server.
|
4
|
+
# It should be customized by subclassing.
|
5
|
+
class VeritySearchRequest
|
6
|
+
attr_reader :query_string
|
7
|
+
|
8
|
+
# Sanitizes the given +query_string+ and takes +options+ for accessing the SES.
|
9
|
+
#
|
10
|
+
# +query_string+ is a VQL search query.
|
11
|
+
# +options+ is a hash and may be used to tweek the query.
|
12
|
+
#
|
13
|
+
# Options:
|
14
|
+
# <tt>:host</tt>:: The SES server host, default: <tt>'localhost'</tt>
|
15
|
+
# <tt>:port</tt>:: The SES server port, default: <tt>3011</tt>
|
16
|
+
# <tt>:offset</tt>:: The search offset, default: <tt>0</tt>
|
17
|
+
# <tt>:limit</tt>:: The maximum number of hits in the SearchResult, default: <tt>10</tt>
|
18
|
+
# <tt>:min_relevance</tt>:: The minimum relevance in percent, default: <tt>50</tt>
|
19
|
+
# <tt>:max_docs</tt>:: The maximum number of documents to be searched, default: <tt>'unlimited'</tt>
|
20
|
+
# <tt>:parser</tt>:: The VQL query parser to be used, default: <tt>'simple'</tt>
|
21
|
+
# <tt>:sort_order</tt>:: The sort order of the hits, a list of key-value pairs, each consisting of the sortkey and the sort direction ("asc"=ascending, "desc"=descending), default: <tt>[["score", "desc"], ["name", "asc"]]</tt>
|
22
|
+
# <tt>:collections</tt>:: The collections to be searched, default: <tt>['cm-contents']</tt>
|
23
|
+
# <tt>:base_query</tt>:: The VQL base query, default: <tt>nil</tt>
|
24
|
+
def initialize(query_string, options=nil)
|
25
|
+
@query_string = self.class.sanitize(query_string)
|
26
|
+
@options = Configuration.search_options.merge(options || {})
|
27
|
+
end
|
28
|
+
|
29
|
+
# Accesses the SES and fetches search hits.
|
30
|
+
#
|
31
|
+
# Uses the #base_query and +options+ given in #new.
|
32
|
+
def fetch_hits
|
33
|
+
SES::VerityAccessor.new(vql_query_for(@query_string), {:base_query => base_query}.merge(@options)).search
|
34
|
+
end
|
35
|
+
|
36
|
+
# Removes unwanted characters from +text+.
|
37
|
+
def self.sanitize(text) #:nodoc:
|
38
|
+
text.strip.gsub(/[<>"'´`,()\[\]{}=!@\\]/, '')
|
39
|
+
end
|
40
|
+
|
41
|
+
def vql_query_for(query_string = '')
|
42
|
+
words = query_string.split(/\s+/).map do |word|
|
43
|
+
word unless %w(and or not).include?(word.downcase)
|
44
|
+
end.compact.join(", ")
|
45
|
+
"<#AND> (#{words})"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Combines base query conditions to a single base query (see #base_query_conditions).
|
49
|
+
#
|
50
|
+
# A base query is used to reduce the number of documents before executing the actual query.
|
51
|
+
# By default, all base query conditions must be met, they are combined using the +AND+ operator.
|
52
|
+
def base_query
|
53
|
+
"<#AND> (#{base_query_conditions.values.compact.join(', ')})"
|
54
|
+
end
|
55
|
+
|
56
|
+
# A hash of conditions, combined to a base query by #base_query.
|
57
|
+
# Note that all values of the hash must be valid VQL syntax.
|
58
|
+
# The keys have no meaning and exist only so single conditions can be replaced
|
59
|
+
# in a subclass:
|
60
|
+
#
|
61
|
+
# class SearchRequest < VeritySearchRequest
|
62
|
+
# def base_query_conditions
|
63
|
+
# super.merge(:content => '("edited" <#IN> state)'
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
def base_query_conditions
|
67
|
+
conditions = {}
|
68
|
+
conditions[:objTypes] = '<#ANY> (
|
69
|
+
("generic" <#IN> objType),
|
70
|
+
("document" <#IN> objType),
|
71
|
+
("publication" <#IN> objType)
|
72
|
+
)'
|
73
|
+
conditions[:content] = '("released" <#IN> state)'
|
74
|
+
conditions[:suppressExport] = '("0" <#IN> suppressExport)'
|
75
|
+
conditions[:validFrom] = "(validFrom < #{Time.now.to_iso})"
|
76
|
+
conditions[:validUntil] = %!<#OR> (
|
77
|
+
(validUntil = ""),
|
78
|
+
(validUntil > #{Time.now.to_iso})
|
79
|
+
)!
|
80
|
+
conditions
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
data/lib/rating.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: infopark_fiona_connector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -18003498967
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 6
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
- 200
|
12
|
+
- 891
|
13
|
+
- 647580
|
14
|
+
- e
|
15
|
+
version: 6.8.0.beta.200.891.647580e
|
16
|
+
platform: ruby
|
17
|
+
authors:
|
18
|
+
- Infopark AG
|
19
|
+
autorequire:
|
20
|
+
bindir: bin
|
21
|
+
cert_chain: []
|
22
|
+
|
23
|
+
date: 2012-09-06 00:00:00 +02:00
|
24
|
+
default_executable:
|
25
|
+
dependencies:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
hash: 47
|
33
|
+
segments:
|
34
|
+
- 1
|
35
|
+
- 16
|
36
|
+
version: "1.16"
|
37
|
+
version_requirements: *id001
|
38
|
+
name: mime-types
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 21
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 1
|
51
|
+
- 3
|
52
|
+
version: 1.1.3
|
53
|
+
version_requirements: *id002
|
54
|
+
name: mysql_blob_streaming
|
55
|
+
prerelease: false
|
56
|
+
type: :runtime
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 23
|
64
|
+
segments:
|
65
|
+
- 1
|
66
|
+
- 0
|
67
|
+
- 0
|
68
|
+
version: 1.0.0
|
69
|
+
version_requirements: *id003
|
70
|
+
name: rsolr
|
71
|
+
prerelease: false
|
72
|
+
type: :runtime
|
73
|
+
description: The Fiona Connector for Infopark CMS Fiona enables you to develop modern, dynamic Web 2.0 applications using Ruby on Rails and at the same time display CMS managed content.
|
74
|
+
email: info@infopark.de
|
75
|
+
executables: []
|
76
|
+
|
77
|
+
extensions: []
|
78
|
+
|
79
|
+
extra_rdoc_files:
|
80
|
+
- README
|
81
|
+
files:
|
82
|
+
- lib/comment.rb
|
83
|
+
- lib/infopark_fiona_connector.rb
|
84
|
+
- lib/rails_connector/attr_dict.rb
|
85
|
+
- lib/rails_connector/attr_value_provider.bundle
|
86
|
+
- lib/rails_connector/attr_value_provider.so
|
87
|
+
- lib/rails_connector/attr_value_provider64.so
|
88
|
+
- lib/rails_connector/attr_value_provider_loader.rb
|
89
|
+
- lib/rails_connector/blob.rb
|
90
|
+
- lib/rails_connector/blob_mysql.rb
|
91
|
+
- lib/rails_connector/blob_oracle.rb
|
92
|
+
- lib/rails_connector/cache_middleware.rb
|
93
|
+
- lib/rails_connector/cms_base_model.rb
|
94
|
+
- lib/rails_connector/date_attribute.rb
|
95
|
+
- lib/rails_connector/default_search_request.rb
|
96
|
+
- lib/rails_connector/errors.rb
|
97
|
+
- lib/rails_connector/link.rb
|
98
|
+
- lib/rails_connector/lucene_search_request.rb
|
99
|
+
- lib/rails_connector/named_link.rb
|
100
|
+
- lib/rails_connector/news.rb
|
101
|
+
- lib/rails_connector/obj.rb
|
102
|
+
- lib/rails_connector/permission.rb
|
103
|
+
- lib/rails_connector/rack_middlewares.rb
|
104
|
+
- lib/rails_connector/ses/verity_accessor.rb
|
105
|
+
- lib/rails_connector/verity_search_request.rb
|
106
|
+
- lib/rating.rb
|
107
|
+
- README
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://www.infopark.de
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- --charset=UTF-8
|
115
|
+
- --title
|
116
|
+
- Infopark Fiona Connector
|
117
|
+
- --main
|
118
|
+
- README
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 17
|
136
|
+
segments:
|
137
|
+
- 1
|
138
|
+
- 3
|
139
|
+
- 5
|
140
|
+
version: 1.3.5
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.6.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Infopark Fiona Connector
|
148
|
+
test_files: []
|
149
|
+
|