It's quite embarrassing how long it's taken me to come to such a
simple solution, but oh well - pushed to my fork is functionality
like:
using (var s = store.OpenSession())
{
var results = s.DynamicQuery<Blog>()
.Customize(x =>
x.WaitForNonStaleResultsAsOfNow())
.Where(x => x.Category == "Rhinos" &&
x.Title.Length == 3)
.ToArray();
Assert.Equal(1, results.Length);
Assert.Equal("two", results[0].Title);
Assert.Equal("Rhinos", results[0].Category);
}
and
using (var s = store.OpenSession())
{
var results = s.DynamicLuceneQuery<Blog>()
.Where("Title.Length:3 AND Category:Rhinos")
.WaitForNonStaleResultsAsOfNow().ToArray();
Assert.Equal(1, results.Length);
Assert.Equal("two", results[0].Title);
Assert.Equal("Rhinos", results[0].Category);
}
I wouldn't class it as "done", trivial tidy up is needed (moving the
magic string "dynamic" to a constant somewhere - things like that)
A few of things to be aware of, and something I'm now going to devote
my afternoon to:
1) I had to modify the Linq provider to start using the full path to
the member instead of the name of the member, I don't think this will
break non-dynamic queries, but it's necessary for dynamic queries to
work (this is in RavenQueryProviderProcessor.GetMember)
2) I've had to do a hack where I remove [[ and ]] from the query when
running StandardAnalyzer over it to extract the terms as it doesn't
like them. It probably doesn't like other things either, and this was
my worry over parsing the Lucene query - I guess fix the issues as I
come across them and start thinking about using a better analyzer
3) I'm currently setting fields to NotAnalyzed by default which makes
my test queries function correctly, this is obviously not desired, but
reflects the assumption by the Linq provider that if it's anything
other than a string it is analyzed, and if it's a string it's not
analyzed
4) I've not yet added the code to delete obsolete indexes
5) I've not yet added the code to hash the index name if it's greater
than a certain number of characters
I intend on getting #4 and #5 sorted immediately
#2 and #3 I'm going to mull over, and by writing some tests against
dynamic queries for common use cases I aim to find the common pitfalls
and from that establish some more intelligent code from which to
generate more appropriate indexes.
That will lead nicely onto collection types (multiple froms), because
without a more intelligent solution to #3 that's not going to be
possible