1
This commit is contained in:
Alex Yatskov 2015-03-25 18:41:19 +09:00
parent 2a32300421
commit 8aaf32c866
2 changed files with 10 additions and 11 deletions

View File

@ -47,13 +47,12 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
geo = &geoContext{latitude: request.Geo.Latitude, longitude: request.Geo.Longitude}
}
context := queryContext{geo, request.Profile, request.WalkingDist}
entries := getRecords(context)
entries := getRecords(queryContext{geo, request.Profile, request.WalkingDist})
features := fixFeatures(request.Features)
foundEntries := findRecords(entries, features, request.MinScore)
response := jsonQueryResponse{
Count: len(foundEntries),
Columns: make(map[string]jsonColumn),
Items: make([]jsonRecord, 0)}
@ -84,7 +83,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
break
}
jsonEntry := jsonRecord{
item := jsonRecord{
Name: value.name,
Score: value.score,
DistanceToUser: value.distanceToUser,
@ -93,7 +92,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
AccessCount: value.accessCount,
Id: value.id}
response.Items = append(response.Items, jsonEntry)
response.Items = append(response.Items, item)
}
js, err := json.Marshal(response)

12
util.go
View File

@ -91,6 +91,7 @@ func findRecords(entries records, features featureMap, minScore float64) records
var foundEntries records
walkMatches(entries, features, minScore, func(record record, score float64) {
record.score = score
foundEntries = append(foundEntries, record)
})
@ -151,8 +152,10 @@ func computeRecordGeo(entries records, context queryContext) {
}
func computeRecordPopularity(entries records, context queryContext) {
for _, record := range entries {
historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", record.id)
for index := range entries {
entry := &entries[index]
historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", entry.id)
if err != nil {
log.Fatal(err)
}
@ -193,12 +196,9 @@ func computeRecordPopularity(entries records, context queryContext) {
log.Fatal(err)
}
var compatibility float64
if groupCount > 0 {
compatibility = groupSum / float64(groupCount)
entry.compatibility = groupSum / float64(groupCount)
}
record.features["compatibility"] = compatibility
}
}