const mongoose = require('mongoose')
const shortId = require('shortid')
const Schema = mongoose.Schema

const assetSchema = Schema({
  _shortId: {type: String, unique: true, default: shortId.generate},
  tagId: { type: String, text: true },
  assignedTo: { type: String, text: true }
})

const specSchema = Schema({
  _shortId: {type: String, unique: true, default: shortId.generate},
  key: { type: String, text: true },
  value: { type: String, text: true }
})

const categorySchema = Schema({
  _shortId: {type: String, unique: true, default: shortId.generate},
  name: String,
  label: String,
  description: String,
  config: {
    faIcon: String,
    color: String,
    api: String,
    fallbackImage: String
  },
  models: [ { type: Schema.Types.ObjectId, ref: 'Model' } ]
})

const modelSchema = Schema({
  _parent: {type: String, ref: 'Category'},
  _shortId: {type: String, unique: true, default: shortId.generate},
  category: { type: String, text: true },
  vendor: { type: String, text: true },
  name: { type: String, text: true },
  version: { type: String, text: true },
  image: String,
  description: { type: String, text: true },
  active: Boolean,
  specs: [ specSchema ],
  assets: [ assetSchema ]
})

modelSchema.index({
  vendor: 'text',
  name: 'text',
  version: 'text',
  description: 'text'
})

module.exports = { assetSchema, modelSchema, categorySchema }

@@ -208,80 +208,36 @@
 Id: 
-%7B type: String, text: true %7D,%0A  assignedTo: %7B type: String, text: true %7D
+String,%0A  assignedTo: String
 %0A%7D)%0A
@@ -345,75 +345,31 @@
 ey: 
-%7B type: String, text: true %7D,%0A  value: %7B type: String, text: true %7D
+String,%0A  value: String
 %0A%7D)%0A
@@ -847,155 +847,67 @@
 ry: 
-%7B type: String, text: true %7D,%0A  vendor: %7B type: String, text: true %7D,%0A  name: %7B type: String, text: true %7D,%0A  version: %7B type: String, text: true %7D
+String,%0A  vendor: String,%0A  name: String,%0A  version: String
 ,%0A  
@@ -940,36 +940,14 @@
 on: 
-%7B type: String, text: true %7D
+String
 ,%0A  

Complete search functionality for models