예제 #1
0
        // 根据特性的评注记录路径,获得一定范围的检索命中结果
        // return:
        //      -1  出错
        //      0   没有找到
        //      1   找到
        public static int GetCommentsSearchResult(
            OpacApplication app,
            LibraryChannel channel,
            ItemLoadEventHandler itemLoadProc,
            SetStartEventHandler setStartProc,
            int nPerCount,
            string strCommentRecPath,
            bool bGetRecord,
            string strLang, // 2012/7/9
            out int nStart,
            out string strError)
        {
            strError = "";
            nStart = -1;

            long lHitCount = 0;

            bool bFound = false;
            List<string> aPath = null;
            for (int j = 0; ; j++)
            {
                nStart = j * nPerCount;
                // 只获得路径。确保所要的lStart lCount范围全部获得
                long lRet = // this.Channel.
                    channel.GetSearchResult(
                    null,
                    "default",
                    nStart, // 0,
                    nPerCount, // -1,
                    strLang,
                    out aPath,
                    out strError);
                if (lRet == -1)
                    goto ERROR1;

                lHitCount = lRet;

                if (lHitCount == 0)
                    return 0;

                if (aPath.Count == 0)
                    break;

                for (int i = 0; i < aPath.Count; i++)
                {
                    if (aPath[i] == strCommentRecPath)
                    {
                        bFound = true;
                        break;
                    }
                }

                if (bFound == true)
                    break;

                if (nStart >= lHitCount)
                    break;
            }

            if (bFound == true)
            {
                if (// this.SetStart != null
                    setStartProc != null)
                {
                    SetStartEventArgs e = new SetStartEventArgs();
                    e.StartIndex = nStart;

                    // this.SetStart(this, e);
                    setStartProc(null, e);
                }

                for (int i = 0; i < aPath.Count; i++)
                {
                    if (bGetRecord == true)
                    {
                        string strXml = "";
                        string strMetaData = "";
                        byte[] timestamp = null;
                        string strOutputPath = "";
                        string strStyle = LibraryChannel.GETRES_ALL_STYLE;

                        long lRet = // this.Channel.
                            channel.GetRes(
                            null,
                            aPath[i],
                            strStyle,
                            out strXml,
                            out strMetaData,
                            out timestamp,
                            out strOutputPath,
                            out strError);
                        if (lRet == -1)
                            goto ERROR1;

                        if (//this.ItemLoad != null
                            itemLoadProc != null)
                        {
                            ItemLoadEventArgs e = new ItemLoadEventArgs();
                            e.Path = aPath[i];
                            e.Index = i;
                            e.Count = aPath.Count;
                            e.Xml = strXml;
                            e.Timestamp = timestamp;
                            e.TotalCount = (int)lHitCount;

                            // this.ItemLoad(this, e);
                            e.Channel = channel;
                            itemLoadProc(null, e);
                        }
                    }
                    else
                    {
                        if (//this.ItemLoad != null
                            itemLoadProc != null)
                        {
                            ItemLoadEventArgs e = new ItemLoadEventArgs();
                            e.Path = aPath[i];
                            e.Index = i;
                            e.Count = aPath.Count;
                            e.Xml = "";
                            e.Timestamp = null;
                            e.TotalCount = (int)lHitCount;

                            // this.ItemLoad(this, e);
                            e.Channel = channel;
                            itemLoadProc(null, e);
                        }
                    }
                }

                return 1;   // 找到
            }

            nStart = -1;
            strError = "路径为 '" + strCommentRecPath + "' 的记录在结果集中没有找到";
            return 0;   // 没有找到
        ERROR1:
            return -1;
        }
