Documentation ¶
Index ¶
- Constants
- func IsAlnumWord(word string) bool
- func SanitiseForAuto(in string) string
- type AddressResolutionError
- type Collection
- type Database
- func (db *Database) AddMeta(pid int, value string) error
- func (db *Database) Close()
- func (db *Database) Connect() error
- func (db *Database) GenerateFts(since int64) error
- func (db *Database) InsertPiece(piece *Piece) (err error)
- func (db *Database) InsertPieces(pieces chan *Piece, fts bool) (err error)
- func (db *Database) InsertPost(post Post) (int64, error)
- func (db *Database) PaginatedQuery(query string, page int) ([]*Post, error)
- func (db *Database) PostCount() uint
- func (db *Database) QueryPiece(id uint, store bool) (*Piece, error)
- func (db *Database) QueryPiecePosts(start, length int, store bool) chan *Post
- func (db *Database) QueryPopular(page int) ([]*Post, error)
- func (db *Database) QueryPostId(id uint) (Post, error)
- func (db *Database) QueryRecent(page int) ([]*Post, error)
- func (db *Database) Search(query string, page, pageSize int) ([]*Post, error)
- func (db *Database) SetLeechers(id, leechers uint) error
- func (db *Database) SetSeeders(id, seeders uint) error
- func (db *Database) Suggest(query string) ([]string, error)
- type ErrorReader
- type Piece
- type Post
- type SearchProvider
- type SearchResult
Constants ¶
const ( TitleMax = 144 TagsMax = 256 MaxPostSize = TitleMax + TagsMax + 1024 )
const PieceSize = 1000
Variables ¶
This section is empty.
Functions ¶
func IsAlnumWord ¶
func SanitiseForAuto ¶
Takes a string, makes it look "nice" for an autocomplete cue.
Types ¶
type AddressResolutionError ¶
type AddressResolutionError struct {
Address string
}
func (AddressResolutionError) Error ¶
func (a AddressResolutionError) Error() string
type Collection ¶
A collection of pieces, by extension a structure containing all posts this peer has. Whether or not the pieces are *actually* there is optional, if not this is essentially a hash list.
func CreateCollection ¶
func CreateCollection(db *Database, start, pieceSize int) (*Collection, error)
Takes a database, starting id, and piece size. From this we create a collection, except it does not contain any posts - consider making this optional.
func LoadCollection ¶
func LoadCollection(path string) (col *Collection, err error)
Loads a collection from file. This essentially loads the hash list, the data of pieces themselves is just left. It's all in the database if it is really needed.
func NewCollection ¶
func NewCollection() *Collection
Create a new collection, set all it's members to the correct default values.
func (*Collection) Add ¶
func (c *Collection) Add(piece *Piece)
Add a piece to the collection, storing it in c.Pieces and appending it's hash to the hash list.
func (*Collection) Hash ¶
func (c *Collection) Hash() []byte
Return the hash of the hash list, which can then go on to be signed by the LocalPeer. This allows proper validation of an entire collection, but the localpeer only needs to sign a single hash.
func (*Collection) Rehash ¶
func (c *Collection) Rehash()
Regenerates the root hash from the hash list we have.
func (*Collection) Save ¶
func (c *Collection) Save(path string) error
Save the collection hash list to the given path, with permissions 0777.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func NewDatabase ¶
func (*Database) Connect ¶
Connect to a database. If it does not already exist it is created, and the proper schema is also setup.
func (*Database) GenerateFts ¶
Generate a full text search index since the given id. This should ideally be done only for new additions, otherwise on a large dataset it can take a bit of time.
func (*Database) InsertPiece ¶
Inserts a piece into the database. All the posts are iterated over and inserted within a single SQL transaction.
func (*Database) InsertPieces ¶
Insert pieces from a channel, good for streaming them from a network or something. The fts bool is whether or not a fts index will be generated on every transaction commit. Transactions contain 100 pieces, or 100,000 posts.
func (*Database) InsertPost ¶
Insert a single post into the database.
func (*Database) PaginatedQuery ¶
Performs a query upon the database where the only arguments are the page range. This is useful for thing such as popular and recent posts.
func (*Database) QueryPiece ¶
Return a single piece given it's id. Optionally store the posts as well, otherwise we just get a hash.
func (*Database) QueryPiecePosts ¶
Very simmilar to QueryPiece, except this returns a channel and streams posts out as they arrive. Queries a range of posts, so you can ask for 100 posts starting at an id.
func (*Database) QueryPopular ¶
Returns a page of posts ordered by popularity, descending. Popularity is a combination of seeders and leechers, weighted ever so slightly towards seeders.
func (*Database) QueryPostId ¶
Return a single post given it's id.
func (*Database) QueryRecent ¶
Returns a page of posts ordered by upload data, descending.
func (*Database) Search ¶
Perform a query on the FTS table. The results returned are used to pull actual results out of the post table, and these are returned.
func (*Database) SetLeechers ¶
func (*Database) SetSeeders ¶
type ErrorReader ¶
type ErrorReader struct { Err error // contains filtered or unexported fields }
func NewErrorReader ¶
func NewErrorReader(r io.Reader) *ErrorReader
func (*ErrorReader) ReadByte ¶
func (er *ErrorReader) ReadByte() (byte, error)
func (*ErrorReader) ReadString ¶
func (er *ErrorReader) ReadString(delim byte) string
type Post ¶
type SearchProvider ¶
type SearchProvider struct {
Loaded bool
}
This provides searching, as it is a little more comlex than just a db query. Search strings could provide other data that needs parsing, as well as spell correction that needs doing. This has to be passed through other functions before it hits a db query, hence this.
func NewSearchProvider ¶
func NewSearchProvider() *SearchProvider
func (*SearchProvider) Search ¶
func (sp *SearchProvider) Search(source string, db *Database, query string, page int) (SearchResult, error)