Class: Celsius::Primo::SoapApi::Searcher::SearchBrief::SearchRequestTransformation::ProcessQueryStringQueries

Inherits:
Transformation::Step
  • Object
show all
Defined in:
lib/celsius/primo/soap_api/searcher/search_brief/search_request_transformation/process_query_string_queries.rb

Instance Method Summary collapse

Instance Method Details

#callObject



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
# File 'lib/celsius/primo/soap_api/searcher/search_brief/search_request_transformation/process_query_string_queries.rb', line 7

def call
  if query_string_queries = Celsius::Hash.deep_find_key(source, :query_string)
    # memoize the QueryTerms node
    query_terms_node = transformation.inner_search_request.locate("PrimoSearchRequest/QueryTerms").first

    # if multiple queries strings are given, they all have to match
    query_terms_node.locate("BoolOpeator").first << "AND"

    # for each query_string query, add a QueryTerm node
    query_string_queries.each do |query_string_query|
      value = query_string_query[:query] || query_string_query["query"]

      # primo can only handle one (index_)field
      index_field = (query_string_query[:fields] || query_string_query["fields"]).first

      # translate the index field to a known primo index field
      index_field = index_field_mapping(index_field)

      query_terms_node << Ox.parse(
        "<QueryTerm>\n<IndexField>\#{index_field}</IndexField>\n<PrecisionOperator>contains</PrecisionOperator>\n<Value>\#{value}</Value>\n</QueryTerm>\n"
      )
    end
  end
end