Reverse in index #17493
-
In the documentation for full-text search with wildcards, it states:
If I put a I've tried: text.Reverse().ToString() ?? string.Empty
text.ToArray().Reverse().ToString() ?? string.Empty
text.ToCharArray().Reverse().ToString() ?? string.Empty All of these will give me a variation of
What is the correct way to do this? The documentation even shows this. https://ravendb.net/docs/article-page/5.4/csharp/indexes/indexing-linq-extensions#reverse I looked at the source code and that isn't one of the extensions in Here is code to reproduce. #nullable enable
void Main()
{
using var store = new DocumentStore
{
Database = "Test1",
Urls = new string[] { "http://localhost:8080" }
};
store.Initialize();
IndexCreation.CreateIndexes(typeof(Foo_BySomething).Assembly, store);
using var session = store.OpenSession();
session.Store(new Foo { IpAddress = "1.2.3.4" });
session.SaveChanges();
}
public class Foo
{
public string? Id { get; set; }
public string IpAddress { get; set; } = string.Empty;
public List<Bar> Bars { get; set; } = new List<Bar>();
}
public class Bar
{
public string IpAddress { get; set; } = string.Empty;
}
public class Foo_BySomething : AbstractIndexCreationTask<Foo, Foo_BySomething.Result>
{
public class Result
{
public string FooIp { get; set; } = string.Empty;
public string FooIpReverse { get; set; } = string.Empty;
public string BarIp { get; set; } = string.Empty;
public string BarIpReverse { get; set; } = string.Empty;
}
public Foo_BySomething()
{
Map = foos =>
from f in foos
from b in f.Bars.DefaultIfEmpty()
let fooIp = Regex.Replace(f.IpAddress, "[^0-9a-fA-F]", "").ToUpper()
let barIp = Regex.Replace(b.IpAddress ?? string.Empty, "[^0-9a-fA-F]", "").ToUpper()
select new Result
{
FooIp = fooIp,
FooIpReverse = fooIp.Reverse().ToString() ?? string.Empty,
BarIp = barIp,
BarIpReverse = barIp.Reverse().ToString() ?? string.Empty
};
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
@JoshClose |
Beta Was this translation helpful? Give feedback.
-
A workaround for now would be to do the reverse before you use |
Beta Was this translation helpful? Give feedback.
You can track the status of this issue here:
https://issues.hibernatingrhinos.com/issue/RavenDB-21559/string-does-not-contain-a-definition-for-Reverse