Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
RavenDB searching multiple words

I want to search documents in RavenDB and make the search results more precise for each word searched.

This is my current code (simplified). For each iteration in the loop I want to make and "and" clause. How is that possible?

At the moment I just get more results for each word, but I want to get less results per word.

using (var session = this.ravenSession.Store.OpenAsyncSession())
{
    var query = session.Query<TestDocument, TestIndex>();

    foreach (string word in search.Split(' '))
    {
        query = query.Search(x => x.Brand, word, boost: 5)
                     .Search(x => x.Model, word, boost: 3)
                     .Search(x => x.Variant, word)
                     .Search(x => x.Color, word);
    }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Solved: I had to use a DocumentQuery and make sub clauses for each loop.

using (var session = this.ravenSession.Store.OpenAsyncSession())
{
    var query = session.Advanced.AsyncDocumentQuery<TestDocument>();

    var words = search.Split(' ');

    for (int i = 0; i < words.Length; i++)
    {
        query.OpenSubclause();

        query = query.Search(x => x.Brand, words[i]).Boost(5).OrElse()
                     .Search(x => x.Model, words[i]).Boost(3).OrElse()
                     .Search(x => x.Variant, words[i]).OrElse()
                     .Search(x => x.Color, words[i]);

        query.CloseSubclause();

        if (i < (words.Length - 1))
        {
            query.AndAlso();
        }
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!