Exemplo n.º 1
0
        public static LfMultiParagraph GetCustomStTextValuesAsLfMultiPara(IStText obj, int flid,
			IWritingSystemManager wsManager, IFwMetaDataCache metaDataCacheAccessor, int fallbackWs)
        {
            if (obj == null || obj.ParagraphsOS == null || obj.ParagraphsOS.Count == 0) return null;
            var result = new LfMultiParagraph();
            result.Paragraphs = obj.ParagraphsOS.OfType<IStTxtPara>().Where(para => para.Contents != null).Select(para => FdoParaToLfPara(para, wsManager)).ToList();
            // StText objects in FDO have a single primary writing system, unlike MultiString or MultiUnicode objects
            int fieldWs = metaDataCacheAccessor.GetFieldWs(flid);
            string wsStr = wsManager.GetStrFromWs(fieldWs);
            if (wsStr == null) wsStr = wsManager.GetStrFromWs(fallbackWs);
            result.InputSystem = wsStr;
            return result;
        }
Exemplo n.º 2
0
        public static LfMultiParagraph GetCustomStTextValuesAsLfMultiPara(IStText obj, int flid,
                                                                          IWritingSystemManager wsManager, IFwMetaDataCache metaDataCacheAccessor, int fallbackWs)
        {
            if (obj == null || obj.ParagraphsOS == null || obj.ParagraphsOS.Count == 0)
            {
                return(null);
            }
            var result = new LfMultiParagraph();

            // result.Guid = obj.Guid;  // TODO: See if this would break LF PHP
            result.Paragraphs = obj.ParagraphsOS.OfType <IStTxtPara>().Where(para => para.Contents != null).Select(para => FdoParaToLfPara(para, wsManager)).ToList();
            // StText objects in FDO have a single primary writing system, unlike MultiString or MultiUnicode objects
            int    fieldWs = metaDataCacheAccessor.GetFieldWs(flid);
            string wsStr   = wsManager.GetStrFromWs(fieldWs);

            if (wsStr == null)
            {
                wsStr = wsManager.GetStrFromWs(fallbackWs);
            }
            result.InputSystem = wsStr;
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Searches an index for the specified string.
        /// </summary>
        /// <param name="indexId">The index ID.</param>
        /// <param name="tss">The string.</param>
        /// <returns>The search results.</returns>
        public IEnumerable <T> Search(int indexId, ITsString tss)
        {
            if (tss == null || string.IsNullOrEmpty(tss.Text))
            {
                return(Enumerable.Empty <T>());
            }

            HashSet <T> results = null;

            foreach (Tuple <int, string> wsStr in GetWsStrings(tss))
            {
                SortKeyIndex index    = GetIndex(indexId, wsStr.Item1);
                ICollator    collator = m_wsManager.Get(wsStr.Item1).Collator;
                switch (m_type)
                {
                case SearchType.Exact:
                case SearchType.Prefix:
                {
                    byte[] sortKey = collator.GetSortKey(wsStr.Item2).KeyData;
                    var    lower   = new byte[wsStr.Item2.Length * SortKeyFactor];
                    Icu.GetSortKeyBound(sortKey, Icu.UColBoundMode.UCOL_BOUND_LOWER, ref lower);
                    var upper = new byte[wsStr.Item2.Length * SortKeyFactor];
                    Icu.GetSortKeyBound(sortKey,
                                        m_type == SearchType.Exact
                                                                                                        ? Icu.UColBoundMode.UCOL_BOUND_UPPER
                                                                                                        : Icu.UColBoundMode.UCOL_BOUND_UPPER_LONG, ref upper);
                    IEnumerable <T> items = index.GetItems(lower, upper);
                    if (results == null)
                    {
                        results = new HashSet <T>(items);
                    }
                    else
                    {
                        results.IntersectWith(items);
                    }
                    break;
                }

                case SearchType.FullText:
                    string   locale = m_wsManager.GetStrFromWs(wsStr.Item1);
                    string[] tokens = Icu.Split(Icu.UBreakIteratorType.UBRK_WORD, locale, wsStr.Item2).ToArray();
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        byte[] sortKey = collator.GetSortKey(tokens[i]).KeyData;
                        var    lower   = new byte[tokens[i].Length * SortKeyFactor];
                        Icu.GetSortKeyBound(sortKey, Icu.UColBoundMode.UCOL_BOUND_LOWER, ref lower);
                        var upper = new byte[tokens[i].Length * SortKeyFactor];
                        Icu.GetSortKeyBound(sortKey,
                                            i < tokens.Length - 1
                                                                                                        ? Icu.UColBoundMode.UCOL_BOUND_UPPER
                                                                                                        : Icu.UColBoundMode.UCOL_BOUND_UPPER_LONG, ref upper);
                        IEnumerable <T> items = index.GetItems(lower, upper);
                        if (results == null)
                        {
                            results = new HashSet <T>(items);
                        }
                        else
                        {
                            results.IntersectWith(items);
                        }
                    }
                    break;
                }
            }
            return(results ?? Enumerable.Empty <T>());
        }