indexable fields
This commit is contained in:
parent
07aeccb36d
commit
7ef56de1be
|
@ -4,6 +4,7 @@ import { backendUiStore, store } from "builderStore"
|
|||
import { findAllMatchingComponents, findComponentPath } from "./storeUtils"
|
||||
import { makePropSafe } from "@budibase/string-templates"
|
||||
import { TableNames } from "../constants"
|
||||
import { search } from "../../../server/src/api/controllers/row"
|
||||
|
||||
// Regex to match all instances of template strings
|
||||
const CAPTURE_VAR_INSIDE_TEMPLATE = /{{([^}]+)}}/g
|
||||
|
@ -64,6 +65,7 @@ export const getDatasourceForProvider = component => {
|
|||
return {
|
||||
tableId: component[datasourceSetting?.key],
|
||||
type: "table",
|
||||
searchableOnly: datasourceSetting.searchableOnly,
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
@ -195,6 +197,12 @@ export const getSchemaForDatasource = datasource => {
|
|||
schema = cloneDeep(table.views?.[datasource.name]?.schema)
|
||||
} else {
|
||||
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]
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
// const appId = ctx.user.appId
|
||||
const appId = "app_1987903cf3604d459969c80cf17651a0"
|
||||
|
|
|
@ -31,6 +31,11 @@ router
|
|||
usage,
|
||||
rowController.save
|
||||
)
|
||||
.post(
|
||||
"/api/createindex",
|
||||
// authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||
rowController.createIndex
|
||||
)
|
||||
.post(
|
||||
"/api/:tableId/rows/search",
|
||||
// authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -130,7 +130,8 @@
|
|||
{
|
||||
"type": "table",
|
||||
"label": "Table",
|
||||
"key": "table"
|
||||
"key": "table",
|
||||
"searchableOnly": true
|
||||
},
|
||||
{
|
||||
"type": "multifield",
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
$: fetchData(table, pagination)
|
||||
// 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) {
|
||||
if (!isEmpty(table)) {
|
||||
|
|
Loading…
Reference in New Issue