AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

terms

描述

terms 是 FuzzyAND 算法的一部分,它用于表示搜索词汇的模糊匹配项。具体来说,terms 包含多个词汇和它们的权重,这些词汇和权重会被用来计算搜索结果的相似程度。

用法

terms 对象是一个包含多个键值对的 JavaScript 对象。每个键值对都表示一个搜索词汇和它的权重。键表示搜索词汇,值表示搜索词汇的权重,权重越高,搜索结果与关键词的匹配度越高。

以下是一个示例 terms 对象:

{
  "牛肉": 10,
  "鸡肉": 7,
  "土豆": 5
}

在该示例中,terms 对象包含了三个词汇,它们分别是 "牛肉"、"鸡肉" 和 "土豆",它们的权重为 10、7 和 5。这意味着如果搜索结果中包含 "牛肉",该搜索结果将比包含 "鸡肉" 或 "土豆" 更相似。

注意事项

  • terms 中的词汇应该尽可能地与搜索关键词相关。
  • 权重的值应根据词汇的重要性适当调整。
  • terms 中的词汇应该是全小写的。
  • terms 对象应该作为 FuzzyAND 算法的参数传递。

示例

const articles = [
  {
    title: "糖醋排骨的做法",
    content: "糖醋排骨既香又甜,是一道深受大家喜欢的经典家常菜。"
  },
  {
    title: "黑椒牛肉的做法",
    content: "黑椒牛肉是一道重口味的美食,牛肉粒鲜嫩,口感极佳。"
  },
  {
    title: "蒜蓉土豆泥的做法",
    content: "蒜蓉土豆泥是一道非常健康的素食菜品,富含多种维生素和纤维素。"
  }
]

const keyword = "牛肉 黑椒"

const terms = {
  "牛肉": 10,
  "黑椒": 7
}

const fuzzy = new FuzzyAND(articles, terms)
const result = fuzzy.search(keyword)

console.log(result)
// 输出: [{ title: "黑椒牛肉的做法", content: "黑椒牛肉是一道重口味的美食,牛肉粒鲜嫩,口感极佳。" }]