Skip to content

Commit

Permalink
19429: Fixes issue where zero weighted features sometimes apply featu…
Browse files Browse the repository at this point in the history
…re attributes for incorrect features in queries (#82)
  • Loading branch information
howsohazard authored Feb 25, 2024
1 parent 008194b commit fb3f2af
Show file tree
Hide file tree
Showing 2 changed files with 1,043 additions and 996 deletions.
49 changes: 48 additions & 1 deletion src/Amalgam/entity/EntityQueryBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ namespace EntityQueryBuilder
}

//select based on type for position or entities
if(DoesDistanceQueryUseEntitiesInsteadOfPosition(condition_type))
bool use_entities_instead_of_position = DoesDistanceQueryUseEntitiesInsteadOfPosition(condition_type);
if(use_entities_instead_of_position)
{
EvaluableNode *entities = ocn[POSITION];
if(EvaluableNode::IsOrderedArray(entities))
Expand Down Expand Up @@ -429,6 +430,52 @@ namespace EntityQueryBuilder
}
}
}

//check for any unused features -- that is, zero weight. if there are any,
//then insert an existance query for them and remove from the distance query
bool any_unused_feature = false;
for(size_t i = 0; i < cur_condition->distParams.featureParams.size(); i++)
{
if(!cur_condition->distParams.IsFeatureEnabled(i))
{
any_unused_feature = true;
break;
}
}

if(any_unused_feature)
{
auto exist_condition_iter = conditions.emplace(end(conditions) - 1);
EntityQueryCondition *exist_condition = &(*exist_condition_iter);
//update pointer since it changed
cur_condition = &(conditions.back());

exist_condition->queryType = ENT_QUERY_EXISTS;

for(size_t i = 0; i < cur_condition->positionLabels.size();)
{
if(cur_condition->distParams.IsFeatureEnabled(i))
{
i++;
}
else
{
//add label to the exist_condition
auto label_sid = cur_condition->positionLabels[i];
exist_condition->existLabels.push_back(label_sid);

//remove label
cur_condition->distParams.featureParams.erase(begin(cur_condition->distParams.featureParams) + i);
cur_condition->positionLabels.erase(begin(cur_condition->positionLabels) + i);

if(!use_entities_instead_of_position)
{
cur_condition->valueToCompare.erase(begin(cur_condition->valueToCompare) + i);
cur_condition->valueTypes.erase(begin(cur_condition->valueTypes) + i);
}
}
}
}
}

//builds a query condition from cn
Expand Down
Loading

0 comments on commit fb3f2af

Please sign in to comment.