/// <summary> /// Initializes a new instance of the <see cref="Collection" /> class. /// </summary> /// <param name="name">The name of the Document Collection.</param> /// <param name="database">The database.</param> /// <param name="schema">The schema.</param> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentNullException"></exception> internal Collection(string name, Database database, Schema schema = null) { if (String.IsNullOrWhiteSpace(name)) throw new ArgumentException($"{nameof(name)} cannot be null or blank"); if (database == null) throw new ArgumentNullException(nameof(database)); Name = name; Schema = schema ?? Schema.CreateDefault(name); _documentStorage = database.DocumentStorage; var indexPath = Path.Combine(database.IndexBasePath, name); _luceneIndex = new LuceneIndex(indexPath, Schema); }
/// <summary> /// Initializes a new instance of the <see cref="Collection" /> class based on a Schema. /// </summary> /// <param name="schema">The Schema.</param> /// <param name="database">The database.</param> internal Collection(Schema schema, Database database) : this(schema.Name, database, schema) { }
/// <summary> /// Creates a default Schema, which contains the _id, _createdTimestamp, _modifiedTimestamp, and _full_text_ fields. /// </summary> /// <param name="name">The name of the Schema.</param> /// <returns></returns> public static Schema CreateDefault(string name = null) { if (String.IsNullOrWhiteSpace(name)) name = "Default"; var defaultSchema = new Schema(); defaultSchema.Name = name; defaultSchema.Fields[StandardField.ID] = new Field { Name = StandardField.ID, DataType = DataType.Guid }; defaultSchema.Fields[StandardField.CREATED_TIMESTAMP] = new Field { Name = StandardField.CREATED_TIMESTAMP, DataType = DataType.DateTime }; defaultSchema.Fields[StandardField.MODIFIED_TIMESTAMP] = new Field { Name = StandardField.MODIFIED_TIMESTAMP, DataType = DataType.DateTime }; defaultSchema.Fields[StandardField.FULL_TEXT] = new Field { Name = StandardField.FULL_TEXT, DataType = DataType.Text }; return defaultSchema; }