#594 - ElasticSearch - Add match / TextExpression support (Full text search expression)

This commit is contained in:
Robin Bygrave
2016-03-09 21:48:22 +13:00
parent 3c63b79324
commit 34dcc98908
37 changed files with 860 additions and 79 deletions
@@ -0,0 +1,62 @@
package com.avaje.ebean;
import com.avaje.ebean.search.Match;
import com.avaje.tests.model.basic.Order;
import org.junit.Test;
public class TextExpressionListTest {
@Test
public void syntax() {
Ebean.find(Order.class)
.text().match("name", "rob");
Ebean.find(Order.class)
.text().should()
.match("name", "rob")
.match("note", "war and peace");
Ebean.find(Order.class)
.text()
.should()
.match("title", "war and peace")
.match("author", "leo tolstoy")
.should()
.match("translator", "Constance Garnett")
.match("translator", "Louise Maude");
Ebean.find(Order.class)
.text()
.should()
.match("title", "war and peace")
.match("author", "leo tolstoy")
.should()
.match("translator", "Constance Garnett", Match.AND().boost(2).minShouldMatch("75%"))
.match("translator", "Louise Maude")
.where()
.gt("reviewDate", 12345);
Ebean.find(Order.class)
.text()
.must()
.match("title", "quick")
.endMust()
.should()
.match("title", "brown")
.match("title", "dog")
.endShould()
.mustNot()
.match("title", "lazy")
.endMustNot()
.where()
.gt("reviewDate", 12345);
}
}
@@ -0,0 +1,75 @@
package com.avaje.ebean.search;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class MatchTest {
Match match() {
return Match.AND()
.analyzer("whitespace")
.boost(2)
.cutoffFrequency(1)
.minShouldMatch("50%")
.maxExpansions(3)
.zeroTerms("all");
}
@Test
public void equals_when_allSet() {
assertEquals(match(), match());
assertEquals(match().hashCode(), match().hashCode());
}
@Test
public void notEquals_when_analyzer() {
assertNotEquals(match(), match().analyzer("foo"));
assertNotEquals(match().hashCode(), match().analyzer("foo").hashCode());
assertNotEquals(match(), match().analyzer(null));
assertNotEquals(match().hashCode(), match().analyzer(null).hashCode());
}
@Test
public void notEquals_when_boost() {
assertNotEquals(match(), match().boost(3));
}
@Test
public void notEquals_when_cutoffFrequency() {
assertNotEquals(match(), match().cutoffFrequency(3));
}
@Test
public void notEquals_when_maxExpansions() {
assertNotEquals(match(), match().maxExpansions(100));
}
@Test
public void notEquals_when_minShouldMatch() {
assertNotEquals(match(), match().minShouldMatch("12%"));
}
@Test
public void notEquals_when_zeroTerms() {
assertNotEquals(match(), match().zeroTerms("none"));
}
@Test
public void notEquals_when_phrase() {
assertNotEquals(match(), match().phrase());
}
@Test
public void notEquals_when_phrasePrefix() {
assertNotEquals(match(), match().phrasePrefix());
}
@Test
public void notEquals_when_operator() {
assertNotEquals(match(), match().opOr());
}
}