use of edu.neu.ccs.pyramid.feature.SpanNotNgram in project pyramid by cheng-li.
the class ESIndexTest method test12.
static void test12() throws Exception {
ESIndex index = new ESIndex.Builder().setClientType("node").setIndexName("imdb").build();
Ngram ngram1 = new Ngram();
ngram1.setInOrder(true);
ngram1.setNgram("recommend");
ngram1.setField("body");
ngram1.setSlop(0);
Ngram ngram2 = new Ngram();
ngram2.setInOrder(true);
ngram2.setNgram("not");
ngram2.setField("body");
ngram2.setSlop(0);
SpanNotNgram spanNotNgram = new SpanNotNgram();
spanNotNgram.setInclude(ngram1);
spanNotNgram.setExclude(ngram2);
spanNotNgram.setPre(2);
SearchResponse response = index.spanNot(spanNotNgram);
System.out.println(response.getHits().getTotalHits());
index.close();
}
use of edu.neu.ccs.pyramid.feature.SpanNotNgram in project pyramid by cheng-li.
the class ESIndex method spanNot.
public SearchResponse spanNot(SpanNotNgram ngram, String[] ids) {
Ngram include = ngram.getInclude();
String field1 = include.getField();
int slop1 = include.getSlop();
boolean inOrder1 = include.isInOrder();
SpanNearQueryBuilder queryBuilder1 = QueryBuilders.spanNearQuery();
for (String term : include.getTerms()) {
queryBuilder1.clause(new SpanTermQueryBuilder(field1, term));
}
queryBuilder1.inOrder(inOrder1);
queryBuilder1.slop(slop1);
Ngram exclude = ngram.getExclude();
String field2 = exclude.getField();
int slop2 = exclude.getSlop();
boolean inOrder2 = exclude.isInOrder();
SpanNearQueryBuilder queryBuilder2 = QueryBuilders.spanNearQuery();
for (String term : exclude.getTerms()) {
queryBuilder2.clause(new SpanTermQueryBuilder(field2, term));
}
queryBuilder2.inOrder(inOrder2);
queryBuilder2.slop(slop2);
int pre = ngram.getPre();
int post = ngram.getPost();
SpanNotQueryBuilder spanNotQueryBuilder = QueryBuilders.spanNotQuery().include(queryBuilder1).exclude(queryBuilder2);
//todo upgrade to 1.5
// .pre(pre).post(post);
IdsFilterBuilder idsFilterBuilder = new IdsFilterBuilder(documentType);
idsFilterBuilder.addIds(ids);
SearchResponse response = client.prepareSearch(indexName).setSize(ids.length).setHighlighterFilter(false).setTrackScores(false).setNoFields().setExplain(false).setFetchSource(false).setQuery(QueryBuilders.filteredQuery(spanNotQueryBuilder, idsFilterBuilder)).execute().actionGet();
return response;
}
use of edu.neu.ccs.pyramid.feature.SpanNotNgram in project pyramid by cheng-li.
the class ESIndex method spanNot.
public SearchResponse spanNot(SpanNotNgram ngram) {
Ngram include = ngram.getInclude();
String field1 = include.getField();
int slop1 = include.getSlop();
boolean inOrder1 = include.isInOrder();
SpanNearQueryBuilder queryBuilder1 = QueryBuilders.spanNearQuery();
for (String term : include.getTerms()) {
queryBuilder1.clause(new SpanTermQueryBuilder(field1, term));
}
queryBuilder1.inOrder(inOrder1);
queryBuilder1.slop(slop1);
Ngram exclude = ngram.getExclude();
String field2 = exclude.getField();
int slop2 = exclude.getSlop();
boolean inOrder2 = exclude.isInOrder();
SpanNearQueryBuilder queryBuilder2 = QueryBuilders.spanNearQuery();
for (String term : exclude.getTerms()) {
queryBuilder2.clause(new SpanTermQueryBuilder(field2, term));
}
queryBuilder2.inOrder(inOrder2);
queryBuilder2.slop(slop2);
int pre = ngram.getPre();
int post = ngram.getPost();
SpanNotQueryBuilder spanNotQueryBuilder = QueryBuilders.spanNotQuery().include(queryBuilder1).exclude(queryBuilder2);
//todo: upgrade to 1.5
// .pre(pre).post(post);
SearchResponse response = client.prepareSearch(indexName).setSize(this.numDocs).setHighlighterFilter(false).setTrackScores(false).setNoFields().setExplain(false).setFetchSource(false).setQuery(spanNotQueryBuilder).execute().actionGet();
return response;
}
Aggregations