ranker_worker.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2013 Hui Chen
  2. // Copyright 2016 ego authors
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  5. // not use this file except in compliance with the License. You may obtain
  6. // a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. // License for the specific language governing permissions and limitations
  14. // under the License.
  15. package riot
  16. import (
  17. "github.com/go-ego/riot/types"
  18. )
  19. type rankerAddDocReq struct {
  20. docId uint64
  21. fields interface{}
  22. // new
  23. content string
  24. // new 属性
  25. attri interface{}
  26. }
  27. type rankerRankReq struct {
  28. docs []types.IndexedDoc
  29. options types.RankOpts
  30. rankerReturnChan chan rankerReturnReq
  31. countDocsOnly bool
  32. }
  33. type rankerReturnReq struct {
  34. // docs types.ScoredDocs
  35. docs interface{}
  36. numDocs int
  37. }
  38. type rankerRemoveDocReq struct {
  39. docId uint64
  40. }
  41. func (engine *Engine) rankerAddDocWorker(shard int) {
  42. for {
  43. request := <-engine.rankerAddDocChans[shard]
  44. if engine.initOptions.IDOnly {
  45. engine.rankers[shard].AddDoc(request.docId, request.fields)
  46. return
  47. }
  48. // } else {
  49. engine.rankers[shard].AddDoc(request.docId, request.fields,
  50. request.content, request.attri)
  51. // }
  52. }
  53. }
  54. func (engine *Engine) rankerRankWorker(shard int) {
  55. for {
  56. request := <-engine.rankerRankChans[shard]
  57. if request.options.MaxOutputs != 0 {
  58. request.options.MaxOutputs += request.options.OutputOffset
  59. }
  60. request.options.OutputOffset = 0
  61. outputDocs, numDocs := engine.rankers[shard].Rank(request.docs,
  62. request.options, request.countDocsOnly)
  63. request.rankerReturnChan <- rankerReturnReq{
  64. docs: outputDocs, numDocs: numDocs}
  65. }
  66. }
  67. func (engine *Engine) rankerRemoveDocWorker(shard int) {
  68. for {
  69. request := <-engine.rankerRemoveDocChans[shard]
  70. engine.rankers[shard].RemoveDoc(request.docId)
  71. }
  72. }