c# lucene 4.8 slow search: 400ms -> to 30ms?

时间:2017-08-04 12:26:12

标签: c# performance search lucene

i try to speed up my lucene-search in my wpf-application. i hoped that my search would be in the range of about 30ms.

87 search items where found in the index. So that is not very much. But Stopwatch timer says, it takes around 400ms, way to much for me.

So can u check my code, how i can improve code ? I also still measured time from the beginning of the try block to the foreach, so there is no big waste of time through init; but it is not (0 ms).

    List<CardView> aAll_CardView = new List<CardView>();

        try
        {
            SortField field        = new SortField(LUCENT_STATE_MAIN, SortFieldType.STRING);
            Sort sort              = new Sort(field);

            searchManager.MaybeRefreshBlocking(); // execute with fresh index searcher

            var searcher   = searchManager.Acquire();
            var topDocs    = searcher.Search(aBooleanQuery, 100, sort);
            var _totalHits = topDocs.TotalHits;

            CardView aCardView = null;
            // measured time: take ~400-500ms grr !!!!
            foreach ( var result in topDocs.ScoreDocs)
            {
                #region iterate through findings and put lucene data into CardView list

                var aDoc = searcher.Doc(result.Doc);

                aAll_CardView.Add(new CardView
                {
                    // all fields are defined as TextField()...

                    // must be first,  because used in e.g. Nr_Main
                    RelatedItemCount = aDoc.Get(LUCENT_RELATED_ITEMS),

                    Nr_Main          = aDoc.Get(LUCENT_NR_MAIN),
                    Nr_Parent        = aDoc.Get(LUCENT_NR_PARENT),
                    Antwort          = aDoc.Get(LUCENT_ANTWORT),
                    Beschreibung     = aDoc.Get(LUCENT_BESCHREIBUNG),
                    Note             = aDoc.Get(LUCENT_NOTES),

                    Question_Main    = aDoc.Get(LUCENT_TITLE_MAIN),
                    Question_Parent  = aDoc.Get(LUCENT_TITLE_PARENT),
                    Book             = aDoc.Get(LUCENT_BOOK),
                    Date_Create      = aDoc.Get(LUCENT_DATE_CREATED),
                    Date_LastEdit    = aDoc.Get(LUCENT_DATE_LASTEDIT),
                    Bibelstelle      = aDoc.Get(LUCENT_BIBELSTELLE),
                    // ParseCore just uses TryParse to get enum for state
                    Status_Main      = ParseCore(aDoc.Get(LUCENT_STATE_MAIN)),
                    Status_Parent    = ParseCore(aDoc.Get(LUCENT_STATE_PARENT))
                });

                #endregion
            }
        }
        catch(Exception e)
        {
            string exp = e.ToString();
            new JMsg(exp).ShowDialog();
        }
        finally
        {
        }

0 个答案:

没有答案