Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda