public void Run() { Global.UserRightProvider.CanDo(Right.RightItem.Select); if (Parameters.Count < 2) { throw new ArgumentException("Parameter 1 is select statement before where. Parameter 2 - n is docids."); } string sql = Parameters[0]; SFQL.Parse.SFQLParse sfqlParse = new Hubble.Core.SFQL.Parse.SFQLParse(); sfqlParse.SyntaxAnalyse(sql); SFQL.SyntaxAnalysis.Select.Select select = sfqlParse.SFQLSentenceList[0].SyntaxEntity as SFQL.SyntaxAnalysis.Select.Select; string tableName = select.SelectFroms[0].Name; Data.DBProvider dbProvider = Data.DBProvider.GetDBProvider(tableName); if (dbProvider == null) { throw new Data.DataException(string.Format("Invalid table:{0}", tableName)); } List <Data.Field> fields; int allFieldsCount; sfqlParse.GetSelectFields(select, dbProvider, out fields, out allFieldsCount); Query.DocumentResultForSort[] docs = new Hubble.Core.Query.DocumentResultForSort[Parameters.Count - 1]; for (int i = 1; i < Parameters.Count; i++) { docs[i - 1] = new Hubble.Core.Query.DocumentResultForSort(int.Parse(Parameters[i])); } List <Data.Document> docResult = dbProvider.Query(fields, docs); Hubble.Framework.Data.DataSet ds = Data.Document.ToDataSet(fields, docResult); ds.Tables[0].TableName = "Select_" + select.SelectFroms[0].Alias; _QueryResult.DataSet = ds; }
unsafe private DocumentResultWhereDictionary GetExternLikeDocResults(DocumentResultWhereDictionary docIdRank) { if (docIdRank.Count <= 0) { return(docIdRank); } //Sort Query.DocumentResultForSort[] docResultArray = new Hubble.Core.Query.DocumentResultForSort[docIdRank.Count];; int i = 0; foreach (Core.SFQL.Parse.DocumentResultPoint drp in docIdRank.Values) { docResultArray[i++] = new Hubble.Core.Query.DocumentResultForSort(drp.pDocumentResult); } List <SFQL.SyntaxAnalysis.Select.OrderBy> orderBys = new List <SFQL.SyntaxAnalysis.Select.OrderBy>(); SFQL.SyntaxAnalysis.Select.OrderBy scoreOrderBy = new SFQL.SyntaxAnalysis.Select.OrderBy(); scoreOrderBy.Name = "score"; scoreOrderBy.Order = "desc"; orderBys.Add(scoreOrderBy); QueryResultSort qSort = new QueryResultSort(orderBys, _DBProvider); int sortLen = MinResultCount; if (_QueryParameter.CanLoadPartOfDocs) { sortLen = _QueryParameter.End + 1 + 10; } if (sortLen > 0) { sortLen = ((sortLen - 1) / 100 + 1) * 100; } qSort.Sort(docResultArray, sortLen); // using part quick sort can reduce 40% time //Build sql int len = Math.Min(docResultArray.Length, sortLen); StringBuilder sql = new StringBuilder(); bool docidReplace = _DBProvider.DocIdReplaceField != null; string docIdFieldName = "docid"; if (docidReplace) { docIdFieldName = _DBProvider.DocIdReplaceField; } sql.AppendFormat("select {0} from {1} where {2} like '{3}' and {0} in (", docIdFieldName, _DBProvider.Table.DBTableName, InvertedIndex.FieldName, _LikeString); for (i = 0; i < len; i++) { long id; if (docidReplace) { id = _DBProvider.GetDocIdReplaceFieldValue(docResultArray[i].DocId); } else { id = docResultArray[i].DocId; } if (i == 0) { sql.AppendFormat("{0}", id); } else { sql.AppendFormat(",{0}", id); } } sql.Append(")"); System.Data.DataSet ds = _DBProvider.DBAdapter.QuerySql(sql.ToString()); DocumentResultWhereDictionary result = new DocumentResultWhereDictionary(ds.Tables[0].Rows.Count); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { int docid; if (docidReplace) { docid = _DBProvider.GetDocIdFromDocIdReplaceFieldValue(long.Parse(row[0].ToString())); } else { docid = int.Parse(row[0].ToString()); } result.Add(docid, 1); } if (result.Count < sortLen) { result.RelTotalCount = result.Count; } else { result.RelTotalCount = docIdRank.RelTotalCount; } if (result.Count < docIdRank.Count && this._QueryParameter.NeedGroupBy) { //if result count less than total count //and need group by //init group by collection foreach (int docid in docIdRank.Keys) { result.AddToGroupByCollection(docid); } } return(result); }
private void BatchAddToUpdate(System.Data.DataTable table, List <SFQL.Parse.SFQLParse.UpdateEntity> updateEntityList) { List <List <FieldValue> > docValues = new List <List <FieldValue> >(); List <Query.DocumentResultForSort> docs = new List <Hubble.Core.Query.DocumentResultForSort>(); foreach (System.Data.DataRow row in table.Rows) { long id = long.Parse(row[0].ToString()); int docid = _DBProvider.GetDocIdFromDocIdReplaceFieldValue(id); //Get field values List <FieldValue> fieldValues = new List <FieldValue>(); System.Data.DataRow vRow = row; for (int i = 1; i < table.Columns.Count; i++) { string field = table.Columns[i].ColumnName; if (string.IsNullOrEmpty(field)) { continue; } FieldValue fv; if (vRow[field] == DBNull.Value) { fv = new FieldValue(field, null); } else { if (vRow[field] is DateTime) { fv = new FieldValue(field, ((DateTime)vRow[field]).ToString("yyyy-MM-dd HH:mm:ss.fff")); } else { fv = new FieldValue(field, vRow[field].ToString()); } } fieldValues.Add(fv); } docValues.Add(fieldValues); Query.DocumentResultForSort doc = new Hubble.Core.Query.DocumentResultForSort(docid); doc.Score = id; //use score store id casually. docs.Add(doc); //_DBProvider.Update(fieldValues, docs); } if (docValues.Count > 0) { updateEntityList.Add(new Hubble.Core.SFQL.Parse.SFQLParse.UpdateEntity( docValues[0], docValues, docs.ToArray())); } else { return; } }