-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] q
for searches
#175
Comments
Currently I use this server-side (FeathersJS) hook to achieve the functionality: import { HookContext } from '@feathersjs/feathers';
const withSearch = (sourceField: string = 'q', targetField: string = 'name', caseSensitive: boolean = false) => {
return async (context: HookContext) => {
if (context.type === 'before') {
if (context?.params?.query && context.params.query[sourceField]) {
// convert to like field (KnexJS FeathersJS Adapter)
// @see https://github.com/feathersjs-ecosystem/feathers-knex/blob/master/test/index.test.js#L205
const value = context.params.query[sourceField];
// Note: Some databases like SQLite don't support `$ilike` (case-insensitive `$like`)...
const targetOp = '$like';
// ... hence internally handle case sensitivity checks
const targetValue = caseSensitive ? value : value.toLowerCase();
// set new parameter that is understood by KnexJS FeathersJS Adapter
// e.g. `fieldName[$like] = '%value%'`
context.params.query[targetField] = {
[targetOp]: `\%${targetValue}\%`, // `%[...]%` for open text start + end
};
// clean up old field from query (otherwise causes query error (non-existing column))
delete context.params.query[sourceField];
return context;
}
}
}
}
export default withSearch; const withSearchHook = withSearch('q', 'name');
// [...]
export default {
before: {
// [...]
find: [
withSearchHook,
],
// [...]
get: [
withSearchHook,
],
// [...]
// [...] So for The old This results in a full-text search in the |
Did you try customQueryOperator as an option? https://github.com/josx/ra-data-feathers#data-provider-restclient |
@josx: Would The |
customQueryOperator is operator to be use on filter key when quering feathers. Please check tests |
react-admin
often usesq
as full text search parameter.Currently FeathersJS will try to use
q
as column (which usually doesn't exist in the table) and report a query error.How can this functionality be added? Must the data provider handle this or a hook in FeathersJS app?
Edit: Just using
source="fieldName[$like]"
sadly won't work as the field name is automatically escaped (probably already inreact-admin
), also the value is not automatically wrapped in%
for an open start + end of string.The text was updated successfully, but these errors were encountered: