I have a macroscript which reads a query string for search term parameters, and then does a multiple word GroupedOr search through UmbracoExamine / Lucene.NET. Because this is a full site search, I have hard-coded an array of about 100 fields across the site to allow the user to search against pretty much anything on the site.

Is there any way to make this search more efficient? Currently I'm averaging about 5 seconds (per 10,000 iterations on stopwatch) to search 100 fields on about ~2.2k nodes and returning ~600 results.

NOTE: I have removed the HTML / Inner loop code as I've already determined that this area isn't where the search is hanging.

string SearchTerm = string.Empty;
if (!string.IsNullOrEmpty(Request.Form["SearchTerm"]))
{
    SearchTerm = Request.Form["SearchTerm"];
    string[] SearchTermList = SearchTerm.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    string[] aliasList = new string[]{"umbracoUrlName", "menuText", "pageHeading", "pageSubheading", 
        "bodyText", "alerts", "headerQuote", "headerQuoteAttribution", "officePhone", "officeFax", 
        "officeEmail", "officeAddress", "officeCityofficeState", "officeZip", "officeAddress2", 
        "officeName", "navSummary", "latestJournals", "frequentNumbers", "searchIntro", "introduction", 
        "heading", "introText", "smName", "divisionTitle ", "districtTitle ", "districtNotes ", 
        "authorFirst ", "authorLast ", "articleTitle ", "articleKeywords ", "associatedJournal ", 
        "headline ", "content", "ruleSection", "articleCategories", "staffListing", "categoryTitle", 
        "articleAuthor", "articleCategory", "articleEndnotes", "journalVolume", "journalIssue", 
        "journalDate", "ruleCategory", "caseNotes", "proposedOpinion", "opinionAdopted", "opinionSummary", 
        "opinionEndnotes", "secondarySegment", "primaryTitle", "primarySubtitle", "primaryIntro", 
        "primaryNote", "secondaryTitle", "secondarySubtitle", "secondaryIntro", "secondaryNote", 
        "contactName", "contactTitle", "contactPhone", "contactEmail", "contactLabel", "contactIntro", 
        "orgMembers", "faqQuestion", "faqAnswer", "eventSummary", "eventVenue", "eventAddress1", 
        "eventAddress2", "eventCity", "eventState", "eventZip", "eventStartDateTime", "eventEndDateTime", 
        "eventContactName", "eventContactTitle", "eventContactEmail", "eventContactPhone", "groupMembers", 
        "pluralName", "makePlural", "subMembers", "newsDate", "newsLocation", "newsSummary", "newsCategory"};

    BaseSearchProvider collection = ExamineManager.Instance.SearchProviderCollection["SiteSearchSearcher"];
    ISearchCriteria searchCriteria = collection.CreateSearchCriteria(IndexTypes.Content, BooleanOperation.Or);
    ISearchCriteria filter = searchCriteria.GroupedOr(aliasList, SearchTermList).Compile();
    var SearchResults = collection.Search(filter).OrderByDescending(n => n.Score);
    string resultText = SearchResults.Count() == 1 ? "result" : "results";

    if (SearchResults.Count() > 0)
    {
      //Removed HTML / Printing Nodes & URL's
    }
}

From my point of view, I cannot see any further improvement in terms of efficiency when you have a massive list of fields like that.

However, you might be interested in change the logic slightly.

For example, you might want the user to select the topic that he is interested in (using a dropdown list):

  • Offices
  • News
  • ...
  • Events

And once he had selected the topic, and typed the keyword (s) in the input field, you can perform the search against an array which contains the fundamental fields such as heading, bodyText and against a custom list of fields just for that particular topic, such as the News:

string[] aliasNewsList = new string[]{"newsDate", "newsLocation", "newsSummary", "newsCategory"};

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.