Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:01:41+00:00 2026-06-06T13:01:41+00:00

Following the example on the RevenDB site , I came up with this: public

  • 0

Following the example on the RevenDB site, I came up with this:

public class Place_ByLocationsAndCategoryId : AbstractIndexCreationTask<Place> {
    public Place_ByLocationsAndCategoryId() {
        Map = places => from p in places
                                select new { p.Categories, _ = Raven.Database.Indexing.SpatialIndex.Generate(p.Location.Lat, p.Location.Lng) };
    }
}

Places look something like this:

Place {
    string Id;
    List<Category> Categories;
    ...
}

Categories look something like this:

Category {
    string Id;
    string Name;
    ...
}

How can I build my index so that I may query by places within a given radius of a lat/lng, and contains a given category?

I attempted to query the index above like so:

 var placesFromDb = RavenSession.Advanced.LuceneQuery<Place>("Place/ByLocationsAndCategoryId").WhereIn("Id", new []{cat.Id}).WithinRadiusOf(radius: 5, latitude: Lat, longitude: Lng).ToList<Place>();

The query processes, but returns no results (when I know there are results to be returned. My error is probably in the .WhereIn() statement, but when I tried to use .Where(x => x.Categories.Any(c => c.Id == id)) I got a build error stating it was obsolete.


–Update–

I switched my index to this (as Ayende recommended)

public Place_ByLocationsAndCategoryId() {
    Map = places => from p in places
                    select new { Categories_Id = p.Categories.Select(x => x.Id), _ = Raven.Database.Indexing.SpatialIndex.Generate(p.Location.Lat, p.Location.Lng) };
}

I create the index on the document store like so:

IndexCreation.CreateIndexes(typeof(Place_ByLocationsAndCategoryId).Assembly, Store);

I query it like so:

var placesFromDb = RavenSession.Advanced.LuceneQuery<Place>("Place/ByLocationsAndCategoryId").WhereEquals("Categories_Id ", cat.Id).WithinRadiusOf(radius: 15, latitude: Lat, longitude: Lng).ToList<Place>();

This is what the index looks like on RavenDB itself:

docs.Places
    .Select(p => new {Categories_Id = p.Categories
    .Select(x => x.Id), _ = SpatialIndex.Generate(((System.Double)(p.Location.Lat)), ((System.Double)(p.Location.Lng)))})

The query seems to run, but returns 0 results (I know there are places to be found).
One thing I noticed is that the Lat and Lng data types in my model are floats, while it appears the index is set to Double.

Trying to cast the coordinates in the index like so, also does not work:

public Place_ByLocationsAndCategoryId() {
    Map = places => from p in places
                    select new { Categories_Id = p.Categories.Select(x => x.Id), _ = Raven.Database.Indexing.SpatialIndex.Generate((float)p.Location.Lat, (float)p.Location.Lng) };
}

So I switched my model to use doubles; still returns 0 results.


–Update 2–

If I remove the category part of the index, and query just the spatial part, it returns places. It appears the category part isn’t functioning as planned.

In case it helps, here’s how partially how a stored document looks (JSON view):

{
  "Id": "4dca6d56d22da18f4e626f54",
  "Name": "焼肉",
  "Categories": [
    {
      "PlaceCategories": null,
      "Name": "Korean Restaurant",
      "Icon": "korean.png",
      "Id": "4bf58dd8d48988d113941735",
      "IsPrimary": true
    }
  ],
  "Location": {
    "Lat": "35.6709824",
    "Lng": "139.374588"
  },
  ...
}

(note: Categories is the List, categories can have subcategories, in their own List property named PlaceCategories)


–Update 3–

Here’s the index error from the management studio:

Places/ByLocationsAndCategoryId 
Cannot convert type 'string' to 'float' 
6/27/2012 
places/1025
... and repeats 50 times

I have already changed my model from float to double, because it looked like the spatial generator wanted doubles. Good chance that there are some errors in the log (can’t see past 50), stating `Cannot convert type ‘string’ to ‘float’

I’m curious, in my model previously, my Lat/Lng were floats. Where is the string coming from?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:01:43+00:00Added an answer on June 6, 2026 at 1:01 pm

    It turns out it was my model. For future reference, if you want to use spatial indexes in Raven, you must store your coordinates as double (mine were float originally). I did change to double, but had to write a script to go through all my documents in the DB and convert the coordinates to double.

    Worked like a champ after that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following example, how to inject a class from third-party library? For example
I have the following example-class: public class MyClass<T> { public IList<T> GetAll() { return
Following example from this link: http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html #include <QObject> #include <QPushButton> #include <iostream> using namespace
Following this following example... public function insert($model,$brand,$price){ mysql_query(INSERT INTO autos (model, brand, price) VALUES
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
The following example is taken from: http://php.net/manual/en/function.curl-multi-close.php#example-3540 This example will create two cURL handles,
The following example, how do I refer base class instance? public class A {
I find the following example mildly surprising: >>> class Foo: def blah(self): pass >>>
The following example fails class A class B end end p Object.const_get 'A' #
Consider the following example from APUE book: #include <errno.h> #include <sys/socket.h> int initserver(int type,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.