浏览代码

在goroutine worker里不要用return

Hui Chen 10 年之前
父节点
当前提交
e1b46affa8
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 5 2
      core/indexer.go
  2. 1 1
      engine/indexer_worker.go

+ 5 - 2
core/indexer.go

@@ -176,6 +176,9 @@ func (indexer *Indexer) Lookup(
 	for ; indexPointers[0] >= 0; indexPointers[0]-- {
 		// 以第一个搜索键出现的文档作为基准,并遍历其他搜索键搜索同一文档
 		baseDocId := indexer.getDocId(table[0], indexPointers[0])
+		if _, ok := indexer.tableLock.docs[baseDocId]; !ok {
+			continue
+		}
 
 		if docIds != nil {
 			_, found := docIds[baseDocId]
@@ -208,8 +211,7 @@ func (indexer *Indexer) Lookup(
 			}
 		}
 
-		_, ok := indexer.tableLock.docs[baseDocId]
-		if found && ok {
+		if found {
 			indexedDoc := types.IndexedDocument{}
 
 			// 当为LocationsIndex时计算关键词紧邻距离
@@ -418,5 +420,6 @@ func (indexer *Indexer) RemoveDoc(docId uint64) {
 
 	indexer.tableLock.Lock()
 	delete(indexer.tableLock.docs, docId)
+	indexer.numDocuments--
 	indexer.tableLock.Unlock()
 }

+ 1 - 1
engine/indexer_worker.go

@@ -47,7 +47,7 @@ func (engine *Engine) indexerLookupWorker(shard int) {
 
 		if request.countDocsOnly {
 			request.rankerReturnChannel <- rankerReturnRequest{numDocs: numDocs}
-			return
+			continue
 		}
 
 		if len(docs) == 0 {