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

在Yuka js库中,FuzzyOR是一个用于模糊查询的方法。它允许我们通过一系列项来查找与查询字符串相关的内容。FuzzyOR中的terms(项)是指FuzzyOR方法中的一个参数,它是一个包含一系列查询项的数组。

属性

terms参数包含以下属性:

  • query:查询字符串。
  • minimumShouldMatch:匹配的最小数量(可选)。默认值为0。

使用示例

下面是一个使用terms参数的FuzzyOR方法的示例:

import { FuzzyOR } from 'yuka';

const items = [
    { content: 'Hello World' },
    { content: 'Foo Bar' }
];

const searchString = 'Hello'; // 查询字符串

const query = [
    { key: 'content', value: searchString }
];

const results = new FuzzyOR().setTerms(query).search(items);

console.log(results);
// Output: [{ content: 'Hello World' }]

在上面的代码示例中,我们使用了FuzzyOR方法中的terms参数进行模糊查询。我们使用{key: 'content', value: searchString}来表示查询项,其中'key'是我们想要匹配的数组元素的属性,'value'是我们正在查找的字符串。因为我们使用了FuzzyOR方法,所以即使查询字符串不完全匹配,也可以找到相关的项。在上面的示例中,我们使用了'Hello'作为查询字符串,因此我们得到了{ content: 'Hello World' }作为结果。

除了查询字符串,我们还可以指定minimumShouldMatch属性来与至少一定数量的项匹配。例如,如果我们想要查找与两个查询字符串中至少有一个匹配的项,我们可以将minimumShouldMatch属性设置为2,如下所示:

const query = [
    { key: 'content', value: 'Hello' },
    { key: 'content', value: 'Bar' }
];

const results = new FuzzyOR().setTerms(query, { minimumShouldMatch: 2 }).search(items);

console.log(results);
// Output: [{ content: 'Hello World' }, { content: 'Foo Bar' }]

通过将minimumShouldMatch设置为2,我们指定了必须至少匹配query数组中两个查询项才能返回结果。在上面的示例中,因为数组中有两个查询项都匹配成功,所以我们获得了两个结果:{ content: 'Hello World' }{ content: 'Foo Bar' }

以上就是关于terms参数的说明,使用FuzzyOR方法可以更方便的进行模糊查询。