Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/Ab_testing.luan @ 544:c5a93767cc5c
lucene overhaul, untested
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 12 Jun 2015 19:11:44 -0600 |
parents | 473e456444ff |
children | ddcd4296107a |
comparison
equal
deleted
inserted
replaced
543:9767da72545b | 544:c5a93767cc5c |
---|---|
8 local String = require "luan:String" | 8 local String = require "luan:String" |
9 local gsub = String.gsub | 9 local gsub = String.gsub |
10 local Io = require "luan:Io" | 10 local Io = require "luan:Io" |
11 local Http = require "luan:http/Http" | 11 local Http = require "luan:http/Http" |
12 local Logging = require "luan:logging/Logging" | 12 local Logging = require "luan:logging/Logging" |
13 local Lucene = require "luan:lucene/Lucene" | |
13 | 14 |
14 local M = {} | 15 local M = {} |
15 | 16 |
16 local logger = Logging.logger "Ab_testing" | 17 local logger = Logging.logger "Ab_testing" |
17 | 18 |
32 test.aggregator_factories or error "aggregator_factories not defined" | 33 test.aggregator_factories or error "aggregator_factories not defined" |
33 | 34 |
34 -- test.date_field is optional | 35 -- test.date_field is optional |
35 | 36 |
36 local field = "ab_test_" .. test.name | 37 local field = "ab_test_" .. test.name |
37 index.fields[field] == nil or error("test "+test.name+" already defined") | 38 index.indexed_fields[field] == nil or error("test "+test.name+" already defined") |
38 index.fields[field] = field .. " index" | 39 index.indexed_fields[field] = Lucene.type.string |
39 test.field = field | 40 test.field = field |
40 | 41 |
41 -- returns map of event name to (map of value to result) and "start_date" | 42 -- returns map of event name to (map of value to result) and "start_date" |
42 function test.results() | 43 function test.results() |
43 return index.Searcher( function(searcher) | 44 return index.Searcher( function(searcher) |
50 for _, value in ipairs(test.values) do | 51 for _, value in ipairs(test.values) do |
51 local aggregators = {} | 52 local aggregators = {} |
52 for name, factory in pairs(test.aggregator_factories) do | 53 for name, factory in pairs(test.aggregator_factories) do |
53 aggregators[name] = factory() | 54 aggregators[name] = factory() |
54 end | 55 end |
55 local query = index.query.term{ [field] = value } | 56 local query = field..":"..value |
56 searcher.search(query, function(doc) | 57 searcher.search(query, function(doc) |
57 for _, aggregator in pairs(aggregators) do | 58 for _, aggregator in pairs(aggregators) do |
58 aggregator.aggregate(doc) | 59 aggregator.aggregate(doc) |
59 end | 60 end |
60 if date_field ~= nil then | 61 if date_field ~= nil then |