Ejemplo n.º 1
0
        public AnnoyIndexSearchResult GetNearestToItem(
            ulong itemIndex,
            uint nResult,
            int searchK,
            bool shouldIncludeDistance)
        {
            if (_indexPtr == IntPtr.Zero)
            {
                throw new ObjectDisposedException("index");
            }

            var searchResultPtr = NativeMethods.GetNearestToItem(
                _indexPtr,
                itemIndex,
                nResult,
                searchK,
                shouldIncludeDistance);

            try
            {
                return(AnnoyIndexSearchResult.LoadFromPtr(searchResultPtr, shouldIncludeDistance));
            }
            finally
            {
                NativeMethods.FreeSearchResult(searchResultPtr);
            }
        }
Ejemplo n.º 2
0
        public AnnoyIndexSearchResult GetNearest(
            IReadOnlyList <float> queryVector,
            uint nResult,
            int searchK,
            bool shouldIncludeDistance)
        {
            if (_indexPtr == IntPtr.Zero)
            {
                throw new ObjectDisposedException("index");
            }

            var searchResultPtr = NativeMethods.GetNearest(
                _indexPtr,
                queryVector.ToArray(),
                nResult,
                searchK,
                shouldIncludeDistance);

            try
            {
                return(AnnoyIndexSearchResult.LoadFromPtr(searchResultPtr, shouldIncludeDistance));
            }
            finally
            {
                NativeMethods.FreeSearchResult(searchResultPtr);
            }
        }