Q4SPNTHA2FEZZHWBKAGTIW2ODRMRTIA2JZST7YMUH2KSLZUD26CQC import ("sort""devt.de/krotik/eliasdb/graph")func RankedWordSearch(terms []string, idx graph.IndexQuery) (RankedResultList, error) {termResults := []map[string][]uint64{}scoredResults := map[string]uint64{}// Search for each term, build a list of postion results and scaffold scoring map.for _, term := range terms {tResult, err := idx.LookupWord("text", term)if err != nil {return nil, err}if len(tResult) > 0 {termResults = append(termResults, tResult)for nodeId := range tResult {scoredResults[nodeId] = 0}}}
func (r SearchResults) Swap(i, j int) {r[i], r[j] = r[j], r[i]}
func (s RankedResultList) Less(i, j int) bool { return s[i].Score < s[j].Score }func (p RankedResultList) Len() int { return len(p) }func (p RankedResultList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func ResultsFromMap(m map[string][]uint64) SearchResults {var results SearchResultsfor k, v := range m {results = append(results, Result{k, len(v)})
func leastTermDistance(aResults map[string][]uint64, bResults map[string][]uint64) map[string]uint64 {// create a map of the scores for each nodescores := map[string]uint64{}localB := map[string][]uint64{}for nodeId, v := range bResults {localB[nodeId] = v
func (r SearchResults) Sort() {sort.Sort(r)
// loop through the nodes in term Afor nodeId, aPositions := range aResults {var shortestDistance uint64 = 99bPositions := localB[nodeId]if len(bPositions) > 0 {for _, aPosition := range aPositions {for _, bPosition := range bPositions {distance := absDiff(aPosition, bPosition)if distance < shortestDistance {shortestDistance = distance}}}}delete(localB, nodeId)scores[nodeId] = shortestDistance}for nodeId := range localB {scores[nodeId] = 100}return scores
// // Go through the captions and get captioned items// for _, caption := range captions {// item := caption.CaptionedItem// if err != nil {// return nil, err// }// results = append(results, item)// }
// Go through the captions and get captioned itemsfor _, caption := range captions {item := caption.CaptionedItemif err != nil {return nil, err}results = append(results, item)}
result := searchResults{Kind: r[0].(string),Key: r[1].(string),Name: r[2].(string),DateTaken: time.Unix(r[3].(int64), 0),}results = append(results, result)}// Sort results by date takensort.SliceStable(results, func(i, j int) bool {return results[i].DateTaken.After((results[j].DateTaken))})var nodes []GraphNodefor _, result := range results {
return results, nil}func FindTakenInYearAndMonth(year int, month int) ([]GraphNode, error) {if !_datesInitialized {ScaffoldMonths()_datesInitialized = true
for _, r := range res.Rows() {result := searchResults{Kind: r[0].(string),Key: r[1].(string),Name: r[2].(string),DateTaken: time.Unix(r[3].(int64), 0),}results = append(results, result)
results := make([]GraphNode, 0)for _, t := range takenInMonth {for _, ty := range takenInYear {if t.Key == ty.Key {results = append(results, t)}
for _, result := range results {node := GraphNode{Key: result.Key,Kind: result.Kind,Name: result.Name,
// if err == nil {// var captions []Caption// for _, key := range keys {// caption, err := GetCaptionByKey(key, gm, gpart)// if err != nil {// return captions, err// }
//TODO - store a format-free lowercase version of the caption text for searching.