Copied to clipboard

Flag this post as spam?

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


  • Mitch 42 posts 157 karma points
    May 29, 2019 @ 14:08
    Mitch
    0

    Adding multiple fields with same name to index

    Hi guys

    I've read that Lucene can handle multiple fields with the same name in a document. I've even seen an example using Examine. However, I'm struggling to get it working in 7.14.

    Take this simple code:

    public static void CourseIndexer_DocumentWriting(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e, UmbracoHelper umbHelper)
        {
            var practiceAreas = course.PracticeAreas;
    
            foreach (var practiceArea in practiceAreas)
            {
                e.Document.Add(new Field("practiceArea", practiceArea, Field.Store.YES, Field.Index.NOT_ANALYZED));
            }
    
        }
    

    This only ever adds a single field named "practiceArea". Am I doing something wrong here or is it a bug?

    Thanks

  • Matthew Wise 271 posts 1373 karma points MVP 4x c-trib
    May 30, 2019 @ 08:53
    Matthew Wise
    0

    Hi Mitch,

    You can do this as a space separated terms. You cant have multiple fields with the same name.

    If you terms have spaces just make sure you query with And not or

    Matt

  • Mitch 42 posts 157 karma points
    May 30, 2019 @ 10:03
    Mitch
    0

    Hi Matt

    Thanks for your reply but it is actually possible to do. My code seems to work but I was testing it using the search in the Examine Management tool in the backoffice. In the search results it only seems to display a field once even though several fields with the same name exists, and are searchable. I think this can be classed as a bug.

Please Sign in or register to post replies

Write your reply to:

Draft