Please help. This is melting my brain.
We are using Find 8.2.4
In our dev environment we have a small number of location based pages. They all inherit from a location base type that uses a GeoPoint to pick a location and a GeoLocation property that exposes the GeoPoint as a GeoLocation read-only property. When searching for location based results, however, we seem to be getting results that don't make logical sense. If I retrieve results for a Lat/Long from London using the following code, I get 2 results:
var results = SearchClient.Instance.Search()
.Filter(x => x.Location.WithinDistanceFrom(location, 1000.Miles()))
.OrderBy(y => y.Location).DistanceFrom(location).Take(10)
If I now change the Take(10) to Take(100), I get 75 results. OK, but why don't I get 10 results with the Take(10) version????
What's weirder, is that if I edit a page so that its Location is very close to the searched Lat/Long, it appears in the results (now I have 3). If I edit a the same page so that it is about 8 miles from the searched Lat/Long, it is no longer in the results (back to 2).
Is it just me, or is this illogical?
That doesn't seem right! I'm curious what the TotalMatching is and if it (somehow) changes depending on if you have Take(10) or Take(100)
If you can't figure out what's wrong and suspect it could be a bug I recommend you get in contact with EPiServer Support.
In both cases the TotalMatching is the same (304).
I had another thought about this: this is a dev environment with a CMS database shared between developers who sometimes use the shared db and sometimes use a local private db. But they will always use the same Find index. So it's possible there is a mis-match between pages in the index and pages in the CMS for some of the matches, which might give unpredictable results. I will try to figure out a way to test this.
That seems to be the solution. I created a brand new index on find.episerver.com and re-indexed the site. Now results are coming back as expected. So without definitively testing it, I'm pretty sure this is the reason it was causing this behaviour. In case others are interested, this is what I think happened:
I/my colleagues added pages using a local copy of the dev CMS database. These still get indexed on Find. I tested the search results on a shared copy of the database. Our search is ordering results by proximity to the searched location and then taking a pagesize number of them. When applying Take(10) to a search, therefore, Find returns 10 pages from its index that are closest to the London location used for testing, but some of these 10 did not exist in the CMS, so I only end up with 2 or 3. When using a Take(100), I was opening up the possibility of pages being in the same db. This also explains why it seemed to work better when testing a different location - probably the nearest 10 to Bradford, say, *were* in my CMS db.
This only applies to our dev environments at the moment (QA, Staging, Production all use a single CMS db), but worth thinking about for more complex architectures.