-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* workaround for issue #375 * fixes issue #381 * Restore nonVocab test, provide 0 scores for nonVocab terms * Patch up the TermSupplier * Cleanup whitespace change * Fix params * Add some tests to verify new logic, add shard param for explorer * Fix failing IT * Cleanup unneeded param * More cleanup * Move TermStates building to createWeight to satisfy DFS logic Co-authored-by: = <[email protected]>
- Loading branch information
Showing
6 changed files
with
193 additions
and
18 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/javaRestTest/java/com/o19s/es/ltr/ShardStatsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.o19s.es.ltr; | ||
|
||
import com.o19s.es.explore.ExplorerQueryBuilder; | ||
import com.o19s.es.termstat.TermStatQueryBuilder; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.search.SearchType; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.TermQueryBuilder; | ||
import org.elasticsearch.search.SearchHits; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/* | ||
These tests mostly verify that shard vs collection stat counting is working as expected. | ||
*/ | ||
public class ShardStatsIT extends ESIntegTestCase { | ||
@Override | ||
protected int numberOfShards() { | ||
return 2; | ||
} | ||
|
||
protected void createIdx() { | ||
prepareCreate("idx") | ||
.addMapping("type", "s", "type=text"); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
indexDoc(i); | ||
} | ||
refreshIndex(); | ||
} | ||
|
||
protected void indexDoc(int id) { | ||
client().prepareIndex("idx", "type", Integer.toString(id)) | ||
.setRouting( ((id % 2) == 0 ) ? "a" : "b" ) | ||
.setSource("s", "zzz").get(); | ||
} | ||
|
||
protected void refreshIndex() { | ||
client().admin().indices().prepareRefresh("idx").get(); | ||
} | ||
|
||
public void testDfsExplorer() throws Exception { | ||
createIdx(); | ||
|
||
QueryBuilder q = new TermQueryBuilder("s", "zzz"); | ||
|
||
ExplorerQueryBuilder eq = new ExplorerQueryBuilder() | ||
.query(q) | ||
.statsType("min_raw_df"); | ||
|
||
final SearchResponse r = client().prepareSearch("idx") | ||
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) | ||
.setQuery(eq).get(); | ||
|
||
assertSearchResponse(r); | ||
|
||
SearchHits hits = r.getHits(); | ||
assertThat(hits.getAt(0).getScore(), equalTo(4.0f)); | ||
} | ||
|
||
public void testNonDfsExplorer() throws Exception { | ||
createIdx(); | ||
|
||
QueryBuilder q = new TermQueryBuilder("s", "zzz"); | ||
|
||
ExplorerQueryBuilder eq = new ExplorerQueryBuilder() | ||
.query(q) | ||
.statsType("min_raw_df"); | ||
|
||
final SearchResponse r = client().prepareSearch("idx") | ||
.setSearchType(SearchType.QUERY_THEN_FETCH) | ||
.setQuery(eq).get(); | ||
|
||
assertSearchResponse(r); | ||
|
||
SearchHits hits = r.getHits(); | ||
assertThat(hits.getAt(0).getScore(), equalTo(2.0f)); | ||
} | ||
|
||
public void testDfsTSQ() throws Exception { | ||
createIdx(); | ||
|
||
TermStatQueryBuilder tsq = new TermStatQueryBuilder() | ||
.expr("df") | ||
.aggr("min") | ||
.posAggr("min") | ||
.terms(new String[]{"zzz"}) | ||
.fields(new String[]{"s"}); | ||
|
||
final SearchResponse r = client().prepareSearch("idx") | ||
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) | ||
.setQuery(tsq) | ||
.get(); | ||
|
||
assertSearchResponse(r); | ||
|
||
SearchHits hits = r.getHits(); | ||
assertThat(hits.getAt(0).getScore(), equalTo(4.0f)); | ||
} | ||
|
||
public void testNonDfsTSQ() throws Exception { | ||
createIdx(); | ||
|
||
TermStatQueryBuilder tsq = new TermStatQueryBuilder() | ||
.expr("df") | ||
.aggr("min") | ||
.posAggr("min") | ||
.terms(new String[]{"zzz"}) | ||
.fields(new String[]{"s"}); | ||
|
||
final SearchResponse r = client().prepareSearch("idx") | ||
.setSearchType(SearchType.QUERY_THEN_FETCH) | ||
.setQuery(tsq) | ||
.get(); | ||
|
||
assertSearchResponse(r); | ||
|
||
SearchHits hits = r.getHits(); | ||
assertThat(hits.getAt(0).getScore(), equalTo(2.0f)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters