Browse Source

indexable fields

pull/1107/head
Martin McKeaveney 5 years ago
parent
commit
d2bd2209eb
  1. 8
      packages/builder/src/builderStore/dataBinding.js
  2. 14
      packages/server/src/api/controllers/row.js
  3. 5
      packages/server/src/api/routes/row.js
  4. 888
      packages/server/yarn.lock
  5. 3
      packages/standard-components/manifest.json
  6. 2
      packages/standard-components/src/Search.svelte

8
packages/builder/src/builderStore/dataBinding.js

@ -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]
})
}
}
}
}

14
packages/server/src/api/controllers/row.js

@ -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"

5
packages/server/src/api/routes/row.js

@ -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),

888
packages/server/yarn.lock

File diff suppressed because it is too large

3
packages/standard-components/manifest.json

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

2
packages/standard-components/src/Search.svelte

@ -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…
Cancel
Save