Skip to content

Commit

Permalink
finishing work for tonight
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-brennan2005 committed May 18, 2024
1 parent 5fc0dc6 commit 88a9a8d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
Binary file added backend/__debug_bin1573908833.exe
Binary file not shown.
1 change: 1 addition & 0 deletions backend/entities/search/base/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// Do a GET request to the OpenSearch instance.
func doSearchGoRequest[T, V any](url string, requestBody T) (*V, error) {
payload, err := json.Marshal(requestBody)
print(string(payload))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
onlyMigrate := flag.Bool("only-migrate", false, "Specify if you want to only perform the database migration")
configPath := flag.String("config", filepath.Join("..", "config"), "Specify the path to the config directory")
useDevDotEnv := flag.Bool("use-dev-dot-env", true, "Specify if you want to use the .env.dev file")
seedSearch := flag.Bool("seed-search", false, "Specify if you want to perform search seeding.")
seedSearch := flag.Bool("seed-search", true, "Specify if you want to perform search seeding.")

flag.Parse()

Expand Down
50 changes: 33 additions & 17 deletions backend/search/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package search

import "github.com/GenerateNU/sac/backend/entities/models"

type Json map[string]interface{}

// Used for making OpenSearch GET /<index>/_search requests.
type SearchEndpointRequest struct {
Query struct {
QueryString struct {
Query string `json:"query"`
} `json:"query_string"`
} `json:"query"`
// OpenSearch's DSL is such that we can't make this a nice static struct with all the fields
// specified; depending on what we are looking to search we'll need to add different clauses.
type SearchEndpointRequest Json

// Used in SearchEndpointRequest
type TagFilterInSearchEndpointRequest struct {
Term struct {
Tag string `json:"tag"`
} `json:"term"`
}

// Used for responses from OpenSearch GET /<index>/_search requests.
Expand Down Expand Up @@ -49,24 +54,35 @@ func ClubSearchDocumentFromClub(c *models.Club) ClubSearchDocument {

// Query parameters for an API GET /api/v1/search/clubs request.
type ClubSearchQuery struct {
Search string `query:"search"`
// Tags []string `query:"tags"`
// MinMembers int `query:"min_members"`
// MaxMembers int `query:"max_members"`
// RecruitmentCycle *RecruitmentCycle `query:"recruitment_cycle"`
// IsRecruiting *bool `query:"is_recruiting"`
// MinWeeklyTimeCommitment int `query:"min_weekly_time_commitment"`
// MaxWeeklyTimeCommitment int `query:"max_weekly_time_commitment"`
// OneWordToDescribeUs string `query:"one_word_to_describe_us"`
// Search string `query:"search"`
Search string `query:"search"`
MinMembers int `query:"min_members"`
MaxMembers int `query:"max_members"`
Tags []string `query:"tags"`
}

// To Query DSL JSON
func (q *ClubSearchQuery) ToSearchEndpointRequest() SearchEndpointRequest {
var req SearchEndpointRequest

req.Query.QueryString.Query = q.Search
/*req.Query.Bool.Must.QueryString.Query = q.Search
req.Query.Bool.Filter.Range.NumMembers.MinMembers = q.MinMembers
if q.MaxMembers != 0 {
req.Query.Bool.Filter.Range.NumMembers.MaxMembers = q.MaxMembers
} else {
// FIXME: This is probably going to break in the future. We should probably be figuring out
// what the most members of any club is and set this to the default.
req.Query.Bool.Filter.Range.NumMembers.MaxMembers = 16384
}
for _, tag := range q.Tags {
req.Query.Bool.Must.Terms.Tags = append(req.Query.Bool.Must.Terms.Tags, tag)
}
req.Query.Bool.Must.Terms.MinimumShouldMatch = 1*/
// TODO:
// must - query_string, filter - tags (done in a match) + members (done in a range)
return req
}

Expand Down
1 change: 1 addition & 0 deletions mock_data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def tags_prompt(name: str, description: str) -> str:
category_uuids = data['category_uuids']


# FIXME: should probably be in args or something but ughhhhh
db_conn = psycopg2.connect(
dbname="sac",
user="postgres",
Expand Down

0 comments on commit 88a9a8d

Please sign in to comment.