public void WriteDriveInfo(DriveInfo info, FieldStorage storage) { if (info == null) { throw new ArgumentNullException("info", "info cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } IndexDocument document = new IndexDocument(); document.Add(new FieldNormal("AvailableFreeSpace", info.AvailableFreeSpace.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("DriveFormat", info.DriveFormat, storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("DriveType", info.DriveType.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("IsReady", info.IsReady.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("Name", info.Name, storage.Store, storage.SearchRule, storage.VectorRule)); if (info.RootDirectory != null && !string.IsNullOrEmpty(info.RootDirectory.FullName)) { document.Add(new FieldNormal("", info.RootDirectory.FullName, storage.Store, storage.SearchRule, storage.VectorRule)); } document.Add(new FieldNormal("TotalFreeSpace", info.TotalFreeSpace.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("TotalSize", info.TotalSize.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("VolumeLabel", info.VolumeLabel, storage.Store, storage.SearchRule, storage.VectorRule)); this.Write(document); }
public void Write <TKey, TValue>(IDictionary <TKey, TValue> values, FieldStorage storage) { if (!this.IsOpen) { throw new ObjectDisposedException("IndexWriter", "You cannot access this method from a disposed IndexWriter"); } if (values == null) { throw new ArgumentNullException("values", "values cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } IndexDocument document = new IndexDocument(); foreach (KeyValuePair <TKey, TValue> pair in values) { if (pair.Key == null || pair.Value == null) { continue; } string fieldName = pair.Key.ToString(); string fieldValue = pair.Value.ToString(); if (string.IsNullOrEmpty(fieldName) || string.IsNullOrEmpty(fieldValue)) { continue; } document.Add(new FieldNormal(fieldName, fieldValue, storage.Store, storage.SearchRule, storage.VectorRule)); } this.Write(document); }
public void WriteDirectory(FileSystemInfo info, FieldStorage storage) { if (info == null) { throw new ArgumentNullException("info", "info cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } IndexDocument document = new IndexDocument(); if (!string.IsNullOrEmpty(info.Attributes.ToString())) { document.Add(new FieldNormal("Attributes", info.Attributes.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); } document.Add(new FieldNormal("CreationTime", info.CreationTime.ToString("G"), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("Exists", info.Exists.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("Extension", info.Extension, storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("FullName", info.FullName, storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("LastAccessTime", info.LastAccessTime.ToString("G"), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("LastWriteTime", info.LastWriteTime.ToString("G"), storage.Store, storage.SearchRule, storage.VectorRule)); document.Add(new FieldNormal("Name", info.Name, storage.Store, storage.SearchRule, storage.VectorRule)); this.Write(document); // this.WriteInstance<DirectoryInfo>(info, storage); // could simpify the whole thing }
public void Write <TKey>(string fieldName, IEnumerable <TKey> values, FieldStorage storage, bool makeSingleDocument) { if (!this.IsOpen) { throw new ObjectDisposedException("IndexWriter", "You cannot access this method from a disposed IndexWriter"); } if (string.IsNullOrEmpty(fieldName)) { throw new ArgumentNullException("fieldName", "fieldName cannot be null"); } if (values == null) { throw new ArgumentNullException("values", "values cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } if (makeSingleDocument) { IndexDocument document = new IndexDocument(); foreach (TKey value in values) { if (value == null) { continue; } string fieldValue = value.ToString(); if (string.IsNullOrEmpty(fieldValue)) { continue; } document.Add(new FieldNormal(fieldName, fieldValue, storage.Store, storage.SearchRule, storage.VectorRule)); } if (document.TotalFields > 0) { this.Write(document); } } else { foreach (TKey value in values) { if (value == null) { continue; } string fieldValue = value.ToString(); if (string.IsNullOrEmpty(fieldValue)) { continue; } IndexDocument document = new IndexDocument(); document.Add(new FieldNormal(fieldName, fieldValue, storage.Store, storage.SearchRule, storage.VectorRule)); this.Write(document); } } }
public IndexableAttribute(bool isIndexable, bool indexPropertiesWithNoAttribute, FieldStorage defaultStorageRule) { if (defaultStorageRule == null) throw new ArgumentNullException("defaultStorageRule", "defaultStorageRule cannot be null"); this.isIndexable = isIndexable; this.indexPropsWithNoAttribute = indexPropertiesWithNoAttribute; this.defaultStorageRule = defaultStorageRule; }
public void WriteDataRow(DataRow dataRow, IndexWriterRuleCollection ruleCollection, AnalyzerType analyzerType) { if (dataRow == null) { throw new ArgumentNullException("dataRow", "dataRow cannot be null"); } if (ruleCollection == null) { throw new ArgumentNullException("ruleCollection", "ruleCollection cannot be null"); } DataTable dataTable = dataRow.Table; int totalColumns = dataTable.Columns.Count; IndexDocument document = new IndexDocument(); for (int j = 0; j < totalColumns; j++) { DataColumn column = dataTable.Columns[j]; if (string.IsNullOrEmpty(column.ColumnName)) { continue; } IndexWriterRule rule = ruleCollection.GetRuleFromType(column.DataType); if (rule.SkipField(column.DataType, column.ColumnName)) { continue; } FieldStorage storageRule = rule.GetStorageRule(column.ColumnName); // that's all the field data, now lets get the value data object rowValue = dataRow[j]; bool isRowNull = rowValue == null || rowValue == DBNull.Value; if (rule.SkipColumnIfNull && isRowNull) { continue; } else if (!rule.SkipColumnIfNull && string.IsNullOrEmpty(rule.DefaultValueIfNull)) { continue; } string fieldValue = (isRowNull) ? rule.DefaultValueIfNull : rowValue.ToString(); rowValue = null; document.Add(new FieldNormal(column.ColumnName, fieldValue, storageRule.Store, storageRule.SearchRule, storageRule.VectorRule)); } if (document.TotalFields > 0) { if (analyzerType == AnalyzerType.None || analyzerType == AnalyzerType.Unknown) { this.Write(document); } else { this.Write(document, analyzerType); } } }
public IndexableAttribute(bool isIndexable, bool indexPropertiesWithNoAttribute, FieldStorage defaultStorageRule) { if (defaultStorageRule == null) { throw new ArgumentNullException("defaultStorageRule", "defaultStorageRule cannot be null"); } this.isIndexable = isIndexable; this.indexPropsWithNoAttribute = indexPropertiesWithNoAttribute; this.defaultStorageRule = defaultStorageRule; }
/// <summary> /// Sets a <see cref="IndexLibrary.FieldStorage"/> rule for the specified field name /// </summary> /// <param name="name">The field name.</param> /// <param name="storageRule">The storage rule that applies to the supplied field name.</param> /// <exception cref="System.ArgumentNullException"> /// The <paramref name="name"/> parameter is null or empty /// </exception> public void SetStorageRule(string name, FieldStorage storageRule) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name", "name cannot be null or empty"); } if (this.appliedColumnNames.ContainsKey(name)) { this.appliedColumnNames[name] = storageRule; } }
/// <summary> /// Initializes a new instance of the <see cref="IndexWriterRule"/> class. /// </summary> /// <param name="appliedType">The System.Type that this rule applies to.</param> public IndexWriterRule(Type appliedType) { if (appliedType == null) throw new ArgumentNullException("appliedType", "appliedType cannot be null"); this.appliedType = appliedType; this.skipIfNull = true; this.maxAllowedLength = int.MaxValue; this.valueWhenNull = "empty"; this.appliedColumnNames = new Dictionary<string, FieldStorage>(); this.onlyIndexIfContainsFieldName = false; this.defaultStorageRule = new FieldStorage(true, FieldSearchableRule.Analyzed, FieldVectorRule.No); }
/// <summary> /// Initializes a new instance of the <see cref="IndexWriterRule"/> class. /// </summary> /// <param name="appliedType">The System.Type that this rule applies to.</param> public IndexWriterRule(Type appliedType) { if (appliedType == null) { throw new ArgumentNullException("appliedType", "appliedType cannot be null"); } this.appliedType = appliedType; this.skipIfNull = true; this.maxAllowedLength = int.MaxValue; this.valueWhenNull = "empty"; this.appliedColumnNames = new Dictionary <string, FieldStorage>(); this.onlyIndexIfContainsFieldName = false; this.defaultStorageRule = new FieldStorage(true, FieldSearchableRule.Analyzed, FieldVectorRule.No); }
public void WriteDriveInfos(DriveInfo[] driveInfos, FieldStorage storage) { if (driveInfos == null || driveInfos.Length == 0) { return; } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } int totalDrives = driveInfos.Length; for (int i = 0; i < totalDrives; i++) { WriteDriveInfo(driveInfos[i], storage); } }
public void WriteFiles(FileInfo[] files, FieldStorage storage) { if (files == null || files.Length == 0) { return; } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } int totalFiles = files.Length; for (int i = 0; i < totalFiles; i++) { WriteFile(files[i]); } }
public void WriteDirectories(FileSystemInfo[] directories, FieldStorage storage) { if (directories == null || directories.Length == 0) { return; } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } int totalDirectories = directories.Length; for (int i = 0; i < totalDirectories; i++) { WriteDirectory(directories[i], storage); } }
/// <summary> /// Sets a <see cref="IndexLibrary.FieldStorage"/> rule for the specified field name /// </summary> /// <param name="name">The field name.</param> /// <param name="storageRule">The storage rule that applies to the supplied field name.</param> /// <exception cref="System.ArgumentNullException"> /// The <paramref name="name"/> parameter is null or empty /// </exception> public void SetStorageRule(string name, FieldStorage storageRule) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "name cannot be null or empty"); if (this.appliedColumnNames.ContainsKey(name)) this.appliedColumnNames[name] = storageRule; }
public IndexOptionsAttribute(bool isIndexable, FieldStorage storageRule) { this.isIndexable = isIndexable; this.storageRule = storageRule; }
public static void WriteInstance <TKey>(this IndexWriter writer, IEnumerable <TKey> values, FieldStorage storage) where TKey : class { // write all classes to index, but use the same storage rule for all of them if (writer == null) { throw new ArgumentNullException("writer", "writer cannot be null"); } if (!writer.IsOpen) { throw new ObjectDisposedException("writer", "You cannot access this method from a disposed IndexWriter"); } if (values == null) { throw new ArgumentNullException("values", "values cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } foreach (TKey value in values) { WriteInstance <TKey>(writer, value, storage); } }
public static void WriteInstance <TKey>(this IndexWriter writer, TKey objectToWrite, IndexWriterRuleCollection ruleCollection) where TKey : class { if (writer == null) { throw new ArgumentNullException("writer", "writer cannot be null"); } if (!writer.IsOpen) { throw new ObjectDisposedException("writer", "You cannot access this method from a disposed IndexWriter"); } if (objectToWrite == null) { throw new ArgumentNullException("objectToWrite", "objectToWrite cannot be null"); } if (ruleCollection == null) { throw new ArgumentNullException("ruleCollection", "storage cannot be null"); } List <PropertyInfo> properties = new List <PropertyInfo>(objectToWrite.GetType().GetProperties()); properties.RemoveAll(x => !x.CanRead); if (properties.Count == 0) { throw new InvalidOperationException("You cannot index a class that doesn't have any publicly accessible (get) properties"); } int totalProperties = properties.Count; IndexDocument document = new IndexDocument(); int addedProperties = 0; for (int i = 0; i < totalProperties; i++) { PropertyInfo info = properties[i]; IndexWriterRule rule = ruleCollection.GetRuleFromType(info.PropertyType); object propertyValue = info.GetValue(objectToWrite, null); if (rule.SkipColumnIfNull && propertyValue == null) { continue; } else if (!rule.SkipColumnIfNull && string.IsNullOrEmpty(rule.DefaultValueIfNull) && propertyValue == null) { continue; } string stringValue = string.Empty; if (propertyValue == null) { stringValue = rule.DefaultValueIfNull; } else { stringValue = propertyValue.ToString(); } propertyValue = null; FieldStorage storage = (rule.AppliedColumns.ContainsKey(info.Name)) ? rule.AppliedColumns[info.Name] : rule.DefaultStorageRule; document.Add(new FieldNormal(info.Name, stringValue, storage.Store, storage.SearchRule, storage.VectorRule)); ++addedProperties; } if (addedProperties > 0) { writer.Write(document); } }
public static void WriteInstance <TKey>(this IndexWriter writer, TKey objectToWrite, IEnumerable <string> propertiesToIndex, FieldStorage storage) where TKey : class { if (writer == null) { throw new ArgumentNullException("writer", "writer cannot be null"); } if (!writer.IsOpen) { throw new ObjectDisposedException("writer", "You cannot access this method from a disposed IndexWriter"); } if (objectToWrite == null) { throw new ArgumentNullException("objectToWrite", "objectToWrite cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } List <PropertyInfo> properties = new List <PropertyInfo>(objectToWrite.GetType().GetProperties()); properties.RemoveAll(x => !x.CanRead || !propertiesToIndex.Contains(x.Name)); if (properties.Count == 0) { throw new InvalidOperationException("You cannot index a class that doesn't have any publicly accessible (get) properties"); } //for (int i = (totalProperties -1); i >= 0; i--) if (!propertiesToIndex.Contains(properties[i].Name)) properties.RemoveAt(i); // now all properties can be indexed int totalProperties = properties.Count; IndexDocument document = new IndexDocument(); int addedProperties = 0; for (int i = 0; i < totalProperties; i++) { PropertyInfo info = properties[i]; object propertyValue = info.GetValue(objectToWrite, null); if (propertyValue == null) { continue; } document.Add(new FieldNormal(info.Name, propertyValue.ToString(), storage.Store, storage.SearchRule, storage.VectorRule)); ++addedProperties; } if (addedProperties > 0) { writer.Write(document); } }
public void Write <TKey>(string fieldName, IEnumerable <TKey> values, FieldStorage storage) { Write <TKey>(fieldName, values, storage, false); }
public void Write <TKey, TValue>(ILookup <TKey, TValue> values, FieldStorage storage) { Write <TKey, TValue>(values, storage, false); }
public static void WriteInstance <TKey>(this IndexWriter writer, IEnumerable <TKey> values, IEnumerable <string> propertiesToIndex, FieldStorage storage) where TKey : class { if (writer == null) { throw new ArgumentNullException("writer", "writer cannot be null"); } if (!writer.IsOpen) { throw new ObjectDisposedException("writer", "You cannot access this method from a disposed IndexWriter"); } if (values == null) { throw new ArgumentNullException("values", "values cannot be null"); } if (storage == null) { throw new ArgumentNullException("storage", "storage cannot be null"); } foreach (TKey value in values) { WriteInstance <TKey>(writer, value, propertiesToIndex, storage); } }