Kouhei Sutou
null+****@clear*****
Wed Mar 26 00:08:35 JST 2014
Kouhei Sutou 2014-03-26 00:08:35 +0900 (Wed, 26 Mar 2014) New Revision: f6e1b7902077d9ec3b755e9dbb76f3fc45ba717e https://github.com/droonga/fluent-plugin-droonga/commit/f6e1b7902077d9ec3b755e9dbb76f3fc45ba717e Message: search: add "queries.QUERY.adjusters" It just increases score for target records in condition matched records. It doesn't change the number of condition matched records. It doesn't remove not target records. See also Groonga's documentation: http://groonga.org/docs/reference/commands/select.html#select-adjuster TODO: * Document me. * Add input validations. Added files: test/command/suite/search/adjusters/one.catalog.json test/command/suite/search/adjusters/one.expected test/command/suite/search/adjusters/one.test Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+29 -1) =================================================================== --- lib/droonga/searcher.rb 2014-03-25 13:09:41 +0900 (8eb92ff) +++ lib/droonga/searcher.rb 2014-03-26 00:08:35 +0900 (28b8b31) @@ -302,7 +302,12 @@ module Droonga @records =****@reque***** condition =****@reque*****["condition"] - apply_condition!(condition) if condition + if condition + apply_condition!(condition) + + adjusters =****@reque*****["adjusters"] + apply_adjusters!(adjusters) if adjusters + end group_by =****@reque*****["groupBy"] apply_group_by!(group_by) if group_by @@ -328,6 +333,29 @@ module Droonga @result.condition = expression end + def apply_adjusters!(adjusters) + logger.trace("search_query: adjusters: start") + adjusters.each do |adjuster| + column_name = adjuster["column"] + value = adjuster["value"] + factor = adjuster["factor"] || 0 + logger.trace("search_query: adjusters: adjuster: start", + :column_name => column_name, + :value => value, + :factor => factor) + column =****@reque*****(column_name) + index, = column.indexes(:match) + # TODO: add index.nil? check + # TODO: add value.nil? check + index.search(value, + :result => @records, + :operator => :adjust, + :weight => factor) + logger.trace("search_query: adjusters: adjuster: done") + end + logger.trace("search_query: adjusters: done") + end + def apply_group_by!(group_by) logger.trace("search_query: group: start", :by => group_by) Added: test/command/suite/search/adjusters/one.catalog.json (+38 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/adjusters/one.catalog.json 2014-03-26 00:08:35 +0900 (3a92872) @@ -0,0 +1,38 @@ +{ + "datasets": { + "Droonga": { + "fact": "Memos", + "schema": { + "Memos": { + "type": "Hash", + "keyType": "ShortText", + "columns": { + "tags": { + "type": "Vector", + "valueType": "ShortText", + "vectorOptions": { + "weight": true + } + } + } + }, + "Tags": { + "type": "Hash", + "keyType": "ShortText", + "columns": { + "memos_index": { + "type": "Index", + "valueType": "Memos", + "indexOptions": { + "sources": [ + "tags" + ], + "weight": true + } + } + } + } + } + } + } +} Added: test/command/suite/search/adjusters/one.expected (+23 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/adjusters/one.expected 2014-03-26 00:08:35 +0900 (d866897) @@ -0,0 +1,23 @@ +[ + "droonga.message", + 0, + { + "inReplyTo": "request-id", + "statusCode": 200, + "type": "search.result", + "body": { + "memos": { + "records": [ + [ + "Droonga is fun.", + 51 + ], + [ + "Groonga is fast!", + 1 + ] + ] + } + } + } +] Added: test/command/suite/search/adjusters/one.test (+65 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/search/adjusters/one.test 2014-03-26 00:08:35 +0900 (a12c474) @@ -0,0 +1,65 @@ +# -*- js -*- +#@require-catalog-version 2 +#@disable-logging +{ + "type": "add", + "dataset": "Droonga", + "body": { + "table": "Memos", + "key": "Droonga is fun.", + "values": { + "tags": [ + { + "value": "droonga", + "weight": 9 + } + ] + } + } +} +{ + "type": "add", + "dataset": "Droonga", + "body": { + "table": "Memos", + "key": "Groonga is fast!", + "values": { + "tags": [ + { + "value": "groonga", + "weight": 9 + } + ] + } + } +} +#@enable-logging +{ + "type": "search", + "dataset": "Droonga", + "body": { + "queries": { + "memos": { + "source": "Memos", + "condition": "true", + "adjusters": [ + { + "column": "tags", + "value": "droonga", + "factor": 5 + } + ], + "output": { + "elements": [ + "records" + ], + "limit": 10, + "attributes": [ + "_key", + "_score" + ] + } + } + } + } +} -------------- next part -------------- HTML����������������������������...Download