Copied to clipboard

Flag this post as spam?

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


  • David Amri 214 posts 740 karma points
    Aug 08, 2018 @ 12:49
    David Amri
    0

    Hi,

    I'm trying to set up phrase search with Lucene. I'm getting nice results when searching the "nodeTitle" field.

    var luceneString = "nodeTitle:" + searchTerm;
    

    But how should I add more fields to search upon?

    var luceneString = "nodeTitle: field2: field3:" + searchTerm;
    

    Best regards David

  • Alex Brown 129 posts 620 karma points
    Aug 09, 2018 @ 07:35
    Alex Brown
    100

    Lucene uses a single whitespace (i.e. " ") as an "OR".

    In your case it would be:

    var luceneString = "nodeTitle:" + searchTerm + " field2:" + searchTerm + " field3:" + searchTerm;
    

    This query says "find all results where nodeTitle = searchTerm OR field2 = searchTerm OR field3 = searchTerm.

    It's personal preference but if you're stringing strings together then maybe use string interpolate or string.format?

    E.g.

    var luceneString = $"nodeTitle:{searchTerm} field2:{searchTerm} field3:{searchTerm}";
    
Please Sign in or register to post replies

Write your reply to:

Draft