Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
Ravendb query order by value

I have objects with fields score and id. I need to get some amount of this objecs from from to from + count, which ordering by field score in descending order. Inside each equals range I need to get object with specific value of id on top of this range if it exist.

Example:

 1. score = 10, id = 5
 2. score = 20, id = 6
 3. score = 20, id = 7
 4. score = 20, id = 8
 5. score = 30, id = 9

Specific value id = 7, from = 0, count = 2

Expected result:

 1. score = 30, id = 9
 2. score = 20, id = 7  <--- my specific value on top of equal range, where score = 20

I write simple query:

final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
            .orderByDescending("score", OrderingType.LONG)
            .skip(from)
            .take(count)
            .toList();

But this does not take into account the conditions with specific value id. How can i do it?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you have this id field indexed in your index, then you can add a whereGreaterThan condition in your query, to filter for those id's that are greater than '7'

So query would be something like:

final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
            .whereGreaterThan("id", 7)
            .orderByDescending("score", OrderingType.LONG)
            .skip(from)
            .take(count)
            .toList();

See documentation link:
https://ravendb.net/docs/article-page/5.1/java/indexes/querying/filtering#where---numeric-property

Is id the document id ? because then it doesn't have to be indexed, should work w/ just adding the 'where' condition to the query. See: https://ravendb.net/docs/article-page/5.1/java/indexes/querying/basics#example-ii---filtering

Btw, check out the code samples in https://demo.ravendb.net/
In each sample, click the 'Java' tab to see sample Java code.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda