★★★★★
#앱별 실전 패턴 · claude-code
[we_are_tonged] 매칭 알고리즘 (조건 기반)
통했어요 앱: 서로의 마음을 확인하는 매칭. 조건 기반 알고리즘.
#we-are-tonged#matching#algorithm
통했어요 앱: 서로의 마음을 확인하는 매칭. 조건 기반 알고리즘.
매칭 조건 예시:
- 나이: ±3세
- 지역: 같은 지역 또는 인근
- 관심사: 2개 이상 겹침
- 성격 유형: MBTI 호환도
구현:
```dart
class MatchingService {
static Future<List<User>> findMatches(User currentUser) async {
// 1단계: 나이 조건
final ageMin = currentUser.age - 3;
final ageMax = currentUser.age + 3;
var query = db.collection('users')
.where('gender', isEqualTo: currentUser.preferredGender)
.where('age', isGreaterThanOrEqualTo: ageMin)
.where('age', isLessThanOrEqualTo: ageMax);
final candidates = await query.get();
// 2단계: 클라이언트에서 추가 필터링
final matches = <User>[];
for (final doc in candidates.docs) {
final user = User.fromDoc(doc);
// 지역 필터
if (!_isNearby(currentUser.location, user.location)) continue;
// 관심사 겹침 확인
final commonInterests = _getCommonInterests(
currentUser.interests,
user.interests,
);
if (commonInterests.length < 2) continue;
// MBTI 호환도
final compatibility = _calculateMBTICompatibility(
currentUser.mbti,
user.mbti,
);
if (compatibility < 0.6) continue;
matches.add(user);
}
return matches;
}
static bool _isNearby(Location loc1, Location loc2) {
final distance = _calculateDistance(loc1, loc2);
return distance <= 50; // 50km 이내
}
static List<String> _getCommonInterests(List<String> interests1, List<String> interests2) {
return interests1.where((i) => interests2.contains(i)).toList();
}
static double _calculateMBTICompatibility(String mbti1, String mbti2) {
// 호환도 계산 로직 (0~1)
// 예: ENFP ↔ INTJ = 0.8
return 0.7; // 임시값
}
static double _calculateDistance(Location loc1, Location loc2) {
// Haversine 공식으로 거리 계산
return 0; // 임시값
}
}
```
구현해줄까?
쓰는 법 — 위 칸에 본인 값을 채우면 아래 프롬프트에 바로 반영돼요. 복사 버튼을 누르면 채워진 그대로 클립보드에 담기니까, claude-code(또는 본인이 쓰는 AI)에 붙여넣기만 하면 됩니다. 변수가 없으면 그냥 복사해서 쓰세요.

