Forráskód Böngészése

修正当数据类型为LocationsIndex时,搜索结果异常的bug

faberliu 9 éve
szülő
commit
da4d0fa659
2 módosított fájl, 13 hozzáadás és 5 törlés
  1. 5 3
      core/indexer.go
  2. 8 2
      engine/segmenter_worker.go

+ 5 - 3
core/indexer.go

@@ -1,11 +1,12 @@
 package core
 
 import (
-	"github.com/huichen/wukong/types"
-	"github.com/huichen/wukong/utils"
 	"log"
 	"math"
 	"sync"
+
+	"github.com/huichen/wukong/types"
+	"github.com/huichen/wukong/utils"
 )
 
 // 索引器
@@ -229,7 +230,8 @@ func (indexer *Indexer) Lookup(
 						})
 					}
 					numDocs++
-					break
+					//当某个关键字对应多个文档且有lable关键字存在时,若直接break,将会丢失相当一部分搜索结果
+					continue
 				}
 
 				// 计算搜索键在文档中的紧邻距离

+ 8 - 2
engine/segmenter_worker.go

@@ -41,10 +41,16 @@ func (engine *Engine) segmenterWorker() {
 		for _, label := range request.data.Labels {
 			if !engine.initOptions.NotUsingSegmenter {
 				if !engine.stopTokens.IsStopToken(label) {
-					tokensMap[label] = []int{}
+					//当正文中已存在关键字时,若不判断,位置信息将会丢失
+					if _, ok := tokensMap[label]; !ok {
+						tokensMap[label] = []int{}
+					}
 				}
 			} else {
-				tokensMap[label] = []int{}
+				//当正文中已存在关键字时,若不判断,位置信息将会丢失
+				if _, ok := tokensMap[label]; !ok {
+					tokensMap[label] = []int{}
+				}
 			}
 		}