Commits

Ross Light  committed 24c55bf

Add internal docs to catalog/search

  • Participants
  • Parent commits dec4930

Comments (0)

Files changed (1)

File catalog/search/search.go

 	Relevance float32
 }
 
+// textSearch is a Searcher that can perform a full text search.
 type textSearch struct {
-	c    catalog.Catalog
 	i    map[string][]indexEntry
 	tags map[string][]string
 	list []string
 		return nil, err
 	}
 	ts := &textSearch{
-		c:    cat,
 		i:    make(map[string][]indexEntry),
 		tags: make(map[string][]string),
 		list: names,
 	}
-	for _, n := range names {
-		if err := ts.build(n); err != nil {
+	for _, sn := range names {
+		p, err := cat.GetProject(sn)
+		if err != nil {
 			return nil, err
 		}
+		ts.build(p)
 	}
 	return ts, nil
 }
 
+// Search parses a query according to the grammar at https://bitbucket.org/zombiezen/glados/wiki/Search
+// and then finds all matching projects, sorted by decreasing relevance.
 func (ts *textSearch) Search(q string) ([]Result, error) {
 	query, err := parseQuery(q)
 	if err != nil {
 	return results, nil
 }
 
+// search executes the query q and stores the matches in results.
 func (ts *textSearch) search(q queryAST, results resultMap) {
 	switch q := q.(type) {
 	case queryAnd:
 	}
 }
 
-func (ts *textSearch) build(sn string) error {
-	p, err := ts.c.GetProject(sn)
-	if err != nil {
-		return err
-	}
+// build adds the project to the index.
+func (ts *textSearch) build(p *catalog.Project) {
+	sn := p.ShortName
 	ts.index(sn, kindShortName, [][]rune{fold([]rune(sn))})
 	ts.index(sn, kindName, tokenize(fold([]rune(p.Name))))
 	ts.index(sn, kindDescription, tokenize(fold([]rune(p.Description))))
 		ts.index(sn, kindTag, [][]rune{t})
 		ts.index(sn, kindTagPart, tokenize(t))
 	}
-	return nil
 }
 
+// indexTag associates a tag with a short name.
 func (ts *textSearch) indexTag(sn string, tag []rune) {
 	stag := string(tag)
 	indexed := ts.tags[stag]
 	ts.tags[stag] = indexed
 }
 
+// index associates words with a short name.
 func (ts *textSearch) index(sn string, kind entryKind, words [][]rune) {
 	for _, w := range words {
 		if len(w) > 0 {