parent
fcf9b1eb8d
commit
8e82ee3702
5 changed files with 26 additions and 15 deletions
|
@ -91,11 +91,15 @@ func addBook(coll *mgo.Collection, book map[string]interface{}) error {
|
|||
}
|
||||
|
||||
func getBooks(coll *mgo.Collection, query string, length int, start int) (books []Book, num int, err error) {
|
||||
return _getBooks(coll, buildQuery(query), length, start)
|
||||
q := buildQuery(query)
|
||||
q["active"] = true
|
||||
return _getBooks(coll, q, length, start)
|
||||
}
|
||||
|
||||
func getNewBooks(coll *mgo.Collection, length int, start int) (books []Book, num int, err error) {
|
||||
return _getBooks(coll, bson.M{"$nor": []bson.M{{"active": true}}}, length, start)
|
||||
func getNewBooks(coll *mgo.Collection, query string, length int, start int) (books []Book, num int, err error) {
|
||||
q := buildQuery(query)
|
||||
q["$nor"] = []bson.M{{"active": true}}
|
||||
return _getBooks(coll, q, length, start)
|
||||
}
|
||||
|
||||
func getBooksIter(coll *mgo.Collection) Iter {
|
||||
|
@ -193,7 +197,7 @@ func isBookActive(coll *mgo.Collection, id string) bool {
|
|||
|
||||
func buildQuery(q string) bson.M {
|
||||
text := ""
|
||||
query := bson.M{"active": true}
|
||||
query := bson.M{}
|
||||
words := strings.Split(q, " ")
|
||||
for _, w := range words {
|
||||
tag := strings.SplitN(w, ":", 2)
|
||||
|
|
Reference in a new issue