Class: RailsConnector::VeritySearchRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_connector/verity_search_request.rb

Overview

This class provides an implementation for accessing the Verity based search server. It should be customized by subclassing.

Instance Method Summary collapse

Constructor Details

#initialize(query_string, options = nil) ⇒ VeritySearchRequest

Sanitizes the given query_string and takes options for accessing the SES.

query_string is a VQL search query. options is a hash and may be used to tweek the query.

Options:

:host

The SES server host, default: 'localhost'

:port

The SES server port, default: 3011

:offset

The search offset, default: 0

:limit

The maximum number of hits in the SearchResult, default: 10

:min_relevance

The minimum relevance in percent, default: 50

:max_docs

The maximum number of documents to be searched, default: 'unlimited'

:parser

The VQL query parser to be used, default: 'simple'

:sort_order

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: [["score", "desc"], ["name", "asc"]]

:collections

The collections to be searched, default: ['cm-contents']

:base_query

The VQL base query, default: nil


27
28
29
30
# File 'lib/rails_connector/verity_search_request.rb', line 27

def initialize(query_string, options=nil)
  @query_string = self.class.sanitize(query_string)
  @options = Configuration.search_options.merge(options || {})
end

Instance Method Details

#base_query_conditionsObject

A hash of conditions, combined to a base query by #base_query. Note that all values of the hash must be valid VQL syntax. The keys have no meaning and exist only so single conditions can be replaced in a subclass:

class SearchRequest < VeritySearchRequest
  def base_query_conditions
    super.merge(:content => '("edited" <#IN> state)'
  end
end

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rails_connector/verity_search_request.rb', line 71

def base_query_conditions
  conditions = {}
  conditions[:objTypes] = '<#ANY> (
    ("generic" <#IN> objType),
    ("document" <#IN> objType),
    ("publication" <#IN> objType)
  )'
  conditions[:content] = '("released" <#IN> state)'
  conditions[:suppressExport] = '("0" <#IN> suppressExport)'
  conditions[:validFrom] = "(validFrom < #{Time.now.to_iso})"
  conditions[:validUntil] =  %!<#OR> (
                  (validUntil = ""),
                  (validUntil > #{Time.now.to_iso})
                )!
  conditions
end

#fetch_hitsObject

Accesses the SES and fetches search hits.

Uses the #base_query and options given in #new.


36
37
38
# File 'lib/rails_connector/verity_search_request.rb', line 36

def fetch_hits
  SES::VerityAccessor.new(vql_query_for(@query_string), {:base_query => base_query}.merge(@options)).search
end