Beispiel #1
0
// 索引博文
func IndexingArticle(isAll bool) {
	solrClient := NewSolrClient()

	articleObj := model.NewArticle()

	limit := strconv.Itoa(MaxRows)
	if isAll {
		id := 0
		for {
			articleList, err := articleObj.Where("id>? AND status!=?", id, model.StatusOffline).Limit(limit).FindAll()
			if err != nil {
				logger.Errorln("IndexingArticle error:", err)
				break
			}

			if len(articleList) == 0 {
				break
			}

			for _, article := range articleList {
				if id < article.Id {
					id = article.Id
				}

				document := model.NewDocument(article, nil)
				addCommand := model.NewDefaultArgsAddCommand(document)

				solrClient.Push(addCommand)
			}

			solrClient.Post()
		}
	}
}
Beispiel #2
0
// 索引帖子
func IndexingTopic(isAll bool) {
	solrClient := NewSolrClient()

	topicObj := model.NewTopic()
	topicExObj := model.NewTopicEx()

	limit := strconv.Itoa(MaxRows)
	if isAll {
		id := 0
		for {
			topicList, err := topicObj.Where("tid>?", id).Limit(limit).FindAll()
			if err != nil {
				logger.Errorln("IndexingTopic error:", err)
				break
			}

			if len(topicList) == 0 {
				break
			}

			tids := util.Models2Intslice(topicList, "Tid")

			tmpStr := strings.Repeat("?,", len(tids))
			query := "tid in(" + tmpStr[:len(tmpStr)-1] + ")"
			args := make([]interface{}, len(tids))
			for i, tid := range tids {
				args[i] = tid
			}

			topicExList, err := topicExObj.Where(query, args...).FindAll()
			if err != nil {
				logger.Errorln("IndexingTopic error:", err)
				break
			}

			topicExMap := make(map[int]*model.TopicEx, len(topicExList))
			for _, topicEx := range topicExList {
				topicExMap[topicEx.Tid] = topicEx
			}

			for _, topic := range topicList {
				if id < topic.Tid {
					id = topic.Tid
				}

				topicEx, _ := topicExMap[topic.Tid]

				document := model.NewDocument(topic, topicEx)
				addCommand := model.NewDefaultArgsAddCommand(document)

				solrClient.Push(addCommand)
			}

			solrClient.Post()
		}
	}
}
Beispiel #3
0
// 索引资源
func IndexingResource(isAll bool) {
	solrClient := NewSolrClient()

	resourceObj := model.NewResource()
	resourceExObj := model.NewResourceEx()

	limit := strconv.Itoa(MaxRows)
	if isAll {
		id := 0
		for {
			resourceList, err := resourceObj.Where("id>?", id).Limit(limit).FindAll()
			if err != nil {
				logger.Errorln("IndexingResource error:", err)
				break
			}

			if len(resourceList) == 0 {
				break
			}

			ids := util.Models2Intslice(resourceList, "Id")

			tmpStr := strings.Repeat("?,", len(ids))
			query := "id in(" + tmpStr[:len(tmpStr)-1] + ")"
			args := make([]interface{}, len(ids))
			for i, rid := range ids {
				args[i] = rid
			}

			resourceExList, err := resourceExObj.Where(query, args...).FindAll()
			if err != nil {
				logger.Errorln("IndexingResource error:", err)
				break
			}

			resourceExMap := make(map[int]*model.ResourceEx, len(resourceExList))
			for _, resourceEx := range resourceExList {
				resourceExMap[resourceEx.Id] = resourceEx
			}

			for _, resource := range resourceList {
				if id < resource.Id {
					id = resource.Id
				}

				resourceEx, _ := resourceExMap[resource.Id]

				document := model.NewDocument(resource, resourceEx)
				addCommand := model.NewDefaultArgsAddCommand(document)

				solrClient.Push(addCommand)
			}

			solrClient.Post()
		}
	}
}
Beispiel #4
0
// 索引主题
func (self SearcherLogic) IndexingTopic(isAll bool) {
	solrClient := NewSolrClient()

	var (
		topicList   []*model.Topic
		topicExList map[int]*model.TopicEx

		err error
	)

	if isAll {
		id := 0
		for {
			topicList = make([]*model.Topic, 0)
			topicExList = make(map[int]*model.TopicEx)

			err = MasterDB.Where("tid>?", id).OrderBy("tid ASC").Limit(self.maxRows).Find(&topicList)
			if err != nil {
				logger.Errorln("IndexingTopic error:", err)
				break
			}

			if len(topicList) == 0 {
				break
			}

			tids := util.Models2Intslice(topicList, "Tid")

			err = MasterDB.In("tid", tids).Find(&topicExList)
			if err != nil {
				logger.Errorln("IndexingTopic error:", err)
				break
			}

			for _, topic := range topicList {
				if id < topic.Tid {
					id = topic.Tid
				}

				topicEx := topicExList[topic.Tid]

				document := model.NewDocument(topic, topicEx)
				addCommand := model.NewDefaultArgsAddCommand(document)

				solrClient.PushAdd(addCommand)
			}

			solrClient.Post()
		}
	}
}
Beispiel #5
0
// 索引资源
func (self SearcherLogic) IndexingResource(isAll bool) {
	solrClient := NewSolrClient()

	var (
		resourceList   []*model.Resource
		resourceExList map[int]*model.ResourceEx
		err            error
	)

	if isAll {
		id := 0
		for {
			resourceList = make([]*model.Resource, 0)
			resourceExList = make(map[int]*model.ResourceEx)

			err = MasterDB.Where("id>?", id).OrderBy("id ASC").Limit(self.maxRows).Find(&resourceList)
			if err != nil {
				logger.Errorln("IndexingResource error:", err)
				break
			}

			if len(resourceList) == 0 {
				break
			}

			ids := util.Models2Intslice(resourceList, "Id")

			err = MasterDB.In("id", ids).Find(&resourceExList)
			if err != nil {
				logger.Errorln("IndexingResource error:", err)
				break
			}

			for _, resource := range resourceList {
				if id < resource.Id {
					id = resource.Id
				}

				resourceEx := resourceExList[resource.Id]

				document := model.NewDocument(resource, resourceEx)
				addCommand := model.NewDefaultArgsAddCommand(document)

				solrClient.PushAdd(addCommand)
			}

			solrClient.Post()
		}
	}
}
Beispiel #6
0
// IndexingArticle 索引博文
func (self SearcherLogic) IndexingArticle(isAll bool) {
	solrClient := NewSolrClient()

	var (
		articleList []*model.Article
		err         error
	)

	if isAll {
		id := 0
		for {
			articleList = make([]*model.Article, 0)
			err = MasterDB.Where("id>?", id).Limit(self.maxRows).OrderBy("id ASC").Find(&articleList)
			if err != nil {
				logger.Errorln("IndexingArticle error:", err)
				break
			}

			if len(articleList) == 0 {
				break
			}

			for _, article := range articleList {
				if id < article.Id {
					id = article.Id
				}

				document := model.NewDocument(article, nil)
				if article.Status != model.ArticleStatusOffline {
					solrClient.PushAdd(model.NewDefaultArgsAddCommand(document))
				} else {
					solrClient.PushDel(model.NewDelCommand(document))
				}
			}

			solrClient.Post()
		}
	}
}