Beispiel #1
0
        private KnnQueryResult InternalKnnSearch(KnnQuery query)
        {
            // get search area
            var searchArea = GetSearchArea(query);

            // query the quadtree
            var docs = _quadTree.Search(searchArea);

            // almost done, but remember we searched a rectangle
            // so we need to exclude some of these results.
            // Let's do that while calculating the distance

            var results = new List <KnnQueryResultItem>();

            foreach (var doc in docs)
            {
                var distance = query.Coordinate.CalculateDistance(doc.Coordinates);
                if (distance <= query.MaxDistance)
                {
                    results.Add(new KnnQueryResultItem(doc, distance));
                }
            }

            // this could be done more efficiently by inserting into an ordered structure
            // unfortunatelly SortedList<> doesn't allow duplicated keys.
            // but there is definetely space for optimization here
            results.Sort((x, y) => x.Distance.CompareTo(y.Distance));

            // reduce set to max results
            results = results.Take(query.MaxResults).ToList();

            return(KnnQueryResult.Success(results));
        }
Beispiel #2
0
        public KnnQueryResult KnnSearch(KnnQuery query)
        {
            var search =
                from doc in _docs
                let distance = query.Coordinate.CalculateDistance(doc.Coordinates)
                               where distance <= query.MaxDistance
                               orderby distance
                               select new KnnQueryResultItem(doc, distance);

            // list results taking top max
            var results = search.Take(query.MaxResults).ToList();

            return(KnnQueryResult.Success(results));
        }
Beispiel #3
0
        public KnnQueryResult KnnSearch(KnnQuery query)
        {
            if (query == null)
            {
                throw new ArgumentException("Parameter query cannot be null");
            }

            // validate query
            if (!IsQueryValid(query))
            {
                return(KnnQueryResult.Fail("Query is not valid. Please verify search parameters"));
            }

            // execute search
            var result = InternalKnnSearch(query);

            return(result);
        }
Beispiel #4
0
 public KnnQueryResult KnnSearch(KnnQuery query)
 {
     return(KnnQueryResult.ZeroResults());
 }