Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        public void WriteDataView(DataView view, IndexWriterRuleCollection ruleCollection, AnalyzerType analyzerType)
        {
            DataTable table = null;

            if (view != null)
            {
                table = view.Table == null?view.ToTable() : view.Table;
            }
            WriteDataTable(table, ruleCollection, analyzerType);
        }
Esempio n. 3
0
        public void WriteDataSet(DataSet dataSet, IndexWriterRuleCollection ruleCollection, AnalyzerType analyzerType)
        {
            if (!this.IsOpen)
            {
                throw new ObjectDisposedException("IndexWriter", "You cannot access this method from a disposed IndexWriter");
            }
            if (dataSet == null || dataSet.Tables.Count == 0)
            {
                return;
            }
            if (ruleCollection == null)
            {
                throw new ArgumentNullException("ruleCollection", "ruleCollection cannot be null");
            }

            int totalTables = dataSet.Tables.Count;

            for (int i = 0; i < totalTables; i++)
            {
                WriteDataTable(dataSet.Tables[i], ruleCollection, analyzerType);
            }
        }
Esempio n. 4
0
 public void WriteDataView(DataView view, IndexWriterRuleCollection ruleCollection)
 {
     WriteDataView(view, ruleCollection, AnalyzerType.None);
 }
Esempio n. 5
0
 public void WriteDataTable(DataTable dataTable, IndexWriterRuleCollection ruleCollection)
 {
     WriteDataTable(dataTable, ruleCollection, AnalyzerType.None);
 }
Esempio n. 6
0
 public void WriteDataSet(DataSet dataSet, IndexWriterRuleCollection ruleCollection)
 {
     WriteDataSet(dataSet, ruleCollection, AnalyzerType.None);
 }
Esempio n. 7
0
 public void WriteDataRow(DataRow dataRow, IndexWriterRuleCollection ruleCollection)
 {
     WriteDataRow(dataRow, ruleCollection, AnalyzerType.None);
 }
Esempio n. 8
0
 public static void WriteInstance <TKey>(this IndexWriter writer, IEnumerable <TKey> values, 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 (values == null)
     {
         throw new ArgumentNullException("values", "values cannot be null");
     }
     foreach (TKey value in values)
     {
         WriteInstance <TKey>(writer, value, ruleCollection);
     }
 }
Esempio n. 9
0
        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);
            }
        }