예제 #1
0
		public void PrefixSearchTest()
		{
			var searcher = new StringSearcher<int>(SearchType.Prefix, m_wsManager);
			searcher.Add(0, 0, m_tsf.MakeString("test", m_enWs));
			searcher.Add(1, 0, m_tsf.MakeString("Hello",  m_enWs));
			searcher.Add(2, 0, m_tsf.MakeString("c'est une phrase", m_frWs));
			searcher.Add(3, 0, m_tsf.MakeString("hello", m_enWs));
			searcher.Add(4, 0, m_tsf.MakeString("zebra", m_enWs));

			CheckSearch(searcher, m_tsf.MakeString("test", m_enWs), new[] {0});
			CheckSearch(searcher, m_tsf.MakeString("hel", m_enWs), new[] {1, 3});
			CheckSearch(searcher, m_tsf.MakeString("zebra", m_enWs), new[] { 4 });
			CheckSearch(searcher, m_tsf.MakeString("c'est", m_frWs), new[] {2});
			CheckNoResultsSearch(searcher, m_tsf.MakeString("zebras", m_enWs));
		}
        private void CreateSearcher()
        {
            int control = 0;

            for (; m_curPossIndex < m_possibilities.Count; m_curPossIndex++)
            {
                // Every so often see whether the user has typed something that makes our search irrelevant.
                if (control++ % 50 == 0 && ShouldAbort())
                {
                    return;
                }

                ICmPossibility poss = m_possibilities[m_curPossIndex];
                ITsString      name = null;
                foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem,
                                                                                      poss.Hvo, CmPossibilityTags.kflidName, null))
                {
                    ITsString tss = poss.Name.StringOrNull(ws);
                    if (tss != null && tss.Length > 0)
                    {
                        name = tss;
                        m_searcher.Add(poss, 0, tss);
                        break;
                    }
                }

                foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem,
                                                                                      poss.Hvo, CmPossibilityTags.kflidAbbreviation, null))
                {
                    ITsString tss = poss.Abbreviation.StringOrNull(ws);
                    if (tss != null && tss.Length > 0)
                    {
                        m_searcher.Add(poss, 0, tss);
                        if (name != null)
                        {
                            var tisb = TsIncStrBldrClass.Create();
                            tisb.AppendTsString(tss);
                            tisb.AppendTsString(m_cache.TsStrFactory.MakeString(" - ", m_cache.DefaultUserWs));
                            tisb.AppendTsString(name);
                            m_searcher.Add(poss, 0, tisb.GetString());
                        }
                        break;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Builds the search index.
        /// </summary>
        private int BuildIndex(int i, SearchField field, Func <bool> isSearchCanceled)
        {
            if (m_searchableObjs == null)
            {
                m_searchableObjs = GetSearchableObjects();
            }

            for (; i < m_searchableObjs.Count; i++)
            {
                if (isSearchCanceled())
                {
                    break;
                }
                foreach (ITsString tss in GetStrings(field, m_searchableObjs[i]))
                {
                    m_searcher.Add(m_searchableObjs[i].Hvo, field.Flid, tss);
                }
            }
            return(i);
        }
예제 #4
0
        private void CreateSearchers()
        {
            int control = 0;

            // This is tricky and non-obvious. This loop does NOT initialize m_curObjIndex. Therefore unless something
            // adds to m_searchableObjs (not sure this can happen) or calls Reset() to set it back to zero, this routine
            // will do nothing except the first time it is called (after m_searchableObjs is set). I don't know exactly
            // why it was done that way, but that is why it is fast after the first time.
            for (; m_curObjIndex < m_searchableObjs.Count; m_curObjIndex++)
            {
                // Every so often see whether the user has typed something that makes our search irrelevant.
                if (control++ % 50 == 0 && ShouldAbort())
                {
                    return;
                }

                foreach (SearchField field in m_stringSelector(m_searchableObjs[m_curObjIndex]))
                {
                    m_searcher.Add(m_searchableObjs[m_curObjIndex], field.Flid, field.String);
                }
            }
        }
예제 #5
0
		public void FullTextSearchTest()
		{
			var searcher = new StringSearcher<int>(SearchType.FullText, m_wsManager);
			searcher.Add(0, 0, m_tsf.MakeString("test", m_enWs));
			searcher.Add(1, 0, m_tsf.MakeString("c'est une phrase", m_frWs));
			ITsIncStrBldr tisb = m_tsf.GetIncBldr();
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_frWs);
			tisb.Append("C'est une sentence. ");
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_enWs);
			tisb.Append("We use it for testing purposes.");
			searcher.Add(2, 0, tisb.GetString());
			searcher.Add(3, 0, m_tsf.MakeString("Hello, how are you doing? I am doing fine. That is good to know.", m_enWs));

			CheckSearch(searcher, m_tsf.MakeString("test", m_enWs), new[] {0, 2});
			CheckSearch(searcher, m_tsf.MakeString("c'est une", m_frWs), new[] {1, 2});
			CheckSearch(searcher, m_tsf.MakeString("t", m_enWs), new[] {0, 2, 3});
			CheckSearch(searcher, m_tsf.MakeString("testing purpose", m_enWs), new[] {2});
		}