Search code examples
c#luceneravendb

RavenDb search over multiple string properties


I'm trying to make a search over multiple properties. I want to get all the items that at least one of its properties contains the specified term. The following code works as expected but I would like to achieve this using Search instead of a Lucene query.

var t = Regex.Replace(term, " ", @"\ ");
var query = session.Advanced
  .DocumentQuery<Order>()
  .Where($"Property1:*{t}* OR Property2:*{t}* OR Property3:*{t}*");

Solution

  • It's been a while since I asked the question but in the last couple of days, I went over this again. I ended up querying in the way I show below and everything works fine.

                var search = $"\"*{term}*\"";
                var qOpt = EscapeQueryOptions.RawQuery;
    
                query = query
                    .Search(o => o.Property1, search, escapeQueryOptions: qOpt)
                    .Search(o => o.Property2, search, escapeQueryOptions: qOpt)
                    .Search(o => o.Property3, search, escapeQueryOptions: qOpt)
                    .Search(o => o.Property4, search, escapeQueryOptions: qOpt);