Show language: C# VB.NET Both

Programmatic Searching

To run programmatic searches is fairly straight forward, it involves setting the Configuration to the correct Index Directory and using SearchAgent to run the actual search.

Example Searcher

C#
using System;
using Keyoti.SearchEngine;
using Keyoti.SearchEngine.Search;


public class MyClass
{
	public static void Main()
	{
			
		// Put user code to initialize the page here
		Configuration configuration = new Configuration();
		configuration.IndexDirectory =
		@"C:\...path to your index directory...";
		
		//this SearchUnit Pro license key will expire December 2012, evaluators should email support
		//for a key
		string licensekey =
		"5A556A61675D69626B5C6D6C644854263C3E41433B41413E44404645474A454B4D503D0";
		
		//run a search for "the"
		SearchAgent sa = new SearchAgent(licensekey, configuration);

		//retrieve results 1 through 10
		SearchResult results = sa.Search("the", 1, 10);
		
		//the number of results there actually are in total
		int totalNumberOfResults = results.NumberOfResults;
		
		foreach(ResultItem i in results)
		{
			//the summary from the document
			string summary = i.Summary;
		
			//the title of the document
			string title = i.Title;
		
			//the document URL
			string url = i.UriString;
		
		
			//the weight of the document in the results
			int weight = i.Weight;
			Console.WriteLine(url);
		}
	}
}
VB.NET
Imports System
Imports Keyoti.SearchEngine
Imports Keyoti.SearchEngine.Search


Public Class MyClass1
    
    Public Shared Sub Main()
        ' Put user code to initialize the page here
        Dim configuration As Configuration = New Configuration
        configuration.IndexDirectory = "C:\...path to your index directory..."
        'this SearchUnit Pro license key will expire December 2012, evaluators should email support
        'for a key
        Dim licensekey As String = "5A556A61675D69626B5C6D6C644854263C3E41433B41413E44404645474A454B4D503D0"
        'run a search for "the"
        Dim sa As SearchAgent = New SearchAgent(licensekey, configuration)

        'retrieve results 1 through 10
        Dim results As SearchResult = sa.Search("the", 1, 10)
        'the number of results there actually are in total
        Dim totalNumberOfResults As Integer = results.NumberOfResults
        For Each i As ResultItem In results
            'the summary from the document
            Dim summary As String = i.Summary
            'the title of the document
            Dim title As String = i.Title
            'the document URL
            Dim url As String = i.UriString
            'the weight of the document in the results
            Dim weight As Integer = i.Weight
            Console.WriteLine(url)
        Next
    End Sub
End Class