private static List <DocumentoSharePoint> OrdenarResultados(ResultTable resultTable) { List <DocumentoSharePoint> resultados = new List <DocumentoSharePoint>(); List <string> primerOrden = new List <string>(); DocumentoSharePoint dsp; while (resultTable.Read()) { dsp = new DocumentoSharePoint(); DateTime fechaBusqueda; bool esFecha = DateTime.TryParse(resultTable["Fecha"].ToString(), out fechaBusqueda); if (esFecha) { dsp.Fecha = fechaBusqueda; } dsp.Path = resultTable["Path"].ToString(); dsp.Titulo = resultTable["Title"].ToString(); resultados.Add(dsp); } if (desc) { primerOrden = resultados.OrderBy(t => t.Path).Select(p => p.Path).ToList(); } else { primerOrden = resultados.Where(t => t.Path.Split('/').Last().StartsWith("20110807")).OrderByDescending(t => t.Path).Select(p => p.Path).ToList().ToList(); var segundoOrden = resultados.Where(t => !t.Path.Split('/').Last().StartsWith("20110807")).OrderBy(t => t).Select(p => p.Path).ToList(); primerOrden.AddRange(segundoOrden); } return(resultados.OrderBy(f => f.Fecha).ToList()); }
public static DataTable ExecuteQuery(string SiteCollection, string QueryString) { SPSite col = new SPSite(SiteCollection); ServerContext ctx = ServerContext.GetContext(col); FullTextSqlQuery ftq = new FullTextSqlQuery(ctx); ftq.ResultTypes = ResultType.RelevantResults; ftq.EnableStemming = true; ftq.TrimDuplicates = true; ftq.QueryText = QueryString; ResultTableCollection allresults = ftq.Execute(); ResultTable relevant = allresults[ResultType.RelevantResults]; DataTable dt = null; if (relevant.RowCount > 0) { dt = new DataTable("Search Result"); dt.Columns.Add("Title"); dt.Columns.Add("URL"); while (relevant.Read()) { DataRow row = dt.NewRow(); row[0] = relevant.GetString(0); row[1] = relevant.GetString(1); dt.Rows.Add(row); } } return(dt); }
static void Main(string[] args) { string SPSiteAdress = ConfigurationManager.AppSettings["SPSiteAddress"].ToString(); Console.WindowWidth = 150; Console.WindowHeight = 50; Console.WriteLine(SPSiteAdress); SPSite objSite = new SPSite(SPSiteAdress); //Replace with yours SPWeb objTargetWeb = objSite.OpenWeb(SPSiteAdress); ResultType resultType = ResultType.RelevantResults; Console.WriteLine("type your query...."); string strQuery = Console.ReadLine(); Console.WriteLine("type your ranking model ID...."); string rankikgModelId = Console.ReadLine(); KeywordQuery keywordQuery = new KeywordQuery(objSite); SearchExecutor searchExecutor = new SearchExecutor(); keywordQuery.QueryText = strQuery; keywordQuery.ResultTypes = resultType; //This is where we specify the custom ranking model to use. keywordQuery.RankingModelId = rankikgModelId; ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery); ResultTable resultTable = resultTableCollection[resultType]; int index = 0; string separator = " "; while (resultTable.Read()) { index++; if (index > 9) { separator = " "; } Console.WriteLine(index + separator + "Rank: " + String.Format("{0:0.00000}", resultTable["RANK"]) + " Title: " + resultTable["TITLE"].ToString()); } Console.ReadLine(); }
private void btnSearch_Click(object sender, EventArgs e) { SPSite col = new SPSite(txtSC.Text); ServerContext ctx = ServerContext.GetContext(col); DropDownHelper <Scope> dds = (DropDownHelper <Scope>)cbScope.SelectedItem; string ScopeName = dds.Item.Name; string query = "Select title, url FROM Scope() where \"Scope\" = '" + ScopeName + "' AND Freetext('" + txtPhrase.Text + " ')"; FullTextSqlQuery ftq = new FullTextSqlQuery(ctx); ftq.ResultTypes = ResultType.RelevantResults; ftq.EnableStemming = true; ftq.TrimDuplicates = true; ftq.QueryText = query; ResultTableCollection allresults = ftq.Execute(); ResultTable relevant = allresults[ResultType.RelevantResults]; DataTable dt = null; if (relevant.RowCount > 0) { dt = new DataTable("Search Result"); dt.Columns.Add("Title"); dt.Columns.Add("URL"); while (relevant.Read()) { DataRow row = dt.NewRow(); row[0] = relevant.GetString(0); row[1] = relevant.GetString(1); dt.Rows.Add(row); } gvResult.DataSource = dt; gvResult.AutoResizeColumns(); } }
public bool Read() { return(m_resultTable.Read()); }