Skip to content

Commit

Permalink
Making sure to compare (in code) in the same manner as we compare in …
Browse files Browse the repository at this point in the history
…Esent for starts with
  • Loading branch information
ayende committed Nov 13, 2015
1 parent 675b411 commit 1d7bdba
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Raven.Database/Storage/Esent/StorageActions/Documents.cs
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -418,13 +419,44 @@ public IEnumerable<JsonDocument> GetDocumentsWithIdStartingWith(string idPrefix,
{
var keyFromDb = Api.RetrieveColumnAsString(session, Documents, tableColumnsCache.DocumentsColumns["key"], Encoding.Unicode);
if (keyFromDb.StartsWith(idPrefix, StringComparison.OrdinalIgnoreCase) == false)
{
if (StartsWithIgnoreCaseAndSymbols(keyFromDb, idPrefix))
continue;
yield break;
}

yield return ReadCurrentDocument();
take--;
} while (Api.TryMoveNext(session, Documents) && take > 0);
}

private bool StartsWithIgnoreCaseAndSymbols(string keyFromDb, string idPrefix)
{
var keyPos = 0;
for (int i = 0; i < idPrefix.Length; i++)
{
var idChar = idPrefix[i];
if(char.IsSymbol(idChar) ||
char.IsPunctuation(idChar))
continue;
char keyChar;
do
{
if (keyPos >= keyFromDb.Length)
return false; // too short
keyChar = keyFromDb[keyPos++];
} while (char.IsSymbol(keyChar) || char.IsPunctuation(keyChar));
if(idChar == keyChar)
continue;
// maybe different casing?
if(char.ToUpperInvariant(keyChar) ==
char.ToUpperInvariant(idChar))
continue;
return false;
}
return true;
}

public Etag GetEtagAfterSkip(Etag etag, int take, CancellationToken cancellationToken)
{
Api.JetSetCurrentIndex(session, Documents, "by_etag");
Expand Down
1 change: 1 addition & 0 deletions Raven.Tests.MailingList/Raven.Tests.MailingList.csproj
Expand Up @@ -471,6 +471,7 @@
<Compile Include="UpdatingData.cs" />
<Compile Include="UriProperty.cs" />
<Compile Include="UrlInIdsRepro.cs" />
<Compile Include="UsingLoadStartsWithAndDashSepartor.cs" />
<Compile Include="VacancyCampaignsTests.cs" />
<Compile Include="ValerioBorioni.cs" />
<Compile Include="Vicente.cs" />
Expand Down
38 changes: 38 additions & 0 deletions Raven.Tests.MailingList/UsingLoadStartsWithAndDashSepartor.cs
@@ -0,0 +1,38 @@
// -----------------------------------------------------------------------
// <copyright file="UsingLoadStartsWithAndDashSepartor.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Threading;
using Raven.Json.Linq;
using Raven.Tests.Common;
using Xunit;
using Xunit.Extensions;

namespace Raven.Tests.MailingList
{
public class UsingLoadStartsWithAndDashSeperator : RavenTest
{
[Theory]
[PropertyData("Storages")]
public void ShouldWork(string storage)
{
using (var store = NewDocumentStore(requestedStorage: storage))
{


//store.DocumentDatabase.Documents.Put("delivery-ORT0529.2", null, new RavenJObject(),
// new RavenJObject(), null);
store.DocumentDatabase.Documents.Put("DeliveryReport-1000", null, new RavenJObject(),
new RavenJObject(), null);

store.DocumentDatabase.Documents.Put("delivery-RT0753.2", null, new RavenJObject(),
new RavenJObject(), null);

int nextStart = 0;
var docs = store.DocumentDatabase.Documents.GetDocumentsWithIdStartingWith("delivery-", null, null,0, 1024, CancellationToken.None, ref nextStart);
Assert.Equal(1, docs.Length);
}
}
}
}

0 comments on commit 1d7bdba

Please sign in to comment.