Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Murray Roke 503 posts 966 karma points c-trib
    May 17, 2010 @ 05:42
    Murray Roke
    0

    Examine - Swapping Search Provider Name seems to 'cache' first used provider

    I have the ability to search using different search providers.

    The SearchProviderName is pulled out of an umbraco property, so it differs in the different sections that use search.

    However it seems to get stuck on the first one used after the app loads.

    Here's my code:

    var searchProvider = ExamineManager.Instance.SearchProviderCollection[SearchProviderName];
    if (searchProvider == null)
    searchProvider = ExamineManager.Instance.DefaultSearchProvider;

    var criteria = searchProvider.CreateSearchCriteria(IndexType.Content);
    var results = searchProvider.Search(criteria);

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    May 17, 2010 @ 06:16
    Aaron Powell
    0

    When/ where is the code executing?

    Have you tried hitting a debugger to see what the name of the searchProvider object is?

    I've got some working POC code for swapping providers on a per-request using an IoC container (and it worked :P)

  • Murray Roke 503 posts 966 karma points c-trib
    May 18, 2010 @ 01:57
    Murray Roke
    0

    The code executes on page load if a query parameter is found on the querystring.

    I step straight into this code and break on the last line shown here when I collect all the debug info using the Imediate Window.

    var searchProvider = ExamineManager.Instance.SearchProviderCollection[SearchProviderName];
    if (searchProvider == null)
    searchProvider = ExamineManager.Instance.DefaultSearchProvider;

    var criteria = searchProvider.CreateSearchCriteria(IndexType.Content);
    criteria.RawQuery(q);
    var results = searchProvider.Search(criteria);

    var summary = (from result in results select new { result.Id, result.Score, Title = result.Fields["nodeName"] }).ToList();
    RecordCount = results.TotalItemCount; // break point here.

    The results below to me they look like I've got a singleton of the inex that doesn't update unless I reload the application. (Similar to the issue I had earlier)

    Here's the debug info for 5 queries, the first 3 use a "member-only" index, and the results change only when touching the web.config.

    The second 2 use a "public" index, but the first results come from the "member-only" index until I touch the web.config again.

    searchProvider.Name
    "KnowledgeForMembers"
    criteria.ToString()
    "{ MaxResults: 0, SearchIndexType: Content, LuceneQuery: +(abstract:lorem bodyText:lorem id:lorem nodeName:lorem updateDate:lorem writerName:lorem path:lorem nodeTypeAlias:lorem parentID:lorem) }"
    summary
    Count = 2
    [0]: { Id = 1166, Score = 0.090463385, Title = "all attachments" }
    [1]: { Id = 1182, Score = 0.03762361, Title = "full article for members" }

    // here I update article #1182 to append v2 to the title.

    searchProvider.Name

    "KnowledgeForMembers"
    criteria.ToString()
    "{ MaxResults: 0, SearchIndexType: Content, LuceneQuery: +(abstract:lorem bodyText:lorem id:lorem nodeName:lorem updateDate:lorem writerName:lorem path:lorem nodeTypeAlias:lorem parentID:lorem) }"
    summary
    Count = 2
        [0]: { Id = 1166, Score = 0.090463385, Title = "all attachments" }
        [1]: { Id = 1182, Score = 0.03762361, Title = "full article for members" }

    // touch web.config

    searchProvider.Name
    "KnowledgeForMembers"
    criteria.ToString()
    "{ MaxResults: 0, SearchIndexType: Content, LuceneQuery: +(abstract:lorem bodyText:lorem id:lorem nodeName:lorem updateDate:lorem writerName:lorem path:lorem nodeTypeAlias:lorem parentID:lorem) }"
    summary
    Count = 2
        [0]: { Id = 1166, Score = 0.090463385, Title = "all attachments" }
        [1]: { Id = 1182, Score = 0.03762361, Title = "full article for members v2" }

    searchProvider.Name
    "KnowledgeForPublic"
    criteria.ToString()
    "{ MaxResults: 0, SearchIndexType: Content, LuceneQuery: +(abstract:lorem bodyText:lorem id:lorem nodeName:lorem updateDate:lorem writerName:lorem path:lorem nodeTypeAlias:lorem parentID:lorem) }"
    summary
    Count = 2
        [0]: { Id = 1166, Score = 0.090463385, Title = "all attachments" }
        [1]: { Id = 1182, Score = 0.03762361, Title = "full article for members v2" }

    // touch web.config

    searchProvider.Name
    "KnowledgeForPublic"
    criteria.ToString()
    "{ MaxResults: 0, SearchIndexType: Content, LuceneQuery: +(abstract:lorem bodyText:lorem id:lorem nodeName:lorem updateDate:lorem writerName:lorem path:lorem nodeTypeAlias:lorem parentID:lorem) }"
    summary
    Count = 1
        [0]: { Id = 1202, Score = 0.257482857, Title = "free teaser article" }

    Hope I included enough info but not toooooo much :-)

    Cheers.

    Murray.

Please Sign in or register to post replies

Write your reply to:

Draft