[iOS][core] Add branch to search result list

Signed-off-by: eisa01 <eisa01@gmail.com>
This commit is contained in:
eisa01
2025-08-25 20:51:59 +02:00
committed by Konstantin Pastbin
parent c9214d3130
commit c039d599e4
6 changed files with 33 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSUInteger index; @property (nonatomic, readonly) NSUInteger index;
@property (nonatomic, readonly) NSString * titleText; @property (nonatomic, readonly) NSString * titleText;
@property (nonatomic, readonly, nullable) NSString * branchText;
@property (nonatomic, readonly) NSString * iconImageName; @property (nonatomic, readonly) NSString * iconImageName;
@property (nonatomic, readonly) NSString * addressText; @property (nonatomic, readonly) NSString * addressText;
@property (nonatomic, readonly) NSString * infoText; @property (nonatomic, readonly) NSString * infoText;

View File

@@ -33,6 +33,7 @@
_titleText = result.GetString().empty() ? @(result.GetLocalizedFeatureType().c_str()) : @(result.GetString().c_str()); _titleText = result.GetString().empty() ? @(result.GetLocalizedFeatureType().c_str()) : @(result.GetString().c_str());
_addressText = @(result.GetAddress().c_str()); _addressText = @(result.GetAddress().c_str());
_infoText = @(result.GetFeatureDescription().c_str()); _infoText = @(result.GetFeatureDescription().c_str());
_branchText = result.GetBranch().empty() ? nil : @(result.GetBranch().c_str());
if (result.IsSuggest()) if (result.IsSuggest())
_suggestion = @(result.GetSuggestionString().c_str()); _suggestion = @(result.GetSuggestionString().c_str());

View File

@@ -25,6 +25,7 @@
self.titleLabel.text = title; self.titleLabel.text = title;
return; return;
} }
NSMutableAttributedString * attributedTitle = NSMutableAttributedString * attributedTitle =
[[NSMutableAttributedString alloc] initWithString:title]; [[NSMutableAttributedString alloc] initWithString:title];
NSDictionary * titleAttributes = isPartialMatching ? unselectedTitleAttributes : selectedTitleAttributes; NSDictionary * titleAttributes = isPartialMatching ? unselectedTitleAttributes : selectedTitleAttributes;
@@ -40,6 +41,18 @@
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText); NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText);
} }
} }
// Add branch with thinner font weight if present and not already in title
if (result.branchText && result.branchText.length > 0 && ![title containsString:result.branchText]) {
NSDictionary * branchAttributes = isPartialMatching ? unselectedTitleAttributes : @{
NSForegroundColorAttributeName : [selectedTitleAttributes objectForKey:NSForegroundColorAttributeName],
NSFontAttributeName : [UIFont regular17]
};
NSAttributedString * branchString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", result.branchText]
attributes:branchAttributes];
[attributedTitle appendAttributedString:branchString];
}
self.titleLabel.attributedText = attributedTitle; self.titleLabel.attributedText = attributedTitle;
[self.titleLabel sizeToFit]; [self.titleLabel sizeToFit];
} }

View File

@@ -732,6 +732,16 @@ Result Ranker::MakeResult(RankerResult const & rankerResult, bool needAddress, b
case RankerResult::Type::Building: case RankerResult::Type::Building:
res.FromFeature(rankerResult.GetID(), rankerResult.GetBestType(), res.FromFeature(rankerResult.GetID(), rankerResult.GetBestType(),
rankerResult.GetBestType(&m_params.m_preferredTypes), rankerResult.m_details); rankerResult.GetBestType(&m_params.m_preferredTypes), rankerResult.m_details);
// Extract branch metadata if available
if (rankerResult.GetID().IsValid())
{
m_dataSource.ReadFeature([&](FeatureType & ft) {
auto const branch = ft.GetMetadata(feature::Metadata::FMD_BRANCH);
if (!branch.empty())
res.SetBranch(std::string(branch));
}, rankerResult.GetID());
}
break; break;
case RankerResult::Type::LatLon: res.SetType(Result::Type::LatLon); break; case RankerResult::Type::LatLon: res.SetType(Result::Type::LatLon); break;
case RankerResult::Type::Postcode: res.SetType(Result::Type::Postcode); break; case RankerResult::Type::Postcode: res.SetType(Result::Type::Postcode); break;

View File

@@ -134,6 +134,11 @@ string const & Result::GetSuggestionString() const
return m_suggestionStr; return m_suggestionStr;
} }
string Result::GetBranch() const
{
return m_branch;
}
bool Result::IsEqualSuggest(Result const & r) const bool Result::IsEqualSuggest(Result const & r) const
{ {
return m_suggestionStr == r.m_suggestionStr; return m_suggestionStr == r.m_suggestionStr;

View File

@@ -62,6 +62,7 @@ public:
void FromFeature(FeatureID const & id, uint32_t mainType, uint32_t matchedType, Details const & details); void FromFeature(FeatureID const & id, uint32_t mainType, uint32_t matchedType, Details const & details);
void SetAddress(std::string && address) { m_address = std::move(address); } void SetAddress(std::string && address) { m_address = std::move(address); }
void SetBranch(std::string && branch) { m_branch = std::move(branch); }
void SetType(Result::Type type) { m_resultType = type; } void SetType(Result::Type type) { m_resultType = type; }
// For Type::PureSuggest. // For Type::PureSuggest.
@@ -75,6 +76,7 @@ public:
std::string const & GetString() const { return m_str; } std::string const & GetString() const { return m_str; }
std::string const & GetAddress() const { return m_address; } std::string const & GetAddress() const { return m_address; }
std::string const & GetDescription() const { return m_details.m_description; } std::string const & GetDescription() const { return m_details.m_description; }
std::string GetBranch() const;
osm::YesNoUnknown IsOpenNow() const { return m_details.m_isOpenNow; } osm::YesNoUnknown IsOpenNow() const { return m_details.m_isOpenNow; }
uint16_t GetMinutesUntilOpen() const { return m_details.m_minutesUntilOpen; } uint16_t GetMinutesUntilOpen() const { return m_details.m_minutesUntilOpen; }
@@ -152,6 +154,7 @@ private:
m2::PointD m_center; m2::PointD m_center;
std::string m_str; std::string m_str;
std::string m_address; std::string m_address;
std::string m_branch;
uint32_t m_mainType = 0; uint32_t m_mainType = 0;
uint32_t m_matchedType = 0; uint32_t m_matchedType = 0;
std::string m_suggestionStr; std::string m_suggestionStr;