Hi folks,
I'm playing around with the
Search functionality in RavenDb. I'm trying to understand certain parts of the creating a
Static Index to handle various result types (remember, I'm just playing/experimenting/learning).
My first two goals I'm trying experiment with are:
1) Simple Search that uses the FieldIndexing.Analyzed and returns the documents, untouched (eg. the document(s))
2) Another Search which still uses the FieldIndexing.Analyzed but returns a different result poco(s).
So, to start out .. here are the two query's i'm trying to play around with:
/*
* Sample Data
* City: New York City; Region: NY
* City: Melbourne; Region: FL
* City: Melbourne; Region: VIC
* City: Hadera; Region: Haifa District
* eg. documentSession.Store(new Location("New York City", "NY"));
*/
// Expected: 1 / New York City / NY
var result1 = await AsyncDocumentSession.Query<Location>
.Search(x => x.Query, "new york")
.ToListAsync();
// Expected: 1 / New York City / NY
// NOTE: as a view model
var result2 = await AsyncDocumentSession.Query<ViewModel>
.Search(x => x.Query, "new york")
.ToListAsync();
So the first one returns the document that is stored in the DocStore. (class defined, below). (eg. SELECT * FROM Table WHERE xxxxx)
The second query is returning a different POCO result. This is an example of returning a smaller amount of data over the network. (SELECT Col1, Col2 FROM Table WHERE xxxxx)
(Apologies for the unfair comparison to a sql statement vs nosql concepts... )
Here's the 2x POCO classes ...
/* This is the class that is stored into the DocStore.. */
public class Location
{
public string Id { get; set; }
public string City { get; set; }
public string Region { get; set; }
}
public class ViewModel
{
public string CityName { get; set; }
}
First one is the doc that is stored in the docStore. Second is an example of a class that has a different Property name and a reduced number of properties compared to the original document.
Finally, here's the index.,.
public class LocationSearch : AbstractMultiMapIndexCreationTask<Location>
{
public LocationSearch()
{
AddMap<Location>(locations =>
from location in locations
select new
{
Query = new object[]
{
location.City,
location.Region
}
});
// How to index this Query property?
Index(x => x.Query, FieldIndexing.Analyzed);
}
}
So experimenting with this, I found that I couldn't create an index on the anonymous select.
So - any help please?
-J-