本文整理汇总了C#中Raven.Database.Indexing.IndexDefinition.GetStorage方法的典型用法代码示例。如果您正苦于以下问题:C# IndexDefinition.GetStorage方法的具体用法?C# IndexDefinition.GetStorage怎么用?C# IndexDefinition.GetStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Database.Indexing.IndexDefinition
的用法示例。
在下文中一共展示了IndexDefinition.GetStorage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public IEnumerable<Field> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != "__document_id"
let value = property.GetValue(val)
where value != null
select new Field(name, ToIndexableString(value, indexDefinition.GetIndex(name)), indexDefinition.GetStorage(name), indexDefinition.GetIndex(name)));
}
示例2: Createfield
private static AbstractField Createfield(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
if (indexDefinition.GetIndex(name, Field.Index.ANALYZED) == Field.Index.NOT_ANALYZED || value is string)
return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.ANALYZED));
if (value is int)
{
return new Field(name, JsonLuceneNumberConverter.NumberToString((int)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is long)
{
return new Field(name, JsonLuceneNumberConverter.NumberToString((long)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if(value is decimal)
{
return new Field(name, JsonLuceneNumberConverter.NumberToString((decimal)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is float)
{
return new Field(name, JsonLuceneNumberConverter.NumberToString((float)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is double)
{
return new Field(name, JsonLuceneNumberConverter.NumberToString((double)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is DateTime)
{
return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.ANALYZED));
}
示例3: CreateFields
/// <summary>
/// This method generate the fields for indexing documents in lucene from the values.
/// Given a name and a value, it has the following behavior:
/// * If the value is enumerable, index all the items in the enumerable under the same field name
/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
/// * If the value is string or was set to not analyzed, create a single field with the supplied name
/// * If the value is date, create a single field with millisecond precision with the supplied name
/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
/// 1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
/// 2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
/// </summary>
private static IEnumerable<AbstractField> CreateFields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
if(string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Field must be not null, not empty and cannot contain whitespace", "name");
if (char.IsLetter(name[0]) == false &&
name[0] != '_')
{
name = "_" + name;
}
if (value == null)
{
yield return new Field(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED);
yield break;
}
if (value is DynamicNullObject)
{
if(((DynamicNullObject)value ).IsExplicitNull)
{
yield return new Field(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED);
}
yield break;
}
if(value is AbstractField)
{
yield return (AbstractField)value;
yield break;
}
var itemsToIndex = value as IEnumerable;
if( itemsToIndex != null && ShouldTreatAsEnumerable(itemsToIndex))
{
yield return new Field(name + "_IsArray", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
foreach (var itemToIndex in itemsToIndex)
{
foreach (var field in CreateFields(name, itemToIndex, indexDefinition, defaultStorage))
{
yield return field;
}
}
yield break;
}
if (indexDefinition.GetIndex(name, null) == Field.Index.NOT_ANALYZED)// explicitly not analyzed
{
yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
yield break;
}
if (value is string)
{
var index = indexDefinition.GetIndex(name, Field.Index.ANALYZED);
yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
index);
yield break;
}
if (value is DateTime)
{
yield return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if(value is bool)
{
yield return new Field(name, ((bool) value) ? "true" : "false", indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if(value is IConvertible) // we need this to store numbers in invariant format, so JSON could read them
{
var convert = ((IConvertible) value);
yield return new Field(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if (value is DynamicJsonObject)
{
var inner = ((DynamicJsonObject)value).Inner;
yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
yield return new Field(name, inner.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else
//.........这里部分代码省略.........
示例4: CreateFields
/// <summary>
/// This method generate the fields for indexing documents in lucene from the values.
/// Given a name and a value, it has the following behavior:
/// * If the value is enumerable, index all the items in the enumerable under the same field name
/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
/// * If the value is string or was set to not analyzed, create a single field with the supplied name
/// * If the value is date, create a single field with millisecond precision with the supplied name
/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
/// 1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
/// 2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
/// </summary>
private IEnumerable<AbstractField> CreateFields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
if(string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Field must be not null, not empty and cannot contain whitespace", "name");
if (char.IsLetter(name[0]) == false &&
name[0] != '_')
{
name = "_" + name;
}
if (value == null)
{
yield return CreateFieldWithCaching(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED_NO_NORMS);
yield break;
}
if(Equals(value, string.Empty))
{
yield return CreateFieldWithCaching(name, Constants.EmptyString, indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED_NO_NORMS);
yield break;
}
if (value is DynamicNullObject)
{
if(((DynamicNullObject)value ).IsExplicitNull)
{
yield return CreateFieldWithCaching(name, Constants.NullValue, indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED_NO_NORMS);
}
yield break;
}
if(value is AbstractField)
{
yield return (AbstractField)value;
yield break;
}
if(value is byte[])
{
yield return CreateBinaryFieldWithCaching(name, (byte[])value, indexDefinition.GetStorage(name, defaultStorage));
yield break;
}
var itemsToIndex = value as IEnumerable;
if( itemsToIndex != null && ShouldTreatAsEnumerable(itemsToIndex))
{
yield return new Field(name + "_IsArray", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
int count = 1;
foreach (var itemToIndex in itemsToIndex)
{
multipleItemsSameFieldCount.Add(count++);
foreach (var field in CreateFields(name, itemToIndex, indexDefinition, defaultStorage))
{
yield return field;
}
multipleItemsSameFieldCount.RemoveAt(multipleItemsSameFieldCount.Count - 1);
}
yield break;
}
var fieldIndexingOptions = indexDefinition.GetIndex(name, null);
if (fieldIndexingOptions == Field.Index.NOT_ANALYZED || fieldIndexingOptions == Field.Index.NOT_ANALYZED_NO_NORMS)// explicitly not analyzed
{
if (value is DateTime)
{
var val = (DateTime) value;
var postFix = val.Kind == DateTimeKind.Utc ? "Z" : "";
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeFormatsToWrite) + postFix, indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
else if(value is DateTimeOffset)
{
var val = (DateTimeOffset)value;
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeOffsetFormatsToWrite), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
else
{
yield return CreateFieldWithCaching(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
yield break;
}
if (value is string)
{
var index = indexDefinition.GetIndex(name, Field.Index.ANALYZED);
yield return CreateFieldWithCaching(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
//.........这里部分代码省略.........
示例5: CreateFields
/// <summary>
/// This method generate the fields for indexing documents in lucene from the values.
/// Given a name and a value, it has the following behavior:
/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
/// * If the value is string or was set to not analyzed, create a single field with the supplied name
/// * If the value is date, create a single field with millisecond precision with the supplied name
/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
/// 1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
/// 2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
/// </summary>
private static IEnumerable<AbstractField> CreateFields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
if (value == null)
{
yield return new Field(name, "NULL_VALUE", indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED);
yield break;
}
var fields = value as IEnumerable<AbstractField>;
if(fields != null)
{
foreach (var field in fields)
{
yield return field;
}
yield break;
}
if (indexDefinition.GetIndex(name, null) == Field.Index.NOT_ANALYZED)// explicitly not analyzed
{
yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
yield break;
}
if (value is string)
{
var index = indexDefinition.GetIndex(name, Field.Index.ANALYZED);
yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
index);
yield break;
}
if (value is DateTime)
{
yield return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if(value is bool)
{
yield return new Field(name, ((bool) value) ? "true" : "false", indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if(value is IConvertible) // we need this to store numbers in invariant format, so JSON could read them
{
var convert = ((IConvertible) value);
yield return new Field(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if (value is DynamicJsonObject)
{
var inner = ((DynamicJsonObject)value).Inner;
yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
yield return new Field(name, inner.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else
{
yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
yield return new Field(name, JToken.FromObject(value).ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
var numericField = new NumericField(name + "_Range", indexDefinition.GetStorage(name, defaultStorage), true);
if (value is int)
{
if(indexDefinition.GetSortOption(name) == SortOptions.Long)
yield return numericField.SetLongValue((int)value);
else
yield return numericField.SetIntValue((int)value);
}
if (value is long)
{
yield return numericField
.SetLongValue((long) value);
}
if (value is decimal)
{
yield return numericField
.SetDoubleValue((double)(decimal)value);
}
if (value is float)
{
if (indexDefinition.GetSortOption(name) == SortOptions.Double)
yield return numericField.SetDoubleValue((float)value);
//.........这里部分代码省略.........
示例6: Createfields
/// <summary>
/// This method generate the fields for indexing documents in lucene from the values.
/// Given a name and a value, it has the following behavior:
/// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
/// * If the value is string or was set to not analyzed, create a single field with the supplied name
/// * If the value is date, create a single field with millisecond precision with the supplied name
/// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
/// 1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
/// 2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
/// </summary>
private static IEnumerable<AbstractField> Createfields(string name, object value, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
if (value == null)
{
yield return new Field(name, "NULL_VALUE", indexDefinition.GetStorage(name, defaultStorage),
Field.Index.NOT_ANALYZED);
yield break;
}
if (indexDefinition.GetIndex(name, Field.Index.ANALYZED) == Field.Index.NOT_ANALYZED || value is string)
{
yield return new Field(name, value.ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.ANALYZED));
yield break;
}
if (value is DateTime)
{
yield return new Field(name, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND),
indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
else if(value is IConvertible) // we need this to store numbers in invariant format, so JSON could read them
{
var convert = ((IConvertible) value);
yield return new Field(name, convert.ToString(CultureInfo.InvariantCulture), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, GetDefaultIndexOption(value)));
}
else
{
yield return new Field(name + "_ConvertToJson", "true", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
yield return new Field(name, JToken.FromObject(value).ToString(), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, GetDefaultIndexOption(value)));
}
if (value is int)
{
yield return new Field(name +"_Range", NumberUtil.NumberToString((int)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is long)
{
yield return new Field(name + "_Range", NumberUtil.NumberToString((long)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is decimal)
{
yield return new Field(name + "_Range", NumberUtil.NumberToString((double)(decimal)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is float)
{
yield return new Field(name + "_Range", NumberUtil.NumberToString((float)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
if (value is double)
{
yield return new Field(name + "_Range", NumberUtil.NumberToString((double)value), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED));
}
}