@@ -16,9 +16,18 @@ func (s *GrpcServer) FindMatchingQuestion(ctx context.Context, req *pb.MatchQues
1616
1717 var docs []* firestore.DocumentSnapshot
1818
19+ matchedDifficulties := make ([]models.ComplexityType , len (req .MatchedDifficulties ))
20+ for i := range req .MatchedDifficulties {
21+ d , err := models .ParseComplexity (req .MatchedDifficulties [i ])
22+ if err != nil {
23+ return nil , err
24+ }
25+ matchedDifficulties [i ] = d
26+ }
27+
1928 // 1. Match by both topic and difficulty
2029 if len (docs ) == 0 {
21- d , err := queryTopicAndDifficultyQuestion (s .Client , ctx , req .MatchedTopics )
30+ d , err := queryTopicAndDifficultyQuestion (s .Client , ctx , req .MatchedTopics , matchedDifficulties )
2231 if err != nil {
2332 return nil , err
2433 }
@@ -36,7 +45,7 @@ func (s *GrpcServer) FindMatchingQuestion(ctx context.Context, req *pb.MatchQues
3645
3746 // 3. Match by difficulty
3847 if len (docs ) == 0 {
39- d , err := queryDifficultyQuestion (s .Client , ctx )
48+ d , err := queryDifficultyQuestion (s .Client , ctx , matchedDifficulties )
4049 if err != nil {
4150 return nil , err
4251 }
@@ -78,16 +87,16 @@ func (s *GrpcServer) FindMatchingQuestion(ctx context.Context, req *pb.MatchQues
7887 }, nil
7988}
8089
81- func queryTopicAndDifficultyQuestion (client * firestore.Client , ctx context.Context , topics []string , difficulties []string ) ([]* firestore.DocumentSnapshot , error ) {
82- return client .Collection ("questions" ).Where ("categories " , "in" , topics ).Documents (ctx ).GetAll ()
90+ func queryTopicAndDifficultyQuestion (client * firestore.Client , ctx context.Context , topics []string , difficulties []models. ComplexityType ) ([]* firestore.DocumentSnapshot , error ) {
91+ return client .Collection ("questions" ).Where ("complexity " , "in" , difficulties ). Where ( "categories" , "array-contains-any " , topics ).Documents (ctx ).GetAll ()
8392}
8493
8594func queryTopicQuestion (client * firestore.Client , ctx context.Context , topics []string ) ([]* firestore.DocumentSnapshot , error ) {
8695 return client .Collection ("questions" ).Where ("categories" , "array-contains-any" , topics ).Documents (ctx ).GetAll ()
8796}
8897
89- func queryDifficultyQuestion (client * firestore.Client , ctx context.Context , difficulties []string ) ([]* firestore.DocumentSnapshot , error ) {
90- return client .Collection ("questions" ).Where ("categories " , "in" , difficulties ).Documents (ctx ).GetAll ()
98+ func queryDifficultyQuestion (client * firestore.Client , ctx context.Context , difficulties []models. ComplexityType ) ([]* firestore.DocumentSnapshot , error ) {
99+ return client .Collection ("questions" ).Where ("complexity " , "in" , difficulties ).Documents (ctx ).GetAll ()
91100
92101}
93102
0 commit comments