예제 #1
0
func (fr *FileRepo) index() error {
	for _, p := range fr.posts {
		cp := fr.categoryIndex[p.Category]
		fr.categoryIndex[p.Category] = append(cp, p)

		for _, tag := range p.Tags {
			tp := fr.tagIndex[tag]
			fr.tagIndex[tag] = append(tp, p)
		}

		for tok := range tokensFor(p) {
			s := tok.String()
			ps, ok := fr.searchIndex[s]
			if !ok {
				ps = post.NewPostSet()
				fr.searchIndex[s] = ps
			}
			ps.Add(p)
		}

		for _, slug := range p.Slugs {
			_, found := fr.slugIndex[slug]
			if found {
				return fmt.Errorf("slug %#v already found", slug)
			}
			fr.slugIndex[slug] = p
		}
	}
	return nil
}
예제 #2
0
func (ts *TestSuite) TestAdd(c *C) {
	ps := post.NewPostSet()
	post := &post.Post{Id: "foo"}
	c.Assert(ps.Len(), Equals, 0)
	ps.Add(post)
	c.Assert(ps.Len(), Equals, 1)
	c.Assert(ps.Contains(post), Equals, true)
}
예제 #3
0
func (ts *TestSuite) TestIntersection(c *C) {
	ps1 := post.NewPostSet()
	ps2 := post.NewPostSet()

	p1 := &post.Post{Id: "foo"}
	p2 := &post.Post{Id: "bar"}
	p3 := &post.Post{Id: "baz"}

	ps1.Add(p1)
	ps1.Add(p2)
	ps2.Add(p2)
	ps2.Add(p3)

	in := ps1.Intersection(ps2)
	c.Assert(in.Len(), Equals, 1)
	c.Assert(in.Contains(p2), Equals, true)
}