예제 #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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Determines if the specified fieldname should be skipped depending on the rule contained in this instance
        /// </summary>
        /// <param name="fieldType">Type of the field.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="fieldType"/> parameter is null
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="fieldName"/> parameter is null or empty
        /// </exception>
        public bool SkipField(Type fieldType, string fieldName)
        {
            if (fieldType == null)
            {
                throw new ArgumentNullException("fieldType", "fieldType cannot be null");
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("fieldName", "fieldName cannot be null or empty");
            }
            IndexWriterRule rule = GetRuleFromType(fieldType);

            // no rule? include it!
            if (rule == null)
            {
                return(false);
            }
            return(rule.SkipField(fieldType, fieldName));
        }