Navigation Menu

Skip to content

Commit

Permalink
Support snippet_html()!
Browse files Browse the repository at this point in the history
GitHub: fixes #7
  • Loading branch information
kou committed Jun 21, 2013
1 parent 1b753bb commit 81c9c2c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/droonga/plugin/handler_search.rb
Expand Up @@ -91,6 +91,7 @@ def initialize(context, query)
@context = context
@query = query
@result = nil
@condition = nil
@start_time = nil
end

Expand Down Expand Up @@ -201,6 +202,7 @@ def search_query(results)
expression.define_variable(:domain => source)
parseCondition(source, expression, @query["condition"])
@result = source.select(expression)
@condition = expression
end
if @query["groupBy"]
if @query["groupBy"].is_a? String
Expand Down Expand Up @@ -311,6 +313,9 @@ def normalize_target_attributes(attributes)
expression = Groonga::Expression.new(context: @context)
variable = expression.define_variable(domain: @result)
expression.parse(source, syntax: :script)
condition = expression.define_variable(name: "$condition",
reference: true)
condition.value = @condition
source = nil
end
{
Expand Down
41 changes: 41 additions & 0 deletions test/plugin/test_handler_search.rb
Expand Up @@ -387,6 +387,47 @@ def test_expression
}
assert_search(expected, request)
end

def test_snippet_html
expected = {
"sections-result" => {
"records" => [
{
"title" => "Groonga overview",
"snippet" => [
"<span class=\"keyword\">Groonga</span> overview",
],
},
],
},
}
request = {
"queries" => {
"sections-result" => {
"source" => "Sections",
"condition" => {
"query" => "Groonga",
"matchTo" => ["title"],
},
"output" => {
"elements" => [
"records",
],
"format" => "complex",
"limit" => 1,
"attributes" => [
"title",
{
"label" => "snippet",
"source" => "snippet_html(title)",
},
],
},
},
},
}
assert_search(expected, request)
end
end

class FormatTest < self
Expand Down

0 comments on commit 81c9c2c

Please sign in to comment.