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

17
util.go
View File

@ -30,6 +30,23 @@ import (
"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 {
var result float64
for key, value1 := range features1 {