Skip to content

Commit

Permalink
Use hits instead of totalhits to determine if elasticsearch results e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
Paul Warren committed Oct 3, 2019
1 parent 6320123 commit b087999
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Expand Up @@ -113,7 +113,7 @@ public Iterable<Serializable> findAllKeywordsWithWeights(String[] terms, double[
private List<Serializable> getIDs(SearchHits result) {
List<Serializable> contents = new ArrayList<>();

if (result == null || result.getTotalHits() == 0) {
if (result == null) {
return contents;
}

Expand Down
Expand Up @@ -65,7 +65,6 @@ public PlatformTransactionManager transactionManager() {
@Bean
public RestHighLevelClient client() {
return new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
// return new RestHighLevelClient(RestClient.builder(new HttpHost("search-test2-tnipwmdwedcr6d2rmale5bjp7u.eu-west-2.es.amazonaws.com")));
}

@Value("/org/springframework/content/jpa/schema-drop-hsqldb.sql")
Expand Down
Expand Up @@ -7,6 +7,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;

import com.github.paulcwarren.ginkgo4j.Ginkgo4jConfiguration;
import com.github.paulcwarren.ginkgo4j.Ginkgo4jSpringRunner;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -25,12 +26,14 @@
import org.springframework.content.commons.search.Searchable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.util.Assert;

import static com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.AfterEach;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.BeforeEach;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.Context;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.Describe;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.FIt;
import static com.github.paulcwarren.ginkgo4j.Ginkgo4jDSL.It;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.hasItem;
Expand Down Expand Up @@ -124,6 +127,25 @@ public class ElasticsearchIntegrationTest {
});
});

Context("when the content is searched with findKeyword", () -> {

It("should become searchable", () -> {
assertThat(() -> store.findKeyword("one"), eventuallyEval(
allOf(
hasItem(doc1.getContentId()),
not(hasItem(doc2.getContentId()))
),
Duration.ofSeconds(10)));

assertThat(() -> store.findKeyword("two"), eventuallyEval(
allOf(
not(hasItem(doc1.getContentId())),
hasItem(doc2.getContentId())
),
Duration.ofSeconds(10)));
});
});

Context("given that document is deleted", () -> {

BeforeEach(() -> {
Expand Down

0 comments on commit b087999

Please sign in to comment.