Experimenting with Query<T> and (full text) Searching.

48 views
Skip to first unread message

Justin A

unread,
Sep 22, 2014, 10:00:21 AM9/22/14
to rav...@googlegroups.com
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-

Chris Marisic

unread,
Sep 22, 2014, 11:16:39 AM9/22/14
to rav...@googlegroups.com

  Index(x => x.Query, FieldIndexing.Analyzed);

Will not compile because that property doesn't exist. you could add the query property to your Location class, but that doesn't really make sense. There should be an overload of Index that has a signature like Index("Query",
FieldIndexing.Analyzed)

if there is not an overload for this, you can do something like

public override IndexDefinition CreateIndexDefinition()
{
var index = base.CreateIndexDefinition();
index.Indexes.Add("Query", FieldIndexing.Analyzed)
}

But i'm pretty sure there should be string overloads, I believe I'm the person that pointed out the lack of them and that it's odd to do what i did with the override above.


Kijana Woodard

unread,
Sep 22, 2014, 11:43:01 AM9/22/14
to rav...@googlegroups.com
I'm having trouble following. What's an "anonymous select"?

From what I can see, why not use OfType or ProjectFromIndexFieldsInto?
Or, why not use a Results Transformer?

Why a multimap index?


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin A

unread,
Sep 22, 2014, 5:24:26 PM9/22/14
to rav...@googlegroups.com
>> What's an "anonymous select"?

Oh - i ment this bit ...
...
select new
{
    Query = new object[]
...

>>From what I can see, why not use OfType or ProjectFromIndexFieldsInto?
>>Or, why not use a Results Transformer?

That's part of my question : do I *have* to do that? can the query be re-written another way? If not, how can I write it that way? Using those other options, does that send the entire document data down the wire (per result) and only at the end on the client, does it copy the results to a different class type? Is there a way to reduce the result payload size across the wire? (this is my poor analogy of SELECT * vs SELECT Col1, Col2 ..

Justin A

unread,
Sep 22, 2014, 5:27:39 PM9/22/14
to rav...@googlegroups.com
>> Why a multimap index?

No reason - I'm experimenting only. More than happy to be shown a simpler way.

Kijana Woodard

unread,
Sep 22, 2014, 5:57:52 PM9/22/14
to rav...@googlegroups.com
ProjectFromIndexFieldsInto and ResultsTransformer will only send the requested properties. Not sure about OfType. Is the doc huge or something?

IMO, results transformer is probably best.

On Mon, Sep 22, 2014 at 4:27 PM, Justin A <jus...@adler.com.au> wrote:
>> Why a multimap index?

No reason - I'm experimenting only. More than happy to be shown a simpler way.

--

Justin A

unread,
Sep 22, 2014, 6:07:15 PM9/22/14
to rav...@googlegroups.com
The example above in my opening post is contrite. So this is really just an experiment to better understand what RavenDB is doing behind the scenes.

In the above document, it's 2 properties that are not large. But I'm thinking about documents that might have .. say .. 20 properties and I only want 3 of them. OR .. like my second 'result example', I want 1 or 2 properties which might be the the result of some *other* properties on the original document. (eg. name == first name + " " + surname).

>> results transformer is probably best.

can you please modify my existing index with an example(s) please?

Kijana Woodard

unread,
Sep 22, 2014, 9:35:09 PM9/22/14
to rav...@googlegroups.com
I'm a bit short on time, but the example in the docs looks fairly clear:

The "trick" is to have the other class with the "transformation shape".

--
Reply all
Reply to author
Forward
0 new messages