1
This commit is contained in:
Alex Yatskov 2015-03-25 13:12:22 +09:00
parent 439ebc3a61
commit bed11ae34b
2 changed files with 34 additions and 16 deletions

View File

@ -49,17 +49,18 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
context := queryContext{geo, request.Profile, request.WalkingDist} context := queryContext{geo, request.Profile, request.WalkingDist}
entries := getRecords(context) entries := getRecords(context)
features := fixFeatures(request.Features)
foundEntries := findRecords(entries, request.Features, request.MinScore) foundEntries := findRecords(entries, features, request.MinScore)
var response jsonQueryResponse response := jsonQueryResponse{Columns: make(map[string]jsonColumn)}
for featureName, featureValue := range request.Features { for name, value := range features {
column := jsonColumn{Value: featureValue, Steps: request.HintSteps} column := jsonColumn{Value: value, Steps: request.HintSteps}
hints := project( hints := project(
foundEntries, foundEntries,
request.Features, features,
featureName, name,
request.MinScore, request.MinScore,
queryBounds{min: request.Range.Min, max: request.Range.Max}, queryBounds{min: request.Range.Min, max: request.Range.Max},
request.HintSteps) request.HintSteps)
@ -71,22 +72,22 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
column.Hints = append(column.Hints, jsonHint) column.Hints = append(column.Hints, jsonHint)
} }
response.Columns[featureName] = column response.Columns[name] = column
} }
for entryIndex, entryValue := range foundEntries { for index, value := range foundEntries {
if entryIndex > request.MaxResults { if index > request.MaxResults {
break break
} }
jsonEntry := jsonRecord{ jsonEntry := jsonRecord{
Name: entryValue.name, Name: value.name,
Score: entryValue.score, Score: value.score,
DistanceToUser: entryValue.distanceToUser, DistanceToUser: value.distanceToUser,
DistanceToStn: entryValue.distanceToStn, DistanceToStn: value.distanceToStn,
ClosestStn: entryValue.closestStn, ClosestStn: value.closestStn,
AccessCount: entryValue.accessCount, AccessCount: value.accessCount,
Id: entryValue.id} Id: value.id}
response.Items = append(response.Items, jsonEntry) response.Items = append(response.Items, jsonEntry)
} }

17
util.go
View File

@ -30,6 +30,23 @@ import (
"strconv" "strconv"
) )
func fixFeatures(features featureMap) featureMap {
fixedFeatures := featureMap{
"nearby": 0.0,
"accessible": 0.0,
"delicious": 0.0,
"accomodating": 0.0,
"affordable": 0.0,
"atmospheric": 0.0}
for name, _ := range fixedFeatures {
value, _ := features[name]
fixedFeatures[name] = value
}
return fixedFeatures
}
func innerProduct(features1 featureMap, features2 featureMap) float64 { func innerProduct(features1 featureMap, features2 featureMap) float64 {
var result float64 var result float64
for key, value1 := range features1 { for key, value1 := range features1 {