本文整理汇总了Golang中labix/org/v2/mgo.Index类的典型用法代码示例。如果您正苦于以下问题:Golang Index类的具体用法?Golang Index怎么用?Golang Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Index类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateNewMongoGraph
func CreateNewMongoGraph(addr string, options graph.Options) bool {
conn, err := mgo.Dial(addr)
if err != nil {
glog.Fatal("Error connecting: ", err)
return false
}
conn.SetSafe(&mgo.Safe{})
dbName := DefaultDBName
if val, ok := options.StringKey("database_name"); ok {
dbName = val
}
db := conn.DB(dbName)
indexOpts := mgo.Index{
Key: []string{"Sub"},
Unique: false,
DropDups: false,
Background: true,
Sparse: true,
}
db.C("triples").EnsureIndex(indexOpts)
indexOpts.Key = []string{"Pred"}
db.C("triples").EnsureIndex(indexOpts)
indexOpts.Key = []string{"Obj"}
db.C("triples").EnsureIndex(indexOpts)
indexOpts.Key = []string{"Provenance"}
db.C("triples").EnsureIndex(indexOpts)
return true
}
示例2: _ensureDbIndexes
func _ensureDbIndexes(session *mgo.Session) {
sessions := session.DB(_cfg.Database).C(SESSIONS_COLLECTION)
expireSessionsIndex := mgo.Index{}
//TODO: should read from the sessions config
//or be invoked from the bootstrapper
expireSessionsIndex.ExpireAfter = 1 * time.Hour
expireSessionsIndex.Key = []string{"expiry"}
sessions.EnsureIndex(expireSessionsIndex)
}
示例3: Index
// Index creates the default indeces for the graph.
func (m *Mongo) Index(gid string, background bool) error {
m.Session.ResetIndexCache()
sessionCopy := m.Session.Copy()
defer sessionCopy.Close()
col := sessionCopy.DB(m.DBName).C(gid)
cInfo := &mgo.CollectionInfo{DisableIdIndex: true}
err := col.Create(cInfo)
if err != nil {
log.Error(err)
}
/*
// TODO figure out the magic of mongo indexes
index := mgo.Index{
Key: []string{"g", "s", "p", "o"},
Background: false,
Sparse: true,
Unique: true,
DropDups: true,
}
err := col.EnsureIndex(index)
return err
*/
index := mgo.Index{
Key: []string{"g", "s"},
Background: background,
Sparse: true,
}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "o"}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "p"}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "s", "p"}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "s", "o"}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "p", "o"}
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
index.Key = []string{"g", "s", "p", "o"}
index.Unique = true
index.DropDups = true
err = col.EnsureIndex(index)
if err != nil {
log.Error(err)
//return err
}
log.V(2).Infof("%+v", index)
return nil
}