1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

indexable fields

This commit is contained in:
Martin McKeaveney 2021-02-08 20:54:55 +00:00
parent 7f24c80bf0
commit d2bd2209eb
6 changed files with 911 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import { backendUiStore, store } from "builderStore"
import { findAllMatchingComponents, findComponentPath } from "./storeUtils" import { findAllMatchingComponents, findComponentPath } from "./storeUtils"
import { makePropSafe } from "@budibase/string-templates" import { makePropSafe } from "@budibase/string-templates"
import { TableNames } from "../constants" import { TableNames } from "../constants"
import { search } from "../../../server/src/api/controllers/row"
// Regex to match all instances of template strings // Regex to match all instances of template strings
const CAPTURE_VAR_INSIDE_TEMPLATE = /{{([^}]+)}}/g const CAPTURE_VAR_INSIDE_TEMPLATE = /{{([^}]+)}}/g
@ -64,6 +65,7 @@ export const getDatasourceForProvider = component => {
return { return {
tableId: component[datasourceSetting?.key], tableId: component[datasourceSetting?.key],
type: "table", type: "table",
searchableOnly: datasourceSetting.searchableOnly,
} }
} }
return null return null
@ -195,6 +197,12 @@ export const getSchemaForDatasource = datasource => {
schema = cloneDeep(table.views?.[datasource.name]?.schema) schema = cloneDeep(table.views?.[datasource.name]?.schema)
} else { } else {
schema = cloneDeep(table.schema) schema = cloneDeep(table.schema)
// Find searchable fields only
if (datasource.searchableOnly) {
Object.keys(table.schema).forEach(key => {
if (!table.schema[key].searchable) delete schema[key]
})
}
} }
} }
} }

View file

@ -229,6 +229,20 @@ exports.fetchView = async function(ctx) {
} }
} }
exports.createIndex = async function(ctx) {
const appId = "app_1987903cf3604d459969c80cf17651a0"
const db = new CouchDB(appId)
ctx.body = await db.createIndex({
index: {
fields: ctx.request.body.fields,
name: "search_index",
ddoc: "search_ddoc",
type: "json",
},
})
}
exports.search = async function(ctx) { exports.search = async function(ctx) {
// const appId = ctx.user.appId // const appId = ctx.user.appId
const appId = "app_1987903cf3604d459969c80cf17651a0" const appId = "app_1987903cf3604d459969c80cf17651a0"

View file

@ -31,6 +31,11 @@ router
usage, usage,
rowController.save rowController.save
) )
.post(
"/api/createindex",
// authorized(PermissionTypes.TABLE, PermissionLevels.READ),
rowController.createIndex
)
.post( .post(
"/api/:tableId/rows/search", "/api/:tableId/rows/search",
// authorized(PermissionTypes.TABLE, PermissionLevels.READ), // authorized(PermissionTypes.TABLE, PermissionLevels.READ),

File diff suppressed because it is too large Load diff

View file

@ -130,7 +130,8 @@
{ {
"type": "table", "type": "table",
"label": "Table", "label": "Table",
"key": "table" "key": "table",
"searchableOnly": true
}, },
{ {
"type": "multifield", "type": "multifield",

View file

@ -31,7 +31,7 @@
$: fetchData(table, pagination) $: fetchData(table, pagination)
// omit empty strings // omit empty strings
$: parsedSearch = Object.keys(search).reduce((acc, next) => search[next] ? { ...acc, [next]: search[next] } : acc, {}) $: parsedSearch = Object.keys(search).reduce((acc, next) => search[next] === "" ? acc : { ...acc, [next]: search[next] }, {})
async function fetchData(table, pagination) { async function fetchData(table, pagination) {
if (!isEmpty(table)) { if (!isEmpty(table)) {