Skip to content

Commit f384cc1

Browse files
author
=
committed
discard changes, wip
1 parent 2f3b4d4 commit f384cc1

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

schema/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ type GameSearchRequestDto struct {
154154
Query string `json:"query"`
155155
Category *[]int `json:"category,omitempty"`
156156
Status *[]int `json:"status,omitempty"`
157+
Genres *[]string `json:"genres"`
158+
Themes *[]string `json:"themes"`
159+
Platforms *[]string `json:"platforms"`
157160
Limit *int `json:"limit,omitempty"`
158161
Page *int `json:"page,omitempty"`
159162
Profile *bool `json:"profile,omitempty"`

search/games/search_games.go

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,63 @@ func ValidateGameSearchRequest(dtoBytes []byte) (*schema.GameSearchRequestDto, e
2626
// buildManticoreMatchString
2727
// Builds the string to be inserted in the 'match' SQL function.
2828
func buildManticoreMatchString(dto *schema.GameSearchRequestDto) (string, error) {
29+
var matchString string
2930
query := &dto.Query
31+
genres := dto.Genres
32+
themes := dto.Themes
33+
platforms := dto.Platforms
3034

3135
if query == nil {
3236
return "", errors.New("query parameter empty")
3337
}
3438

3539
parsedQuery := parseQuery(*query)
3640

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+
3886
}
3987

4088
func buildManticoreFilterString(dto *schema.GameSearchRequestDto) (string, error) {
@@ -94,11 +142,11 @@ func buildManticoreOrderString() string {
94142
func buildManticoreSearchRequest(dto *schema.GameSearchRequestDto) (string, error) {
95143

96144
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()
100148

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)
102150

103151
return selectString, nil
104152

0 commit comments

Comments
 (0)