1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| private DataTable GetData()
{
string strKey = GetSearchCriteria();
querysearch = strKey;
try
{
if (!string.IsNullOrEmpty(strKey))
{
if (this.Page != null && ds != null)
{
Utils.writeDBLog("", "", "ds.FilterExpression: " + ds.FilterExpression + "- isPostBack? " + this.Page.IsPostBack.ToString());
if (string.IsNullOrEmpty(ds.FilterExpression))
{
string[] splitStr = ds.FilterExpression.Split('=');
string newSearch = string.Empty;
if (splitStr.Length >= 2)
newSearch = splitStr[0].Trim() + ":" + splitStr[1].Trim() ;
strKey = newSearch + " " + strKey;
}
}
// get the query and settings service proxy
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
// get the search service application proxy by name
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");
// create QueryManager and LocationList objects
QueryManager queryManager = new QueryManager();
LocationList locationList = new LocationList();
// add the federated location we want
Location localSearchLocation = new Location("LocalSearchIndex", searchProxy);
// set the start page and page size
localSearchLocation.ItemsPerPage = Convert.ToInt32(itemPerPage);
localSearchLocation.StartItem = (currentPage * Convert.ToInt32(itemPerPage)) + 1;
if (oGrid!= null)
{
if (currentPage != oGrid.PageIndex)
{
currentPage = oGrid.PageIndex;
}
}
// add our managed properties
localSearchLocation.RequestedProperties = new System.Collections.Specialized.StringCollection();//{ "title", "id" };
localSearchLocation.RequestedProperties.AddRange(queryCol.Split(';'));
// add the Location to the LocationList
locationList.Add(localSearchLocation);
// set the query
queryManager.UserQuery = strKey.Trim();
queryManager.Add(locationList);
queryManager.IsTriggered(locationList);
// make the call to search
XmlDocument xmlDocument = queryManager.GetResults(locationList);
nbResult = localSearchLocation.TotalResults;
DataTable dtTemp = ConvertXmlDocumentToDataTable(xmlDocument);
myDataTable = new DataTableWrapper(dtTemp, nbResult);
//oGrid.DataBind();
return dtTemp;
}
}
catch (Exception ex)
{
Utils.writeDBLog("GetData", "error", ex.Message + " - " + ex.StackTrace);
}
return new DataTable();
} |
Partager