Knowledgebase Home Page  >  SearchUnit  >  Version 2 Articles
Search the Knowledge Base
Is it possible to use the API to programmatically run searches and display results?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=83&catId=66

Options

Print this page
Email this to a friend

Yes.  However we would encourage layout customizations to be done through the template mechanism, since this is powerful and simple.

 

First, add the Keyoti.SearchEngine.Core DLL to your references.  Then in the codebehind (or Win form etc) run the search with

 

 //sets up the index directory path, in this example it's underneath the app. root.

Configuration.xmlLocation = Server.MapPath("IndexDirectory");   

Configuration.enablePhraseMatching = true;       

Configuration.summaryWordLength = 50;

Configuration.dbType = "xml";

 //temp license key, if this has expired please request new one from support@keyoti.com

string license = "5550655C6258645D665768675F5864364E543840363C3B39453B4140414740484E474F9";

 //run the search using the query string (you can direct the SearchBox control to this page)

SearchAgent sa = new SearchAgent(Request.Params["QueryExpr"], license);

 //get results 1 through 10, change these to create paging

SearchResult res = sa.Search(1, 10);

foreach(ResultItem rItem in res)

{

Response.Write(rItem.Title+"<br>"+rItem.URIString+"<br><br>");

}

 

 

 

Full code behind.

-------------------------

 

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using Keyoti.SearchEngine.Search;

using Keyoti.SearchEngine;

namespace KeyotiSearchDemo_CSharp

{

/// <summary>

/// Summary description for APISearchResults.

/// </summary>

public class APISearchResults : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

Configuration.xmlLocation = Server.MapPath("IndexDirectory");

Configuration.enablePhraseMatching = true;

Configuration.summaryWordLength = 50;

Configuration.dbType = "xml";

string license = "5550655C6258645D665768675F5864364E543840363C3B39453B4140414740484E474F9";

SearchAgent sa = new SearchAgent(Request.Params["QueryExpr"], license);

SearchResult res = sa.Search(1, 10);

foreach(ResultItem rItem in res)

{

Response.Write(rItem.Title+"<br>"+rItem.URIString+"<br><br>");

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}


Related Questions:

Attachments:

No attachments were found.