Class: Redis::Commands::Search::HybridSearchQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/commands/modules/search/hybrid.rb

Overview

The textual SEARCH leg of an FT.HYBRID query.

Chainable setters (+scorer+, yield_score_as) return self; #args renders the leg into its argument tokens, beginning with "SEARCH".

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_string, scorer: nil, yield_score_as: nil) ⇒ HybridSearchQuery

Returns a new instance of HybridSearchQuery.

Parameters:

  • query_string (String)

    the search query string

  • scorer (String, nil) (defaults to: nil)

    the scoring function

  • yield_score_as (String, nil) (defaults to: nil)

    the alias to expose the search score under



17
18
19
20
21
# File 'lib/redis/commands/modules/search/hybrid.rb', line 17

def initialize(query_string, scorer: nil, yield_score_as: nil)
  @query_string = query_string
  @scorer = scorer
  @yield_score_as = yield_score_as
end

Instance Attribute Details

#query_stringString (readonly)

Returns the search query string.

Returns:

  • (String)

    the search query string



12
13
14
# File 'lib/redis/commands/modules/search/hybrid.rb', line 12

def query_string
  @query_string
end

Instance Method Details

#argsArray

Returns the SEARCH leg argument tokens, beginning with "SEARCH".

Returns:

  • (Array)

    the SEARCH leg argument tokens, beginning with "SEARCH"



42
43
44
45
46
47
# File 'lib/redis/commands/modules/search/hybrid.rb', line 42

def args
  result = ["SEARCH", @query_string]
  result << "SCORER" << @scorer if @scorer
  result << "YIELD_SCORE_AS" << @yield_score_as if @yield_score_as
  result
end

#scorer(scorer) ⇒ self

Set the scoring function (+SCORER+).

Parameters:

  • scorer (String)

    the scorer name

Returns:

  • (self)


27
28
29
30
# File 'lib/redis/commands/modules/search/hybrid.rb', line 27

def scorer(scorer)
  @scorer = scorer
  self
end

#yield_score_as(alias_name) ⇒ self

Expose the search score under an alias (+YIELD_SCORE_AS+).

Parameters:

  • alias_name (String)

    the alias for the score

Returns:

  • (self)


36
37
38
39
# File 'lib/redis/commands/modules/search/hybrid.rb', line 36

def yield_score_as(alias_name)
  @yield_score_as = alias_name
  self
end