@@ -26,15 +26,63 @@ func ValidateGameSearchRequest(dtoBytes []byte) (*schema.GameSearchRequestDto, e
26
26
// buildManticoreMatchString
27
27
// Builds the string to be inserted in the 'match' SQL function.
28
28
func buildManticoreMatchString (dto * schema.GameSearchRequestDto ) (string , error ) {
29
+ var matchString string
29
30
query := & dto .Query
31
+ genres := dto .Genres
32
+ themes := dto .Themes
33
+ platforms := dto .Platforms
30
34
31
35
if query == nil {
32
36
return "" , errors .New ("query parameter empty" )
33
37
}
34
38
35
39
parsedQuery := parseQuery (* query )
36
40
37
- return parsedQuery , nil
41
+ // Matches name and alternative_names fields
42
+ matchString = fmt .Sprintf ("@(name,alternative_names) %s" , parsedQuery )
43
+ var genresMatchString = ""
44
+ var themesMatchString = ""
45
+ var platformsMatchString = ""
46
+
47
+ if genres != nil && len (* genres ) > 0 {
48
+ genresMatchString = " @genres_names "
49
+ for i , v := range * genres {
50
+ if i > 0 {
51
+ genresMatchString = fmt .Sprintf ("%s|%s" , genresMatchString , v )
52
+ continue
53
+ }
54
+ genresMatchString = fmt .Sprintf ("%s%s" , genresMatchString , v )
55
+ }
56
+
57
+ }
58
+
59
+ if themes != nil && len (* themes ) > 0 {
60
+ themesMatchString = " @themes_names "
61
+ for i , v := range * themes {
62
+ if i > 0 {
63
+ themesMatchString = fmt .Sprintf ("%s|%s" , themesMatchString , v )
64
+ continue
65
+ }
66
+ themesMatchString = fmt .Sprintf ("%s|%s" , themesMatchString , v )
67
+ }
68
+
69
+ }
70
+
71
+ if platforms != nil && len (* platforms ) > 0 {
72
+ platformsMatchString = " @(platforms_names,platforms_abbreviations) "
73
+ for i , v := range * platforms {
74
+ if i > 0 {
75
+ platformsMatchString = fmt .Sprintf ("%s|%s" , platformsMatchString , v )
76
+ continue
77
+ }
78
+ platformsMatchString = fmt .Sprintf ("%s%s" , platformsMatchString , v )
79
+ }
80
+ }
81
+
82
+ finalMatchString := fmt .Sprintf ("%s%s%s%s" , matchString , genresMatchString , themesMatchString , platformsMatchString )
83
+
84
+ return finalMatchString , nil
85
+
38
86
}
39
87
40
88
func buildManticoreFilterString (dto * schema.GameSearchRequestDto ) (string , error ) {
@@ -94,11 +142,11 @@ func buildManticoreOrderString() string {
94
142
func buildManticoreSearchRequest (dto * schema.GameSearchRequestDto ) (string , error ) {
95
143
96
144
matchString , _ := buildManticoreMatchString (dto )
97
- // filterString, _ := buildManticoreFilterString(dto)
98
- // paginationString := buildManticorePaginationString(dto)
99
- // orderString := buildManticoreOrderString()
145
+ filterString , _ := buildManticoreFilterString (dto )
146
+ paginationString := buildManticorePaginationString (dto )
147
+ orderString := buildManticoreOrderString ()
100
148
101
- selectString := fmt .Sprintf ("SELECT * FROM games WHERE match('%s') OPTION fuzzy=1 ;" , matchString )
149
+ selectString := fmt .Sprintf ("SELECT * FROM games WHERE match('%s') %s %s %s ;" , matchString , filterString , orderString , paginationString )
102
150
103
151
return selectString , nil
104
152
0 commit comments