Skip to content

Commit

Permalink
HSEARCH-2254 Update test DSL api
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Sep 11, 2019
1 parent 4b3a533 commit 4e1c93b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
Expand Up @@ -198,15 +198,15 @@ public void then_flattened_nested() {
String flattenedField = "flattened." + indexMapping.flattenedField.relativeFieldName;
String nestedField = "nested." + indexMapping.flattenedField.relativeFieldName;

query = simpleQuery( f -> f.byField( flattenedField ).asc().then().byField( normalField ).asc() );
query = simpleQuery( f -> f.field( flattenedField ).asc().then().field( normalField ).asc() );
// [a b a][a a b] => {1 3 2}
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_3, DOCUMENT_2 );

query = simpleQuery( f -> f.byField( nestedField ).asc().then().byField( flattenedField ).asc() );
query = simpleQuery( f -> f.field( nestedField ).asc().then().field( flattenedField ).asc() );
// [b a a][a b a] => {3 2 1}
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_3, DOCUMENT_2, DOCUMENT_1 );

query = simpleQuery( f -> f.byField( normalField ).asc().then().byField( nestedField ).asc() );
query = simpleQuery( f -> f.field( normalField ).asc().then().field( nestedField ).asc() );
// [a a b][b a a] => {2 1 3}
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_2, DOCUMENT_1, DOCUMENT_3 );
}
Expand All @@ -227,8 +227,8 @@ public void then_nested_normal_limit1() {
* The test below would fail if, by chance, the top N documents of the first pass did not include
* the expected top document overall (i.e. document 2 or 3).
*/
query = simpleQuery( f -> f.byField( nestedField ).asc().onMissingValue().sortLast()
.then().byField( normalField ).asc() );
query = simpleQuery( f -> f.field( nestedField ).asc().missing().last()
.then().field( normalField ).asc() );
// [b a a][a b b] => {[2 or 3] (3 or 2) 1}
assertThat( query.fetch( 1 ) ).hits().ordinal( 0 )
.isDocRefHit( INDEX_NAME, DOCUMENT_2, DOCUMENT_3 );
Expand All @@ -242,15 +242,15 @@ public void then_flattened_nested_limit2() {
String flattenedField = "flattened." + indexMapping.flattenedField.relativeFieldName;
String nestedField = "nested." + indexMapping.flattenedField.relativeFieldName;

query = simpleQuery( f -> f.byField( flattenedField ).asc().then().byField( normalField ).asc() );
query = simpleQuery( f -> f.field( flattenedField ).asc().then().field( normalField ).asc() );
// [a b a][a a b] => {[1 3] 2}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_3 );

query = simpleQuery( f -> f.byField( nestedField ).asc().then().byField( flattenedField ).asc() );
query = simpleQuery( f -> f.field( nestedField ).asc().then().field( flattenedField ).asc() );
// [b a a][a b a] => {[3 2] 1}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_3, DOCUMENT_2 );

query = simpleQuery( f -> f.byField( normalField ).asc().then().byField( nestedField ).asc() );
query = simpleQuery( f -> f.field( normalField ).asc().then().field( nestedField ).asc() );
// [a a b][b a a] => {[2 1] 3}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_2, DOCUMENT_1 );
}
Expand All @@ -264,24 +264,24 @@ public void then_flattened_nested_filterByPredicate() {
String nestedField = "nested." + indexMapping.flattenedField.relativeFieldName;

query = indexManager.createScope().query()
.predicate( b -> b.match().onField( normalField ).matching( "aaa" ) )
.sort( f -> f.byField( flattenedField ).asc().then().byField( normalField ).asc() )
.predicate( b -> b.match().field( normalField ).matching( "aaa" ) )
.sort( f -> f.field( flattenedField ).asc().then().field( normalField ).asc() )
.toQuery();

// [a b a][a a b] => {1+ 3 2+}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_2 );

query = indexManager.createScope().query()
.predicate( b -> b.match().onField( normalField ).matching( "aaa" ) )
.sort( f -> f.byField( nestedField ).asc().then().byField( flattenedField ).asc() )
.predicate( b -> b.match().field( normalField ).matching( "aaa" ) )
.sort( f -> f.field( nestedField ).asc().then().field( flattenedField ).asc() )
.toQuery();

// [b a a][a b a] => {3 2+ 1+}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_2, DOCUMENT_1 );

query = indexManager.createScope().query()
.predicate( b -> b.match().onField( normalField ).matching( "aaa" ) )
.sort( f -> f.byField( normalField ).asc().then().byField( nestedField ).asc() )
.predicate( b -> b.match().field( normalField ).matching( "aaa" ) )
.sort( f -> f.field( normalField ).asc().then().field( nestedField ).asc() )
.toQuery();
// [a a b][b a a] => {2+ 1+ 3}
assertThat( query.fetch( 2 ) ).hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_2, DOCUMENT_1 );
Expand Down
Expand Up @@ -349,37 +349,37 @@ public void byField_inNestedObject() {
SearchQuery<DocumentReference> query;
String fieldPath = indexMapping.nestedObject.relativeFieldName + "." + fieldModel.relativeFieldName;

query = simpleQuery( b -> b.byField( fieldPath ).onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( fieldPath ).missing().last() );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_2, DOCUMENT_3, EMPTY );

query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().last() );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_2, DOCUMENT_3, EMPTY );

