tagstack

package module
v0.0.0-...-68deb29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2014 License: MIT Imports: 13 Imported by: 0

README

tagstack

Documentation

Overview

A tag indexing & searching system.

Index

Constants

View Source
const (
	SORT_BY_SCORE = iota
	SORT_BY_DATE
	SORT_BY_OVERALL
)

Variables

View Source
var (
	// To get reading / writing connections, tagstack is based on Redis & redigo.
	GetReadConn, GetWriteConn GetRedisConnFuncType

	// To notify if a new tag group becomes high.
	HighTagNofityFunc HighTagNotifyFuncType

	RedisShardMax int
)
View Source
var (
	// Normal logger.
	Logger = log.New(os.Stdout, "[tagstack]", log.LstdFlags)
	// Debug logger.
	DebugLogger = log.New(ioutil.Discard, "", 0)
)

Loggers.

Functions

This section is empty.

Types

type GetRedisConnFuncType

type GetRedisConnFuncType func(shard_key int) redis.Conn

type HighTagNotifyFuncType

type HighTagNotifyFuncType func(tags []string)

type Index

type Index struct {
	// To describe what's this index about, for example: Blog / News
	// And the string should be as short as possible, for the string is the prefix of all the keys in the redis database.
	What string

	// High Node Boundary:
	// A parameter to balance between memory usage & search speed:
	// the higher: the index size smaller & search slower.
	// normally a value of 100 is Ok.
	HighNodeBoundary int

	// the rule of this index.
	// please see type Rule struct for detail.
	Rule *Rule

	// Item loading funcation
	ItemLoadFunc ItemLoadFuncType

	// Optional: Enable this if you use 'RandomSuggestTags' method.
	// Note: If the items usually have more than 20 tags, this SHOULD NOT be enabled, because this feature will slow down the indexing progress to a "minutes per update" level.
	EnableRandomSuggestTags bool
	// contains filtered or unexported fields
}

the index struct

func (*Index) Init

func (index *Index) Init()

This should be called once the struct is configured properly.

func (*Index) ItemCount

func (index *Index) ItemCount(tags []string) int

How many items have all the tags.

func (*Index) Query

func (index *Index) Query(tags []string, start, stop int) (ids []uint64)

Query by tags in the [start, stop] range (including both start/stop)

func (*Index) QueryOptions

func (index *Index) QueryOptions(tags []string, start, stop int, options *IndexOptions) (ids []uint64)

func (*Index) RandomSuggestTags

func (index *Index) RandomSuggestTags(tags []string, count int) (sugs []string)

Suggest some tag that

func (*Index) RelativeTags

func (index *Index) RelativeTags(tags []string, count int) (relative_tags []string)

What's the most frequently used tags with the tags ? Blame my poor language, in another way: Suggest a group of tags depends on a given group of tags.

func (*Index) RelativeTagsCount

func (index *Index) RelativeTagsCount(tags []string) int

Number of "relative tags".

func (*Index) RelativeTagsOptions

func (index *Index) RelativeTagsOptions(tags []string, count int, options *IndexOptions) (relative_tags []string)

func (*Index) Remove

func (index *Index) Remove(id uint64)

Remove an item completely from the index.

func (*Index) Update

func (index *Index) Update(id uint64)

Update an item: Note: If you are looking for: Create or New, use this instead. To reduce code complexity: we mix 2 kinds of request together: 1. Adding / Removing Tags 2. Update an item's score to affect the rank in searching. Update function will first remove old tags then refresh everything about the item together.

func (*Index) WaitAllIndexingDone

func (index *Index) WaitAllIndexingDone()

When you wonder if all the indexing jobs are all done

type IndexOptions

type IndexOptions struct {
	SortBy   SORT_BY
	Reversal bool   // TODO: feature
	WhoseId  uint64 // TODO: feature
}

type Item

type Item interface {
	// The item's identifier in uint64.
	Id() uint64

	// The basic score / value of this item.
	Score() float64

	// What's the item's tag, and the scores.
	// If there's no score among the tags, just pass scores with nil.
	TagsWithScore() (tags []string, scores []float64)

	// Whose item? the item id in uint64
	WhoseId() uint64

	// When did this item created.
	CreateDate() uint64
}

What you should feed into this tag system.

type ItemLoadFuncType

type ItemLoadFuncType func(id uint64) Item

The function type the system load a item. (thread-safe)

type Rule

type Rule struct {
	Normalization map[string][]string
	Entanglement  [][]string
	Containing    map[string][]string
}

The rule struct: This should be configured very carefully. It's normal to use a json.Decode to generate this.

type SORT_BY

type SORT_BY int

options.

type Tag

type Tag string

Tag is a string, and nothing else matters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL