Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure we know the source expressions for dynamic index being merged

  • Loading branch information...
commit 7e1ee9f632dfab4a6181e998ea2a3612e9fe86ad 1 parent 902fc96
@ayende ayende authored
View
6 Raven.Abstractions/Indexing/IndexDefinition.cs
@@ -137,6 +137,12 @@ public bool IsMapReduce
/// <value>The spatial options.</value>
public IDictionary<string, SpatialOptions> SpatialIndexes { get; set; }
+ /// <summary>
+ /// Internal map of field names to expressions generating them
+ /// Only relevant for auto indexes and only used internally
+ /// </summary>
+ public IDictionary<string, string> InternalFieldsMapping { get; set; }
+
/// <summary>
/// Equals the specified other.
/// </summary>
View
29 Raven.Database/Data/DynamicQueryMapping.cs
@@ -118,8 +118,14 @@ public IndexDefinition CreateIndexDefinition()
realMappings.Concat(new[] { AggregationMapPart() }).Where(x => x != null))),
Reduce = DynamicAggregation ? null : AggregationReducePart(),
TransformResults = DynamicAggregation ? AggregationReducePart() : null,
+ InternalFieldsMapping = new Dictionary<string,string>()
};
+ foreach (var item in Items)
+ {
+ index.InternalFieldsMapping[item.To] = item.From;
+ }
+
if (DynamicAggregation)
{
foreach (var item in GroupByItems)
@@ -289,21 +295,22 @@ private void SetupSortDescriptors(DynamicSortInfo[] sortDescriptors)
public void AddExistingIndexDefinition(IndexDefinition indexDefinition, DocumentDatabase database, IndexQuery query)
{
- var abstractViewGenerator = database.IndexDefinitionStorage.GetViewGenerator(indexDefinition.Name);
- if (abstractViewGenerator == null) return; // No biggy, it just means we'll have two small indexes and we'll do this again later
+ var existing = database.IndexDefinitionStorage.GetIndexDefinition(indexDefinition.Name);
+ if (existing == null || existing.InternalFieldsMapping == null)
+ return; // No biggy, it just means we'll have two small indexes and we'll do this again later
this.Items = this.Items.Union(
- abstractViewGenerator.Fields
- .Where(field => this.Items.All(item => item.To != field) && !field.StartsWith("__"))
+ existing.InternalFieldsMapping
+ .Where(field => this.Items.All(item => item.To != field.Key) && !field.Key.StartsWith("__"))
.Select(field => new DynamicQueryMappingItem()
{
- From = field,
- To = ReplaceInvalidCharactersForFields(field),
- QueryFrom = EscapeParentheses(field)
+ From = field.Value,
+ To = ReplaceInvalidCharactersForFields(field.Key),
+ QueryFrom = EscapeParentheses(field.Key)
})
).ToArray();
- this.SortDescriptors = this.SortDescriptors.Union(
+ this.SortDescriptors = this.SortDescriptors.Union(
indexDefinition.SortOptions
.Where(option => this.SortDescriptors.All(desc => desc.Field != option.Key))
.Select(option => new DynamicSortInfo()
@@ -313,19 +320,19 @@ public void AddExistingIndexDefinition(IndexDefinition indexDefinition, Document
})
).ToArray();
- foreach (var fieldStorage in abstractViewGenerator.Stores)
+ foreach (var fieldStorage in existing.Stores)
{
KeyValuePair<string, FieldStorage> storage = fieldStorage;
extraActionsToPerform.Add(def=> def.Stores[storage.Key] = storage.Value);
}
- foreach (var fieldIndex in abstractViewGenerator.Indexes)
+ foreach (var fieldIndex in existing.Indexes)
{
KeyValuePair<string, FieldIndexing> index = fieldIndex;
extraActionsToPerform.Add(def=> def.Indexes[index.Key] = index.Value);
}
- foreach (var fieldTermVector in abstractViewGenerator.TermVectors)
+ foreach (var fieldTermVector in existing.TermVectors)
{
KeyValuePair<string, FieldTermVector> vector = fieldTermVector;
extraActionsToPerform.Add(def=> def.TermVectors[vector.Key] = vector.Value);
View
53 Raven.Tests/MailingList/ComplexIndexMerge.cs
@@ -0,0 +1,53 @@
+// -----------------------------------------------------------------------
+// <copyright file="ComplexIndexMerge.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System;
+using System.Linq;
+using Raven.Client.Document;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class ComplexIndexMerge : RavenTest
+ {
+ public class Ref
+ {
+ public Guid Id { get; set; }
+ }
+
+ public class Entity
+ {
+ public Ref EntityARef { get; set; }
+ public Ref EntityBRef { get; set; }
+ }
+
+ [Fact]
+ public void CanQueryOnBothProperties()
+ {
+ using (var store = NewDocumentStore())
+ {
+ store.Conventions.DefaultQueryingConsistency =
+ ConsistencyOptions.AlwaysWaitForNonStaleResultsAsOfLastWrite;
+ using (var session = store.OpenSession())
+ {
+ session.Store(new Entity
+ {
+ EntityARef = new Ref(),
+ EntityBRef = new Ref()
+ });
+ session.SaveChanges();
+ }
+
+ using (var session = store.OpenSession())
+ {
+ var id = Guid.Empty;
+ Assert.NotEmpty(session.Query<Entity>().Where(x => x.EntityARef.Id == id).ToList());
+ Assert.NotEmpty(session.Query<Entity>().Where(x => x.EntityBRef.Id == id).ToList());
+ Assert.NotEmpty(session.Query<Entity>().Where(x => x.EntityARef.Id == id).ToList());
+ }
+ }
+ }
+ }
+}
View
1  Raven.Tests/Raven.Tests.csproj
@@ -723,6 +723,7 @@
<Compile Include="MailingList\ChangeTrackingDoesntWorkForDecimalsWithSmallChanges.cs" />
<Compile Include="MailingList\Chirea.cs" />
<Compile Include="MailingList\CoalescingOperatorWithStringARray.cs" />
+ <Compile Include="MailingList\ComplexIndexMerge.cs" />
<Compile Include="MailingList\CompoundOrQueryWithOrderByDescending .cs" />
<Compile Include="MailingList\ConcurrencyTests.cs" />
<Compile Include="MailingList\CustomizingIndexQuery.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.