query = simpleQuery( b -> b.byField( fieldPath ).desc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( fieldPath ).desc().missing().last() );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_3, DOCUMENT_2, DOCUMENT_1, EMPTY );

query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().first() );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, EMPTY, DOCUMENT_1, DOCUMENT_2, DOCUMENT_3 );

query = simpleQuery( b -> b.byField( fieldPath ).desc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( fieldPath ).desc().missing().first() );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, EMPTY, DOCUMENT_3, DOCUMENT_2, DOCUMENT_1 );

// Explicit order with onMissingValue().use( ... )
query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().use( fieldModel.before1Value ) );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().use( fieldModel.before1Value ) );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, EMPTY, DOCUMENT_1, DOCUMENT_2, DOCUMENT_3 );
query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().use( fieldModel.between1And2Value ) );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().use( fieldModel.between1And2Value ) );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, EMPTY, DOCUMENT_2, DOCUMENT_3 );
query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().use( fieldModel.between2And3Value ) );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().use( fieldModel.between2And3Value ) );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_2, EMPTY, DOCUMENT_3 );
query = simpleQuery( b -> b.byField( fieldPath ).asc().onMissingValue().use( fieldModel.after3Value ) );
query = simpleQuery( b -> b.field( fieldPath ).asc().missing().use( fieldModel.after3Value ) );
assertThat( query )
.hasDocRefHitsExactOrder( INDEX_NAME, DOCUMENT_1, DOCUMENT_2, DOCUMENT_3, EMPTY );
}
Expand Down
Expand Up @@ -127,57 +127,57 @@ public void byIndexOrder() {
@Test
public void byField_flattened() {
SearchQuery<DocumentReference> query;
query = simpleQuery( b -> b.byField( "flattenedObject.string" )
.asc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "flattenedObject.string" )
.asc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, FIRST_ID, SECOND_ID, THIRD_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "flattenedObject.string" )
.desc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "flattenedObject.string" )
.desc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "flattenedObject.integer" )
.asc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "flattenedObject.integer" )
.asc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, FIRST_ID, SECOND_ID, THIRD_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "flattenedObject.integer" )
.desc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "flattenedObject.integer" )
.desc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID );
}

@Test
@TestForIssue( jiraKey = "HSEARCH-2254" )
public void byField_nested() {
SearchQuery<DocumentReference> query;
query = simpleQuery( b -> b.byField( "nestedObject.string" )
.asc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "nestedObject.string" )
.asc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, FIRST_ID, SECOND_ID, THIRD_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "nestedObject.string" )
.desc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "nestedObject.string" )
.desc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "nestedObject.string" )
.asc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( "nestedObject.string" )
.asc().missing().first() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, EMPTY_ID, FIRST_ID, SECOND_ID, THIRD_ID );

query = simpleQuery( b -> b.byField( "nestedObject.string" )
.desc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( "nestedObject.string" )
.desc().missing().first() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, EMPTY_ID, THIRD_ID, SECOND_ID, FIRST_ID );

query = simpleQuery( b -> b.byField( "nestedObject.integer" )
.asc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "nestedObject.integer" )
.asc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, FIRST_ID, SECOND_ID, THIRD_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "nestedObject.integer" )
.desc().onMissingValue().sortLast() );
query = simpleQuery( b -> b.field( "nestedObject.integer" )
.desc().missing().last() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, THIRD_ID, SECOND_ID, FIRST_ID, EMPTY_ID );

query = simpleQuery( b -> b.byField( "nestedObject.integer" )
.asc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( "nestedObject.integer" )
.asc().missing().first() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, EMPTY_ID, FIRST_ID, SECOND_ID, THIRD_ID );

query = simpleQuery( b -> b.byField( "nestedObject.integer" )
.desc().onMissingValue().sortFirst() );
query = simpleQuery( b -> b.field( "nestedObject.integer" )
.desc().missing().first() );
assertThat( query ).hasDocRefHitsExactOrder( INDEX_NAME, EMPTY_ID, THIRD_ID, SECOND_ID, FIRST_ID );
}

Expand Down

0 comments on commit 4e1c93b

Please sign in to comment.