예제 #2
0
        // TODO: 结果集是和 channel 在一起的。如果 channel 不确定,就需要用全局结果集
        // 获得一定范围的检索命中结果
        // return:
        public static int GetCommentsSearchResult(
            OpacApplication app,
            LibraryChannel channel,
            ItemLoadEventHandler itemLoadProc,
            int nStart,
            int nMaxCount,
            bool bGetRecord,
            string strLang, // 2012/7/9
            out string strError)
        {
            strError = "";

            List<string> aPath = null;
            long lRet = // this.Channel.
                channel.GetSearchResult(
                null,
                "default",
                nStart, // 0,
                nMaxCount, // -1,
                strLang,
                out aPath,
                out strError);
            if (lRet == -1)
                goto ERROR1;

            long lHitCount = lRet;

            if (aPath.Count == 0)
            {
                strError = "GetSearchResult aPath error";
                goto ERROR1;
            }

            for (int i = 0; i < aPath.Count; i++)
            {
                if (bGetRecord == true)
                {
                    string strXml = "";
                    string strMetaData = "";
                    byte[] timestamp = null;
                    string strOutputPath = "";
                    string strStyle = LibraryChannel.GETRES_ALL_STYLE;

                    lRet = // this.Channel.
                        channel.GetRes(
                        null,
                        aPath[i],
                        strStyle,
                        out strXml,
                        out strMetaData,
                        out timestamp,
                        out strOutputPath,
                        out strError);
                    if (lRet == -1)
                        goto ERROR1;

                    if (// this.ItemLoad != null
                        itemLoadProc != null
                        )
                    {
                        ItemLoadEventArgs e = new ItemLoadEventArgs();
                        e.Path = aPath[i];
                        e.Index = i;
                        e.Count = aPath.Count;
                        e.Xml = strXml;
                        e.Timestamp = timestamp;
                        e.TotalCount = (int)lHitCount;

                        // this.ItemLoad(this, e);
                        e.Channel = channel;
                        itemLoadProc(null, e);
                    }
                }
                else
                {
                    if (// this.ItemLoad != null
                        itemLoadProc != null)
                    {
                        ItemLoadEventArgs e = new ItemLoadEventArgs();
                        e.Path = aPath[i];
                        e.Index = i;
                        e.Count = aPath.Count;
                        e.Xml = "";
                        e.Timestamp = null;
                        e.TotalCount = (int)lHitCount;

                        // this.ItemLoad(this, e);
                        e.Channel = channel;
                        itemLoadProc(null, e);
                    }
                }
            }

            return 0;
        ERROR1:
            return -1;
        }
예제 #3
0
        // 检索出册数据
        // 带有偏移量的版本
        // 2009/6/9 
        // return:
        //      -2  实体库没有定义
        //      -1  出错
        //      其他  命中的全部结果数量。
        //
        public static int OpacSearchItems(
            OpacApplication app,
            LibraryChannel channel,
            ItemLoadEventHandler itemLoadProc,
            string strBiblioRecPath,
            int nStart,
            int nMaxCount,
            string strLang,
            string strLibraryCode,
            out string strError)
        {
            strError = "";
            // string strXml = "";

            // LibraryChannel channel = this.GetChannel(true, this.m_strParameters);
            try
            {
                string strStyle = "opac";
                if (string.IsNullOrEmpty(strLibraryCode) == true)
                    strStyle += ",getotherlibraryitem";
                else
                    strStyle += ",librarycode:" + strLibraryCode;

                long lStart = nStart;
                long lCount = nMaxCount;
                long lTotalCount = 0;
                for (; ; )
                {
                    EntityInfo[] iteminfos = null;
                    long lRet = // this.Channel.
                        channel.GetEntities(
                        null,
                        strBiblioRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        strLang,
                        out iteminfos,
                        out strError);
                    if (lRet == -1)
                    {
                        if (//this.Channel.
                            channel.ErrorCode == ErrorCode.ItemDbNotDef)
                            return -2;
                        return -1;
                    }

                    if (lRet == 0)
                    {
                        strError = "没有找到";
                        return 0;
                    }

                    lTotalCount = lRet;

                    if (lCount < 0)
                        lCount = lTotalCount - lStart;

                    if (lStart + lCount > lTotalCount)
                        lCount = lTotalCount - lStart;

                    // 处理
                    for (int i = 0; i < iteminfos.Length; i++)
                    {
                        EntityInfo info = iteminfos[i];

                        if (//this.ItemLoad != null
                            itemLoadProc != null)
                        {
                            ItemLoadEventArgs e = new ItemLoadEventArgs();
                            e.Path = info.OldRecPath;
                            e.Index = i;    // +nStart;
                            e.Count = nMaxCount;    // (int)lTotalCount - nStart;
                            e.Timestamp = info.OldTimestamp;
                            e.Xml = info.OldRecord;

                            //this.ItemLoad(this, e);
                            itemLoadProc(null, e);
                        }
                    }

                    lStart += iteminfos.Length;
                    lCount -= iteminfos.Length;

                    if (lStart >= lTotalCount)
                        break;
                    if (lCount <= 0)
                        break;
                }

                return (int)lTotalCount;
            }
            finally
            {
                // this.ReturnChannel(channel);
            }
        }