summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cache/index.go56
-rw-r--r--cache/types.go13
2 files changed, 63 insertions, 6 deletions
diff --git a/cache/index.go b/cache/index.go
index ee00479..a6ee7b6 100644
--- a/cache/index.go
+++ b/cache/index.go
@@ -52,11 +52,59 @@ func (index UserIndex) QueryUser(name string) []string {
 	return users
 }
 
+// QueryTag returns all the known statuses that
+// contain the provided tag.
+func (index UserIndex) QueryTag(tag string) []string {
+	var statusmap StatusMapSlice
+	i := 0
+	for _, v := range index {
+		statusmap[i] = v.FindTag(tag)
+		i++
+	}
+
+	return statusmap.SortByTime()
+}
+
 // FindTag takes a user's tweets and looks for a given tag.
 // Returns the tweets with the tag as a []string.
-func (userdata *Data) FindTag(tag string) {
-	//for _, e := range userdata.status {
-	//parts := strings.Split(e, "\t")
+func (userdata *Data) FindTag(tag string) StatusMap {
+	var statuses StatusMap
+	for k, e := range userdata.status {
+		parts := strings.Split(e, "\t")
+		statusslice := strings.Split(parts[3], " ")
+		for _, v := range statusslice {
+			if v == tag {
+				statuses[k] = v
+				break
+			}
+		}
+	}
+
+	return statuses
+}
+
+// SortByTime returns a string slice of the statuses sorted by time
+func (sm StatusMapSlice) SortByTime() []string {
+	var tagmap StatusMap
+	var times TimeSlice
+	var statuses []string
+	for _, e := range sm {
+		for k, v := range e {
+			tagmap[k] = v
+		}
+	}
+	for k := range tagmap {
+		times = append(times, k)
+	}
+	sort.Sort(times)
+	for _, e := range times {
+		statuses = append(statuses, tagmap[e])
+	}
+
+	return statuses
+}
 
-	//}
+// GetStatuses returns the string slice containing a user's statuses
+func (index UserIndex) GetStatuses(url string) StatusMap {
+	return index[url].status
 }
diff --git a/cache/types.go b/cache/types.go
index 939114e..2962ab4 100644
--- a/cache/types.go
+++ b/cache/types.go
@@ -19,9 +19,17 @@ type Data struct {
 	nick    string
 	date    time.Time
 	apidate []byte
-	status  []string
+	status  StatusMap
 }
 
+// StatusMap holds the statuses posted by a given user. A standard
+// time.Time value is used as the key, with the status as a string.
+type StatusMap map[time.Time]string
+
+// StatusMapSlice is a slice of StatusMaps. Useful for sorting the
+// output of queries.
+type StatusMapSlice []StatusMap
+
 // Mutex to control access to the User Index.
 var imutex = sync.RWMutex{}
 
@@ -34,7 +42,8 @@ func (t TimeSlice) Len() int {
 	return len(t)
 }
 
-// Less returns true if the timestamp at index i is before the timestamp at index j in TimeSlice.
+// Less returns true if the timestamp at index i is before the
+// timestamp at index j in TimeSlice.
 // This helps satisfy sort.Interface with respect to TimeSlice.
 func (t TimeSlice) Less(i, j int) bool {
 	return t[i].Before(t[j])
' href='#n223'>223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344