本文整理汇总了C#中Raven.Database.Indexing.IndexDefinition类的典型用法代码示例。如果您正苦于以下问题:C# IndexDefinition类的具体用法?C# IndexDefinition怎么用?C# IndexDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexDefinition类属于Raven.Database.Indexing命名空间,在下文中一共展示了IndexDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateIndexImplementation
private Index CreateIndexImplementation(string name, IndexDefinition indexDefinition, Lucene.Net.Store.Directory directory)
{
var viewGenerator = indexDefinitionStorage.GetViewGenerator(name);
return indexDefinition.IsMapReduce
? (Index)new MapReduceIndex(directory, name, indexDefinition, viewGenerator)
: new SimpleIndex(directory, name, indexDefinition, viewGenerator);
}
示例2: MapReduceIndex
public MapReduceIndex(Directory directory, int id, IndexDefinition indexDefinition,
AbstractViewGenerator viewGenerator, WorkContext context)
: base(directory, id, indexDefinition, viewGenerator, context)
{
jsonSerializer = JsonExtensions.CreateDefaultJsonSerializer();
jsonSerializer.Converters = MapReduceConverters;
}
示例3: DynamicViewCompiler
public DynamicViewCompiler(string name, IndexDefinition indexDefinition, AbstractDynamicCompilationExtension[] extensions)
{
this.indexDefinition = indexDefinition;
this.extensions = extensions;
this.name = MonoHttpUtility.UrlEncode(name);
RequiresSelectNewAnonymousType = true;
}
示例4: OpenOrCreateLuceneDirectory
protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(IndexDefinition indexDefinition, string indexName = null)
{
Lucene.Net.Store.Directory directory;
if (indexDefinition.IsTemp || configuration.RunInMemory)
{
directory = new RAMDirectory();
new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Close(); // creating index structure
}
else
{
var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path);
var indexFullPath = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory));
directory = FSDirectory.Open(new DirectoryInfo(indexFullPath));
if (!IndexReader.IndexExists(directory))
{
//creating index structure if we need to
new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Close();
}
else
{
// forcefully unlock locked indexes if any
if (IndexWriter.IsLocked(directory))
IndexWriter.Unlock(directory);
}
}
return directory;
}
示例5: ToLuceneSortField
public Lucene.Net.Search.SortField ToLuceneSortField(IndexDefinition definition)
{
var sortOptions = definition.GetSortOption(Field);
if(sortOptions == null)
return new Lucene.Net.Search.SortField(Field, CultureInfo.InvariantCulture, Descending);
return new Lucene.Net.Search.SortField(Field, (int)sortOptions.Value);
}
示例6: Convert_select_many_will_keep_doc_id
public void Convert_select_many_will_keep_doc_id()
{
IndexDefinition indexDefinition = new IndexDefinition<Order>
{
Map = orders => from order in orders
from line in order.OrderLines
select new { line.ProductId }
}.ToIndexDefinition(new DocumentConvention());
var generator = new DynamicViewCompiler("test", indexDefinition, new AbstractDynamicCompilationExtension[0])
.GenerateInstance();
var results = generator.MapDefinition(new[]
{
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Orders', '@id': 1},
'OrderLines': [{'ProductId': 2}, {'ProductId': 3}]
}"),
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Orders', '@id': 2},
'OrderLines': [{'ProductId': 5}, {'ProductId': 4}]
}")
}).Cast<object>().ToArray();
foreach (var result in results)
{
Assert.NotNull(TypeDescriptor.GetProperties(result).Find("__document_id", true));
}
}
示例7: AddIndex
public string AddIndex(string name, IndexDefinition indexDefinition)
{
DynamicViewCompiler transformer = AddAndCompileIndex(name, indexDefinition);
if(configuration.RunInMemory == false)
File.WriteAllText(Path.Combine(path, transformer.Name + ".index"), JsonConvert.SerializeObject(indexDefinition, Formatting.Indented, new JsonEnumConverter()));
return transformer.Name;
}
示例8: RetrieveDocumentInternal
private JsonDocument RetrieveDocumentInternal(
IndexQueryResult queryResult,
HashSet<string> loadedIds,
IEnumerable<string> fieldsToFetch,
IndexDefinition indexDefinition,
AggregationOperation aggregationOperation)
{
if (queryResult.Projection == null)
{
// duplicate document, filter it out
if (loadedIds.Add(queryResult.Key) == false)
return null;
return GetDocumentWithCaching(queryResult.Key);
}
if (fieldsToFetch != null)
{
if (indexDefinition.IsMapReduce == false)
{
bool hasStoredFields = false;
foreach (var fieldToFetch in fieldsToFetch)
{
FieldStorage value;
if (indexDefinition.Stores.TryGetValue(fieldToFetch, out value) == false &&
value != FieldStorage.No)
continue;
hasStoredFields = true;
}
if (hasStoredFields == false)
{
// duplicate document, filter it out
if (loadedIds.Add(queryResult.Key) == false)
return null;
}
}
if (aggregationOperation != AggregationOperation.None)
{
var aggOpr = aggregationOperation & ~AggregationOperation.Dynamic;
fieldsToFetch = fieldsToFetch.Concat(new[] {aggOpr.ToString()});
}
var fieldsToFetchFromDocument = fieldsToFetch.Where(fieldToFetch => queryResult.Projection.Property(fieldToFetch) == null);
var doc = GetDocumentWithCaching(queryResult.Key);
if (doc != null)
{
var result = doc.DataAsJson.SelectTokenWithRavenSyntax(fieldsToFetchFromDocument.ToArray());
foreach (var property in result.Properties())
{
if(property.Value == null || property.Value.Type == JTokenType.Null)
continue;
queryResult.Projection[property.Name] = property.Value;
}
}
}
return new JsonDocument
{
Key = queryResult.Key,
Projection = queryResult.Projection,
};
}
示例9: ReadIndexesFromCatalog
private void ReadIndexesFromCatalog(IEnumerable<AbstractViewGenerator> compiledGenerators, ITransactionalStorage transactionalStorage)
{
foreach (var generator in compiledGenerators)
{
var copy = generator;
var displayNameAtt = TypeDescriptor.GetAttributes(copy)
.OfType<DisplayNameAttribute>()
.FirstOrDefault();
var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;
transactionalStorage.Batch(actions =>
{
if (actions.Indexing.GetIndexesStats().Any(x => x.Name == name))
return;
actions.Indexing.AddIndex(name);
});
var indexDefinition = new IndexDefinition
{
Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
// need to supply this so the index storage will create map/reduce index
Reduce = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
Indexes = generator.Indexes,
Stores = generator.Stores,
IsCompiled = true
};
indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
}
}
示例10: AnonymousObjectToLuceneDocumentConverter
public AnonymousObjectToLuceneDocumentConverter(DocumentDatabase database, IndexDefinition indexDefinition, AbstractViewGenerator viewGenerator, ILog log)
{
this.database = database;
this.indexDefinition = indexDefinition;
this.viewGenerator = viewGenerator;
this.log = log;
}
示例11: Index
public static IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != "__document_id"
let value = property.GetValue(val)
where value != null
select Createfield(name, value, indexDefinition, defaultStorage));
}
示例12: Index
public static IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition, Field.Store defaultStorage)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != Constants.DocumentIdFieldName
let value = property.GetValue(val)
from field in CreateFields(name, value, indexDefinition, defaultStorage)
select field);
}
示例13: GetSort
internal override Lucene.Net.Search.Sort GetSort(Lucene.Net.Search.Filter filter, IndexDefinition indexDefinition)
{
if (SortByDistance == false)
return base.GetSort(filter, indexDefinition);
var dsort = new Lucene.Net.Spatial.Tier.DistanceFieldComparatorSource((Lucene.Net.Spatial.Tier.DistanceFilter)filter);
return new Lucene.Net.Search.Sort(new Lucene.Net.Search.SortField("foo", dsort, false));
}
示例14: 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)));
}
示例15: CanPerformSpatialSearch
public void CanPerformSpatialSearch()
{
var indexDefinition = new IndexDefinition
{
Map = "from e in docs.Events select new { Tag = \"Event\", _ = SpatialGenerate(e.Latitude, e.Longitude) }",
Indexes = {
{ "Tag", FieldIndexing.NotAnalyzed }
}
};
store.DatabaseCommands.PutIndex("eventsByLatLng", indexDefinition);
var events = SpatialIndexTestHelper.GetEvents();
for (int i = 0; i < events.Length; i++)
{
store.DatabaseCommands.Put("Events/" + (i + 1), null,
RavenJObject.FromObject(events[i]),
RavenJObject.Parse("{'Raven-Entity-Name': 'Events'}"));
}
const double lat = 38.96939, lng = -77.386398;
const double radiusInKm = 6.0*1.609344;
QueryResult queryResult;
do
{
queryResult = store.DatabaseCommands.Query("eventsByLatLng", new SpatialIndexQuery()
{
Query = "Tag:[[Event]]",
QueryShape = SpatialIndexQuery.GetQueryShapeFromLatLon(lat, lng, radiusInKm),
SpatialRelation = SpatialRelation.Within,
SpatialFieldName = Constants.DefaultSpatialFieldName,
SortedFields = new[] { new SortedField("__distance"), }
}, null);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
var expected = events.Count(e => GetGeographicalDistance(lat, lng, e.Latitude, e.Longitude) <= radiusInKm);
Assert.Equal(expected, queryResult.Results.Count);
Assert.Equal(7, queryResult.Results.Count);
double previous = 0;
foreach (var r in queryResult.Results)
{
Event e = r.JsonDeserialization<Event>();
double distance = GetGeographicalDistance(lat, lng, e.Latitude, e.Longitude);
Console.WriteLine("Venue: " + e.Venue + ", Distance " + distance);
Assert.True(distance < radiusInKm);
Assert.True(distance >= previous);
previous = distance;
}
}