pass related_to flag to search for recommended content

This commit is contained in:
Sean Yesmunt 2019-12-18 17:20:08 -05:00
parent 04615f0d6b
commit 8086ccdc01
5 changed files with 59 additions and 26 deletions

30
dist/bundle.es.js vendored
View file

@ -1042,7 +1042,7 @@ function toQueryString(params) {
return parts.join('&');
}
const getSearchQueryString = (query, options = {}, includeUserOptions = false) => {
const getSearchQueryString = (query, options = {}, includeUserOptions = false, additionalOptions = {}) => {
const encodedQuery = encodeURIComponent(query);
const queryParams = [`s=${encodedQuery}`, `size=${options.size || DEFAULT_SEARCH_SIZE}`, `from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`];
@ -1056,6 +1056,13 @@ const getSearchQueryString = (query, options = {}, includeUserOptions = false) =
}
}
if (additionalOptions) {
Object.keys(additionalOptions).forEach(key => {
const option = additionalOptions[key];
queryParams.push(`${key}=${option}`);
});
}
return queryParams.join('&');
};
@ -1395,11 +1402,11 @@ const selectSearchSuggestions = reselect.createSelector(selectSearchValue, selec
// Creates a query string based on the state in the search reducer
// Can be overrided by passing in custom sizes/from values for other areas pagination
const makeSelectQueryWithOptions = (customQuery, customSize, customFrom, isBackgroundSearch = false // If it's a background search, don't use the users settings
) => reselect.createSelector(selectSearchValue, selectSearchOptions, (query, options) => {
const makeSelectQueryWithOptions = (customQuery, customSize, customFrom, isBackgroundSearch = false, // If it's a background search, don't use the users settings
additionalOptions = {}) => reselect.createSelector(selectSearchValue, selectSearchOptions, (query, options) => {
const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
const queryString = getSearchQueryString(customQuery || query, _extends$1({}, options, { size, from: customFrom }), !isBackgroundSearch);
const queryString = getSearchQueryString(customQuery || query, _extends$1({}, options, { size, from: customFrom }), !isBackgroundSearch, additionalOptions);
return queryString;
});
@ -2179,7 +2186,13 @@ const makeSelectRecommendedContentForUri = uri => reselect.createSelector(makeSe
const { title } = claim.value;
const searchQuery = getSearchQueryString(title ? title.replace(/\//, ' ') : '');
if (!title) {
return;
}
const searchQuery = getSearchQueryString(title, undefined, undefined, {
related_to: claim.claim_id
});
let searchUris = searchUrisByQuery[searchQuery];
if (searchUris) {
@ -3908,9 +3921,8 @@ const doUpdateSearchQuery = (query, shouldSkipSuggestions) => dispatch => {
}
};
const doSearch = (rawQuery, // pass in a query if you don't want to search for what's in the search bar
size, // only pass in if you don't want to use the users setting (ex: related content)
from, isBackgroundSearch = false) => (dispatch, getState) => {
const doSearch = (rawQuery, size, // only pass in if you don't want to use the users setting (ex: related content)
from, isBackgroundSearch = false, options = {}) => (dispatch, getState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
if (!query) {
@ -3921,7 +3933,7 @@ from, isBackgroundSearch = false) => (dispatch, getState) => {
}
const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state);
let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(state);
// If we have already searched for something, we don't need to do anything
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);

View file

@ -75,10 +75,13 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole
};
export const doSearch = (
rawQuery: string, // pass in a query if you don't want to search for what's in the search bar
rawQuery: string,
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
from: ?number,
isBackgroundSearch: boolean = false
isBackgroundSearch: boolean = false,
options: {
related_to?: string,
} = {}
) => (dispatch: Dispatch, getState: GetState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
@ -90,7 +93,9 @@ export const doSearch = (
}
const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state);
let queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch, options)(
state
);
// If we have already searched for something, we don't need to do anything
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
@ -151,6 +156,8 @@ export const doSearch = (
});
};
export const doSearchForRelatedContent = (query: string) => {};
export const doFocusSearchInput = () => (dispatch: Dispatch) =>
dispatch({
type: ACTIONS.SEARCH_FOCUS,

View file

@ -212,7 +212,6 @@ export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
}
);
export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
createSelector(
selectClaimsById,
@ -261,8 +260,8 @@ export const makeSelectDateForUri = (uri: string) =>
(claim.value.release_time
? claim.value.release_time * 1000
: claim.meta && claim.meta.creation_timestamp
? claim.meta.creation_timestamp * 1000
: null);
? claim.meta.creation_timestamp * 1000
: null);
if (!timestamp) {
return undefined;
}
@ -473,8 +472,7 @@ export const makeSelectOmittedCountForChannel = (uri: string) =>
(claimsInChannel, claimsInSearch) => {
if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) {
return claimsInChannel - claimsInSearch;
}
else return 0;
} else return 0;
}
);
@ -508,7 +506,13 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
const { title } = claim.value;
const searchQuery = getSearchQueryString(title ? title.replace(/\//, ' ') : '');
if (!title) {
return;
}
const searchQuery = getSearchQueryString(title, undefined, undefined, {
related_to: claim.claim_id,
});
let searchUris = searchUrisByQuery[searchQuery];
if (searchUris) {
@ -625,11 +629,9 @@ export const makeSelectMyStreamUrlsForPage = (page: number = 1) =>
createSelector(
selectMyClaimUrisWithoutChannels,
urls => {
const start = ((Number(page) - 1) * Number(PAGE_SIZE));
const end = (Number(page) * Number(PAGE_SIZE));
return (urls && urls.length)
? urls.slice(start, end)
: [];
const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = Number(page) * Number(PAGE_SIZE);
return urls && urls.length ? urls.slice(start, end) : [];
}
);

View file

@ -137,7 +137,10 @@ export const makeSelectQueryWithOptions = (
customQuery: ?string,
customSize: ?number,
customFrom: ?number,
isBackgroundSearch: boolean = false // If it's a background search, don't use the users settings
isBackgroundSearch: boolean = false, // If it's a background search, don't use the users settings
additionalOptions: {
related_to?: string,
} = {}
) =>
createSelector(
selectSearchValue,
@ -148,7 +151,8 @@ export const makeSelectQueryWithOptions = (
const queryString = getSearchQueryString(
customQuery || query,
{ ...options, size, from: customFrom },
!isBackgroundSearch
!isBackgroundSearch,
additionalOptions
);
return queryString;

View file

@ -36,7 +36,8 @@ export function toQueryString(params: { [string]: string | number }) {
export const getSearchQueryString = (
query: string,
options: any = {},
includeUserOptions: boolean = false
includeUserOptions: boolean = false,
additionalOptions: {} = {}
) => {
const encodedQuery = encodeURIComponent(query);
const queryParams = [
@ -67,5 +68,12 @@ export const getSearchQueryString = (
}
}
if (additionalOptions) {
Object.keys(additionalOptions).forEach(key => {
const option = additionalOptions[key];
queryParams.push(`${key}=${option}`);
});
}
return queryParams.join('&');
};