summary refs log tree commit diff stats
path: root/cache/index.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-14 02:44:37 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-14 02:44:37 -0400
commit1281d2b6bbc797af79d6a87b082276b2049693cd (patch)
tree17cbc7e029c4dc88dc8907f2ee9101a7534e7e65 /cache/index.go
parent76ab864fd8372d947d3de97315e4f9996a39ff49 (diff)
downloadgetwtxt-1281d2b6bbc797af79d6a87b082276b2049693cd.tar.gz
tentatively finished QueryTag and associated functions
Diffstat (limited to 'cache/index.go')
-rw-r--r--cache/index.go56
1 files changed, 52 insertions, 4 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
 }