Last active
December 18, 2015 08:59
-
-
Save jonupchurch/5757545 to your computer and use it in GitHub Desktop.
GSA Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************** | |
* GSALib Wrapper for Google Search Appliance | |
* GSA.Paragon.Utils | |
* Written by Jon Upchurch | |
* Copyright 2013 by Paragon Consulting, Inc. | |
* Free to use, distribute, and modify | |
* with this credit comment retained. | |
****************************************/ | |
using GSALib.Constants; | |
using GSALib.GSA; | |
namespace GSA.Paragon.Utils | |
{ | |
public class GSAReader | |
{ | |
/// <summary> | |
/// Query the GSA and return results. | |
/// </summary> | |
/// <exception cref="GSALib.Exceptions.GSANeedNetworkCredentailsException"></exception> | |
/// <param name="searchString">Query text to be sent to the GSA</param> | |
/// <param name="collections">Array of collections to include in the search</param> | |
/// <param name="frontEnd">The name of the front end to use</param> | |
/// <param name="maxResults">Max # of results to return</param> | |
/// <param name="output">GSALib.Constants.Output type</param> | |
/// <param name="encoding">Encoding type found in GSALib.Constants.Encoding</param> | |
/// <param name="access">GSALib.Constants.Access type</param> | |
/// <returns>Array of GSALib.GSA.Result items</returns> | |
public Result[] GetGSAResults( | |
string searchString, | |
string[] collections, | |
string frontEnd, | |
int maxResults, | |
Output output, | |
string encoding, | |
Access access) | |
{ | |
var query = new Query(); | |
query.setSiteCollections(collections); | |
query.setFrontend(frontEnd); | |
query.setOutputFormat(output); | |
query.setOutputEncoding(encoding); | |
query.setAccess(access); | |
query.setMaxResults(maxResults); | |
var term = new QueryTerm(searchString); | |
query.setQueryTerm(term); | |
var ca = new ClientAccess(); | |
var res = ca.getGSAResponse(query, null); | |
var results = res.getResults(); | |
return (Result[])results.ToArray(typeof(Result)); | |
} | |
public Result[] GetGSAResults( | |
string searchString, | |
string[] collections, | |
string frontEnd, | |
int maxResults) | |
{ | |
return GetGSAResults(searchString, collections, frontEnd, maxResults, Output.XML_NO_DTD, Encoding.UTF8, Access.PUBLIC); | |
} | |
public Result[] GetGSAResults( | |
string searchString, | |
string[] collections, | |
string frontEnd) | |
{ | |
return GetGSAResults(searchString, collections, frontEnd, 100, Output.XML_NO_DTD, Encoding.UTF8, Access.PUBLIC); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment