To run a reverse image search, use the SearchFirst method of the Searcher class. This method returns the first portion of results as a NetworkImageSearchResult object, which contains the images found in one shard.
To continue the search, the SearchNext method is used, returning the second and subsequent portions of results. Continue the search while the NetworkImageSearchToken property of the result is not null.
The search image object and search options object are the same as those used for single index searches. Images can be found only if image indexing was enabled when the documents were added.
The examples on this page use the master node of a running search network. The following code creates and starts the master node as described on the Search network deployment page; the slave nodes must be started beforehand.
C#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// Loading the search network configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");// Creating, configuring and starting the master node; the timeouts are specified in millisecondsSearchNetworkNodenode=SearchNetworkNode.CreateMasterNode(0,basePath+"Node0",newTcpSettings(basePort,3000,3000,3000,1000),newFileLogger(basePath+"Log.txt",4.0),configuration);node.ConfigureAllNodes();node.Start();
The following code example, which continues the previous one, demonstrates performing a reverse image search on the search network.
C#
// Creating a search image from a fileSearchImagesearchImage=SearchImage.Create(@"c:\MyDocuments\Image.png");inthashDifferences=8;// The maximum allowed difference between the image hashesConsole.WriteLine("First image search");Searchersearcher=node.Searcher;ImageSearchOptionsoptions=newImageSearchOptions();options.HashDifferences=hashDifferences;inttotal=0;NetworkImageSearchResultresult=searcher.SearchFirst(searchImage,options);Console.WriteLine("Images found (shard "+result.ShardIndex+"): "+result.ImageCount);total+=result.ImageCount;while(result.NetworkImageSearchToken!=null){Console.WriteLine();Console.WriteLine("Next image search");result=searcher.SearchNext(result.NetworkImageSearchToken);Console.WriteLine("Images found (shard "+result.ShardIndex+"): "+result.ImageCount);total+=result.ImageCount;}Console.WriteLine();Console.WriteLine("Total images found (diffs = "+hashDifferences+"): "+total);
More information about reverse image search can be found on the Reverse image search page.
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: