Exemple #1
0
        /// <summary>
        /// 사용자의 질의어를 서버로 보낸다.
        /// </summary>
        /// <param name="aScenario">시나리오</param>
        /// <param name="aQuery">검색쿼리</param>
        /// <param name="aLogInfo">로그정보</param>
        /// <param name="aHilightText">하이라이트 키워드</param>
        /// <param name="aOrderBy">정렬절</param>
        /// <param name="aPageNum">페이지번호</param>
        /// <param name="aPageSize">페이지사이즈</param>
        /// <param name="aUseRowId">rowid 사용 유무 플래그</param>
        /// <param name="aLanguage">언어셋</param>
        /// <param name="aCharset">캐릭터셋</param>
        /// <exception cref="IOException"></exception>
        /// <exception cref="Exception"></exception>
        /// <exception cref="KonanException"></exception>
        /// <returns>결과 VO</returns>
        public ResultVO SubmitQuery(string aScenario, string aQuery, string aLogInfo, string aHilightText,
                                    string aOrderBy, int aPageNum, int aPageSize, bool aUseRowId, int aLanguage, int aCharset)
        {
            ResultVO lResult = new ResultVO();

            lResult.ReturnCode    = 0;
            lResult.ReturnMessage = string.Empty;

            object lTotal = 0;
            object lRows  = 0;
            object lCols  = 0;
            object lColNameArrayObject = null;

            object lRowIds         = null;
            object lScores         = null;
            object lRowArrayObject = null; //한개의 로우 데이터 object[]
            object lfdataLength    = null;


            int i, j;

            int lStartNum = (aPageNum - 1) * aPageSize;


            try
            {
                if (mClient.BeginSession() < 0)
                {
                    throw (new KonanException("BeginSession : " + mClient.GetErrorMessage()));
                }

                lResult.ReturnCode = mClient.SetOption(mClient.OPTION_SOCKET_TIMEOUT_REQUEST, 3 * 60);
                if (lResult.ReturnCode < 0)
                {
                    throw (new KonanException("SetOption : " + mClient.GetErrorMessage()));
                }
                //if ("utf8".Equals(INDEX_CHARSET, StringComparison.OrdinalIgnoreCase))
                //{
                //    //문자 세트가 utf 8 인 경우 설정.
                //    lResult.ReturnCode = mClient.SetOption(mClient.OPTION_REQUEST_CHARSET_UTF8, 1);

                //    if (lResult.ReturnCode < 0)
                //    {
                //        throw (new KonanException("SetOption : " + mClient.GetErrorMessage()));
                //    }
                //}

                lResult.ReturnCode = mClient.SubmitQuery(DAEMON_SERVICE_IP, DAEMON_SERVICE_PORT, "", aLogInfo, aScenario, aQuery,
                                                         aOrderBy, aHilightText, lStartNum, aPageSize, aLanguage, aCharset);

                if (lResult.ReturnCode != 0)
                {
                    throw (new KonanException("ReturnCode : " + lResult.ReturnCode + " Scenario : " + aScenario + "\n Query : " + aQuery + "\n OrderBy : " + aOrderBy));
                }

                if (mClient.GetResult_TotalCount(out lTotal) < 0)
                {
                    throw (new KonanException("GetResult_TotalCount:" + mClient.GetErrorMessage()));
                }

                if (mClient.GetResult_RowSize(out lRows) < 0)
                {
                    throw (new KonanException("GetResult_RowSize:" + mClient.GetErrorMessage()));
                }

                if (mClient.GetResult_ColumnSize(out lCols) < 0)
                {
                    throw (new KonanException("GetResult_ColumnSize:" + mClient.GetErrorMessage()));
                }
                if (mClient.GetResult_ColumnName(out lColNameArrayObject, (int)lCols) < 0)
                {
                    throw (new KonanException("GetResult_ColumnName:" + mClient.GetErrorMessage()));
                }

                if (aUseRowId)
                {
                    lRowIds = new object[(int)lRows];
                    lScores = new object[(int)lRows];

                    if (mClient.GetResult_ROWID(out lRowIds, out lScores) < 0)
                    {
                        throw (new KonanException("GetResult_ROWID:" + mClient.GetErrorMessage()));
                    }
                }

                object[] lColNameArray = (object[])lColNameArrayObject;

                List <Dictionary <string, object> > lData = new List <Dictionary <string, object> >(); //결과 데이터
                for (i = 0; i < (int)lRows; i++)
                {
                    mClient.GetResult_Row(out lRowArrayObject, out lfdataLength, i);
                    object[] lRowArray = (object[])lRowArrayObject;

                    Dictionary <string, object> lRowDic = new Dictionary <string, object>();
                    for (j = 0; j < (int)lCols; j++)
                    {
                        lRowDic.Add((string)lColNameArray[j], lRowArray[j]);
                    }

                    lData.Add(lRowDic);
                }

                lResult.Total    = (int)lTotal;
                lResult.Rows     = (int)lRows;
                lResult.Cols     = (int)lCols;
                lResult.RowIds   = (object[])lRowIds;
                lResult.Scores   = (object[])lScores;
                lResult.ColNames = lColNameArray;
                lResult.Data     = lData;
                mTotal           = (int)lTotal;
            }
            catch (KonanException e)
            {
                throw (new KonanException("Unexpected Error : " + e.Message));
            }
            catch (Exception e)
            {
                throw (new Exception("Unexpected Error : " + e.Message));
            }
            finally
            {
                mClient.EndSession();
            }

            return(lResult);
        }