Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.TextQuery


   */
  @Test
  public void shouldOnlyFindTextInSpecificLanguage() {

    initWithDefaultDocuments();
    List<FullTextDoc> result = template.find(new TextQuery("leche").addCriteria(where("language").is("spanish")),
        FullTextDoc.class);
    assertThat(result, hasSize(1));
    assertThat(result.get(0), equalTo(SPANISH_MILK));
  }
View Full Code Here


  @Test
  public void shouldNotFindDocumentsWithNegatedTerms() {

    initWithDefaultDocuments();

    List<FullTextDoc> result = template.find(new TextQuery("bake coffee -cake"), FullTextDoc.class);
    assertThat(result, hasSize(2));
    assertThat(result, hasItems(BAKE, COFFEE));
  }
View Full Code Here

  @Test
  public void shouldInlcudeScoreCorreclty() {

    initWithDefaultDocuments();

    List<FullTextDoc> result = template.find(new TextQuery("bake coffee -cake").includeScore().sortByScore(),
        FullTextDoc.class);

    assertThat(result, hasSize(2));
    for (FullTextDoc scoredDoc : result) {
      assertTrue(scoredDoc.score > 0F);
View Full Code Here

  @Test
  public void shouldApplyPhraseCorrectly() {

    initWithDefaultDocuments();

    TextQuery query = TextQuery.queryText(TextCriteria.forDefaultLanguage().matchingPhrase("milk and sugar"));
    List<FullTextDoc> result = template.find(query, FullTextDoc.class);

    assertThat(result, hasSize(1));
    assertThat(result, contains(MILK_AND_SUGAR));
  }
View Full Code Here

  @Test
  public void shouldReturnEmptyListWhenNoDocumentsMatchGivenPhrase() {

    initWithDefaultDocuments();

    TextQuery query = TextQuery.queryText(TextCriteria.forDefaultLanguage().matchingPhrase("milk no sugar"));
    List<FullTextDoc> result = template.find(query, FullTextDoc.class);

    assertThat(result, empty());
  }
View Full Code Here

  public void shouldApplyPaginationCorrectly() {

    initWithDefaultDocuments();

    // page 1
    List<FullTextDoc> result = template.find(new TextQuery("bake coffee cake").sortByScore()
        .with(new PageRequest(0, 2)), FullTextDoc.class);
    assertThat(result, hasSize(2));
    assertThat(result, contains(BAKE, COFFEE));

    // page 2
    result = template.find(new TextQuery("bake coffee cake").sortByScore().with(new PageRequest(1, 2)),
        FullTextDoc.class);
    assertThat(result, hasSize(1));
    assertThat(result, contains(CAKE));
  }
View Full Code Here

  @Test
  public void shouldOnlyFindDocumentsMatchingAnyWordOfGivenQuery() {

    initWithDefaultDocuments();

    List<FullTextDoc> result = template.find(new TextQuery("bake coffee cake"), FullTextDoc.class);
    assertThat(result, hasSize(3));
    assertThat(result, hasItems(BAKE, COFFEE, CAKE));
  }
View Full Code Here

  @Test
  public void shouldNotFindDocumentsWhenQueryDoesNotMatchAnyDocumentInIndex() {

    initWithDefaultDocuments();

    List<FullTextDoc> result = template.find(new TextQuery("tasmanian devil"), FullTextDoc.class);
    assertThat(result, hasSize(0));
  }
View Full Code Here

    initWithDefaultDocuments();
    FullTextDoc coffee2 = new FullTextDocBuilder().headline("coffee").build();
    template.insert(coffee2);

    List<FullTextDoc> result = template.find(new TextQuery("bake coffee cake").sortByScore(), FullTextDoc.class);
    assertThat(result, hasSize(4));
    assertThat(result.get(0), anyOf(equalTo(BAKE), equalTo(coffee2)));
    assertThat(result.get(1), anyOf(equalTo(BAKE), equalTo(coffee2)));
    assertThat(result.get(2), equalTo(COFFEE));
    assertThat(result.get(3), equalTo(CAKE));
View Full Code Here

   */
  @Test
  public void shouldFindTextInAnyLanguage() {

    initWithDefaultDocuments();
    List<FullTextDoc> result = template.find(new TextQuery("leche"), FullTextDoc.class);
    assertThat(result, hasSize(2));
    assertThat(result, hasItems(SPANISH_MILK, FRENCH_MILK));
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.query.TextQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.