Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/common/src/services/audius-api-client/AudiusAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AudiusLibs } from '@audius/sdk'
import type { AudiusLibs, Genre, Mood } from '@audius/sdk'

import {
ID,
Expand Down Expand Up @@ -284,6 +284,9 @@ type GetSearchArgs = {
limit?: number
offset?: number
includePurchaseable?: boolean
genre?: Genre
mood?: Mood
isVerified?: boolean
}

type TrendingIdsResponse = {
Expand Down Expand Up @@ -1119,7 +1122,10 @@ export class AudiusAPIClient {
kind,
offset,
limit,
includePurchaseable
includePurchaseable,
genre,
mood,
isVerified
}: GetSearchArgs) {
this._assertInitialized()
const encodedUserId = encodeHashId(currentUserId)
Expand All @@ -1129,7 +1135,10 @@ export class AudiusAPIClient {
kind,
offset,
limit,
includePurchaseable
includePurchaseable,
genre,
mood,
is_verified: isVerified
}

const searchResponse =
Expand Down
65 changes: 40 additions & 25 deletions packages/common/src/store/pages/search-results/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Genre, Mood } from '@audius/sdk'

import { SearchKind } from './types'

export const FETCH_SEARCH_PAGE_RESULTS = 'SEARCH/FETCH_SEARCH_PAGE_RESULTS'
Expand All @@ -15,9 +17,12 @@ export const FETCH_SEARCH_PAGE_TAGS_FAILED =
export type FetchSearchPageResultsAction = {
type: typeof FETCH_SEARCH_PAGE_RESULTS
searchText: string
searchKind: SearchKind
kind: SearchKind
limit: number
offset: number
genre?: Genre
mood?: Mood
is_verified?: boolean
}

export type FetchSearchPageResultsSuceededAction = {
Expand Down Expand Up @@ -58,54 +63,64 @@ export type SearchPageActions =

// Query-based search

export const fetchSearchPageResults = (
searchText: string,
searchKind: SearchKind,
limit: number,
type FetchSearchPageResultsArgs = {
searchText: string
kind: SearchKind
limit: number
offset: number
genre?: Genre
mood?: Mood
isVerified?: boolean
}

export const fetchSearchPageResults = (
args: FetchSearchPageResultsArgs
): SearchPageActions => ({
type: FETCH_SEARCH_PAGE_RESULTS,
searchText,
searchKind,
limit,
offset
...args
})

export const fetchSearchPageResultsSucceeded = (
results: any,
type fetchSearchPageResultsSucceededArgs = {
results: any
searchText: string
}

export const fetchSearchPageResultsSucceeded = (
args: fetchSearchPageResultsSucceededArgs
): SearchPageActions => ({
type: FETCH_SEARCH_PAGE_RESULTS_SUCCEEDED,
results,
searchText
...args
})

export const fetchSearchPageResultsFailed = (): SearchPageActions => ({
type: FETCH_SEARCH_PAGE_RESULTS_FAILED
})

// Tag-based searcxh
type FetchSearchPageTagsArgs = {
tag: string
searchKind: SearchKind
limit: number
offset: number
}

export const fetchSearchPageTags = (
tag: string,
searchKind: SearchKind,
limit: number,
offset: number
args: FetchSearchPageTagsArgs
): SearchPageActions => ({
type: FETCH_SEARCH_PAGE_TAGS,
tag,
searchKind,
limit,
offset
...args
})

export const fetchSearchPageTagsSucceeded = (
results: any,
type FetchSearchPageTagsSucceededArgs = {
results: any
tag: string
}

export const fetchSearchPageTagsSucceeded = (
args: FetchSearchPageTagsSucceededArgs
): SearchPageActions => ({
type: FETCH_SEARCH_PAGE_TAGS_SUCCEEDED,
results,
tag
...args
})

export const fetchSearchPageTagsFailed = (): SearchPageActions => ({
Expand Down
15 changes: 14 additions & 1 deletion packages/discovery-provider/src/api/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def __schema__(self):
)

full_search_parser = pagination_with_current_user_parser.copy()
full_search_parser.add_argument("query", required=True, description="The search query")
full_search_parser.add_argument("query", required=False, description="The search query")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we want this to go in now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yeah it's fine for this to go now

full_search_parser.add_argument(
"kind",
required=False,
Expand All @@ -838,6 +838,19 @@ def __schema__(self):
type=str,
description="The genres to filter by",
)
full_search_parser.add_argument(
"mood",
action="append",
required=False,
type=str,
description="The moods to filter by",
)
full_search_parser.add_argument(
"is_verified",
required=False,
type=str,
description="Only include verified users in the user results",
)

verify_token_parser = reqparse.RequestParser(argument_class=DescriptiveArgument)
verify_token_parser.add_argument("token", required=True, description="JWT to verify")
Expand Down
4 changes: 4 additions & 0 deletions packages/discovery-provider/src/api/v1/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def get(self):
current_user_id = get_current_user_id(args)
include_purchaseable = parse_bool_param(args.get("includePurchaseable"))
genres = args.get("genre")
moods = args.get("mood")
is_verified = parse_bool_param(args.get("is_verified"))

search_args = {
"is_auto_complete": False,
Expand All @@ -58,6 +60,8 @@ def get(self):
"only_downloadable": False,
"include_purchaseable": include_purchaseable,
"genres": genres,
"moods": moods,
"only_verified": is_verified,
}
resp = search(search_args)
return success_response(resp)
Expand Down
46 changes: 41 additions & 5 deletions packages/discovery-provider/src/queries/search_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
populate_user_metadata_es,
)
from src.utils.hardcoded_data import genre_allowlist
from src.utils.hardcoded_data import moods as mood_allowlist

logger = logging.getLogger(__name__)

Expand All @@ -26,12 +27,19 @@ def get_capitalized_genre(genre):
return lowercase_to_capitalized_genre.get(genre.lower())


lowercase_to_capitalized_mood = {mood.lower(): mood for mood in mood_allowlist}


def get_capitalized_mood(mood):
return lowercase_to_capitalized_mood.get(mood.lower())


def search_es_full(args: dict):
esclient = get_esclient()
if not esclient:
raise Exception("esclient is None")

search_str = args.get("query", "").strip()
search_str = (args.get("query", "") or "").strip()
current_user_id = args.get("current_user_id")
limit = args.get("limit", 10)
offset = args.get("offset", 0)
Expand All @@ -40,6 +48,8 @@ def search_es_full(args: dict):
is_auto_complete = args.get("is_auto_complete")
include_purchaseable = args.get("include_purchaseable", False)
genres = args.get("genres", [])
moods = args.get("moods", [])
only_verified = args.get("only_verified", False)
do_tracks = search_type == "all" or search_type == "tracks"
do_users = search_type == "all" or search_type == "users"
do_playlists = search_type == "all" or search_type == "playlists"
Expand All @@ -64,6 +74,7 @@ def search_es_full(args: dict):
only_downloadable=only_downloadable,
include_purchaseable=include_purchaseable,
genres=genres,
moods=moods,
),
]
)
Expand All @@ -73,7 +84,12 @@ def search_es_full(args: dict):
mdsl.extend(
[
{"index": ES_USERS},
user_dsl(search_str, current_user_id),
user_dsl(
search_str=search_str,
current_user_id=current_user_id,
must_saved=False,
only_verified=only_verified,
),
]
)

Expand Down Expand Up @@ -355,6 +371,7 @@ def track_dsl(
only_downloadable=False,
include_purchaseable=False,
genres=[],
moods=[],
):
dsl = {
"must": [
Expand Down Expand Up @@ -426,8 +443,24 @@ def track_dsl(
}

if genres:
capitalized_genres = [get_capitalized_genre(genre) for genre in genres]
dsl["filter"].append({"terms": {"genre": capitalized_genres}})
capitalized_genres = list(
filter(
None,
[get_capitalized_genre(genre) for genre in genres if genre is not None],
)
)
if capitalized_genres:
dsl["filter"].append({"terms": {"genre": capitalized_genres}})

if moods:
capitalized_moods = list(
filter(
None, [get_capitalized_mood(mood) for mood in moods if mood is not None]
)
)

if capitalized_moods:
dsl["filter"].append({"terms": {"mood": capitalized_moods}})

if only_downloadable:
dsl["must"].append({"term": {"downloadable": {"value": True}}})
Expand All @@ -439,7 +472,7 @@ def track_dsl(
return default_function_score(dsl, "repost_count")


def user_dsl(search_str, current_user_id, must_saved=False):
def user_dsl(search_str, current_user_id, only_verified, must_saved=False):
# must_search_str = search_str + " " + search_str.replace(" ", "")
dsl = {
"must": [
Expand Down Expand Up @@ -544,6 +577,9 @@ def user_dsl(search_str, current_user_id, must_saved=False):
if current_user_id and must_saved:
dsl["must"].append(be_followed(current_user_id))

if only_verified:
dsl["must"].append({"term": {"is_verified": {"value": True}}})

if current_user_id:
dsl["should"].append(be_followed(current_user_id))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,13 @@ def update_user_metadata(
challenge_event_bus = params.challenge_bus
# Iterate over the user_record keys
user_record_attributes = user_record.get_attributes_dict()

env = shared_config["discprov"]["env"]
for key, _ in user_record_attributes.items():
# Update the user_record when the corresponding field exists
# in metadata
if key in metadata:
if key in immutable_user_fields:
if key in immutable_user_fields and env != "dev":
continue
setattr(user_record, key, metadata[key])

Expand Down
2 changes: 1 addition & 1 deletion packages/es-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ npm run dev --drop

## How it works

Program attempts to avoid any gaps by doing a "catchup" on boot... when complete it swithces to processing "batches" which are events collected from postgres LISTEN / NOTIFY.
Program attempts to avoid any gaps by doing a "catchup" on boot... when complete it switches to processing "batches" which are events collected from postgres LISTEN / NOTIFY.

Any error or exception will cause the program to crash and be restarted by pm2. This is inspired by the erlang "let it crash" mantra, since the startup behavior is designed to get everything into a good state.

Expand Down
3 changes: 2 additions & 1 deletion packages/mobile/src/components/audio/RNVideoAudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useDispatch, useSelector } from 'react-redux'
import { usePrevious } from 'react-use'
import { useFeatureFlag } from '~/hooks'
import { FeatureFlags } from '~/services'
import { getUserId } from '~/store/account/selectors'

import { DEFAULT_IMAGE_URL } from 'app/components/image/TrackImage'
import { getImageSourceOptimistic } from 'app/hooks/useContentNodeImage'
Expand Down Expand Up @@ -102,7 +103,7 @@ export const RNVideoAudioPlayer = () => {
const counter = useSelector(getCounter)
// const repeatMode = useSelector(getRepeat)
// const playbackRate = useSelector(getPlaybackRate)
// const currentUserId = useSelector(getUserId)
const currentUserId = useSelector(getUserId)
// const uid = useSelector(getUid)
// Player behavior determines whether to preview a track or play the full track
const playerBehavior =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export const useFetchTabResultsEffect = (searchKind: SearchKind) => {
if (isTagSearch) {
if (shouldFetch) {
dispatch(
searchResultsPageActions.fetchSearchPageTags(
query,
searchResultsPageActions.fetchSearchPageTags({
tag: query,
searchKind,
ALL_CATEGORY_RESULTS_LIMIT,
0
)
limit: ALL_CATEGORY_RESULTS_LIMIT,
offset: 0
})
)
}
track(
Expand All @@ -65,12 +65,12 @@ export const useFetchTabResultsEffect = (searchKind: SearchKind) => {
} else {
if (shouldFetch) {
dispatch(
searchResultsPageActions.fetchSearchPageResults(
query,
searchKind,
ALL_CATEGORY_RESULTS_LIMIT,
0
)
searchResultsPageActions.fetchSearchPageResults({
searchText: query,
kind: searchKind,
limit: ALL_CATEGORY_RESULTS_LIMIT,
offset: 0
})
)
}
track(
Expand Down
Loading