mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-30 03:48:54 +00:00
API Change: moreLikeThis, closes #109.
This commit is contained in:
parent
52f193c849
commit
2d6c2d8586
@ -65,8 +65,7 @@ public class MoreLikeThisRequest implements ActionRequest {
|
|||||||
private int maxDocFreq = -1;
|
private int maxDocFreq = -1;
|
||||||
private int minWordLen = -1;
|
private int minWordLen = -1;
|
||||||
private int maxWordLen = -1;
|
private int maxWordLen = -1;
|
||||||
private Boolean boostTerms = null;
|
private float boostTerms = -1;
|
||||||
private float boostTermsFactor = -1;
|
|
||||||
|
|
||||||
private SearchType searchType = SearchType.DEFAULT;
|
private SearchType searchType = SearchType.DEFAULT;
|
||||||
private String searchQueryHint;
|
private String searchQueryHint;
|
||||||
@ -282,35 +281,20 @@ public class MoreLikeThisRequest implements ActionRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to boost terms in query based on "score" or not. Defaults to <tt>false</tt>.
|
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
||||||
*/
|
*/
|
||||||
public MoreLikeThisRequest boostTerms(Boolean boostTerms) {
|
public MoreLikeThisRequest boostTerms(float boostTerms) {
|
||||||
this.boostTerms = boostTerms;
|
this.boostTerms = boostTerms;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to boost terms in query based on "score" or not. Defaults to <tt>false</tt>.
|
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
||||||
*/
|
*/
|
||||||
public Boolean boostTerms() {
|
public float boostTerms() {
|
||||||
return this.boostTerms;
|
return this.boostTerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
|
||||||
*/
|
|
||||||
public MoreLikeThisRequest boostTermsFactor(float boostTermsFactor) {
|
|
||||||
this.boostTermsFactor = boostTermsFactor;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
|
||||||
*/
|
|
||||||
public float boostTermsFactor() {
|
|
||||||
return this.boostTermsFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An optional search source request allowing to control the search request for the
|
* An optional search source request allowing to control the search request for the
|
||||||
* more like this documents.
|
* more like this documents.
|
||||||
@ -483,10 +467,7 @@ public class MoreLikeThisRequest implements ActionRequest {
|
|||||||
maxDocFreq = in.readVInt();
|
maxDocFreq = in.readVInt();
|
||||||
minWordLen = in.readVInt();
|
minWordLen = in.readVInt();
|
||||||
maxWordLen = in.readVInt();
|
maxWordLen = in.readVInt();
|
||||||
if (in.readBoolean()) {
|
boostTerms = in.readFloat();
|
||||||
boostTerms = in.readBoolean();
|
|
||||||
}
|
|
||||||
boostTermsFactor = in.readFloat();
|
|
||||||
searchType = SearchType.fromId(in.readByte());
|
searchType = SearchType.fromId(in.readByte());
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
searchQueryHint = in.readUTF();
|
searchQueryHint = in.readUTF();
|
||||||
@ -553,13 +534,7 @@ public class MoreLikeThisRequest implements ActionRequest {
|
|||||||
out.writeVInt(maxDocFreq);
|
out.writeVInt(maxDocFreq);
|
||||||
out.writeVInt(minWordLen);
|
out.writeVInt(minWordLen);
|
||||||
out.writeVInt(maxWordLen);
|
out.writeVInt(maxWordLen);
|
||||||
if (boostTerms == null) {
|
out.writeFloat(boostTerms);
|
||||||
out.writeBoolean(false);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(true);
|
|
||||||
out.writeBoolean(boostTerms);
|
|
||||||
}
|
|
||||||
out.writeFloat(boostTermsFactor);
|
|
||||||
|
|
||||||
out.writeByte(searchType.id());
|
out.writeByte(searchType.id());
|
||||||
if (searchQueryHint == null) {
|
if (searchQueryHint == null) {
|
||||||
|
@ -222,7 +222,6 @@ public class TransportMoreLikeThisAction extends BaseAction<MoreLikeThisRequest,
|
|||||||
.likeText(likeText)
|
.likeText(likeText)
|
||||||
.percentTermsToMatch(request.percentTermsToMatch())
|
.percentTermsToMatch(request.percentTermsToMatch())
|
||||||
.boostTerms(request.boostTerms())
|
.boostTerms(request.boostTerms())
|
||||||
.boostTermsFactor(request.boostTermsFactor())
|
|
||||||
.minDocFreq(request.minDocFreq())
|
.minDocFreq(request.minDocFreq())
|
||||||
.maxDocFreq(request.maxDocFreq())
|
.maxDocFreq(request.maxDocFreq())
|
||||||
.minWordLen(request.minWordLen())
|
.minWordLen(request.minWordLen())
|
||||||
|
@ -42,8 +42,7 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
private int maxDocFreq = -1;
|
private int maxDocFreq = -1;
|
||||||
private int minWordLen = -1;
|
private int minWordLen = -1;
|
||||||
private int maxWordLen = -1;
|
private int maxWordLen = -1;
|
||||||
private Boolean boostTerms = null;
|
private float boostTerms = -1;
|
||||||
private float boostTermsFactor = -1;
|
|
||||||
private float boost = -1;
|
private float boost = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,20 +136,11 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether to boost terms in query based on "score" or not. Defaults to
|
|
||||||
* <tt>false</tt>.
|
|
||||||
*/
|
|
||||||
public MoreLikeThisFieldJsonQueryBuilder boostTerms(Boolean boostTerms) {
|
|
||||||
this.boostTerms = boostTerms;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
* Sets the boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
||||||
*/
|
*/
|
||||||
public MoreLikeThisFieldJsonQueryBuilder boostTermsFactor(float boostTermsFactor) {
|
public MoreLikeThisFieldJsonQueryBuilder boostTerms(float boostTerms) {
|
||||||
this.boostTermsFactor = boostTermsFactor;
|
this.boostTerms = boostTerms;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +184,9 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
if (maxWordLen != -1) {
|
if (maxWordLen != -1) {
|
||||||
builder.field("max_word_len", maxWordLen);
|
builder.field("max_word_len", maxWordLen);
|
||||||
}
|
}
|
||||||
if (boostTerms != null) {
|
if (boostTerms != -1) {
|
||||||
builder.field("boost_terms", boostTerms);
|
builder.field("boost_terms", boostTerms);
|
||||||
}
|
}
|
||||||
if (boostTermsFactor != -1) {
|
|
||||||
builder.field("boost_terms_factor", boostTermsFactor);
|
|
||||||
}
|
|
||||||
if (boost != -1) {
|
if (boost != -1) {
|
||||||
builder.field("boost", boost);
|
builder.field("boost", boost);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import org.elasticsearch.index.Index;
|
|||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.query.QueryParsingException;
|
import org.elasticsearch.index.query.QueryParsingException;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
import org.elasticsearch.util.Booleans;
|
|
||||||
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
|
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
|
|
||||||
@ -87,8 +86,7 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
|
|||||||
} else if ("max_word_len".equals(currentFieldName)) {
|
} else if ("max_word_len".equals(currentFieldName)) {
|
||||||
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
|
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
|
||||||
} else if ("boost_terms".equals(currentFieldName)) {
|
} else if ("boost_terms".equals(currentFieldName)) {
|
||||||
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
|
mltQuery.setBoostTerms(true);
|
||||||
} else if ("boost_terms_factor".equals(currentFieldName)) {
|
|
||||||
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
|
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
|
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
|
||||||
@ -106,9 +104,8 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
|
|||||||
mltQuery.setMinWordLen(jp.getIntValue());
|
mltQuery.setMinWordLen(jp.getIntValue());
|
||||||
} else if ("max_word_len".equals(currentFieldName)) {
|
} else if ("max_word_len".equals(currentFieldName)) {
|
||||||
mltQuery.setMaxWordLen(jp.getIntValue());
|
mltQuery.setMaxWordLen(jp.getIntValue());
|
||||||
} else if ("boost_terms".equals(currentFieldName)) {
|
} else if ("boost_term".equals(currentFieldName)) {
|
||||||
mltQuery.setBoostTerms(jp.getIntValue() != 0);
|
mltQuery.setBoostTerms(true);
|
||||||
} else if ("boost_term_factor".equals(currentFieldName)) {
|
|
||||||
mltQuery.setBoostTermsFactor(jp.getIntValue());
|
mltQuery.setBoostTermsFactor(jp.getIntValue());
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(jp.getIntValue());
|
mltQuery.setPercentTermsToMatch(jp.getIntValue());
|
||||||
@ -116,7 +113,8 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
|
|||||||
mltQuery.setBoost(jp.getIntValue());
|
mltQuery.setBoost(jp.getIntValue());
|
||||||
}
|
}
|
||||||
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
|
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
|
||||||
if ("boost_terms_factor".equals(currentFieldName)) {
|
if ("boost_terms".equals(currentFieldName)) {
|
||||||
|
mltQuery.setBoostTerms(true);
|
||||||
mltQuery.setBoostTermsFactor(jp.getFloatValue());
|
mltQuery.setBoostTermsFactor(jp.getFloatValue());
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
|
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
|
||||||
|
@ -43,8 +43,7 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
private int maxDocFreq = -1;
|
private int maxDocFreq = -1;
|
||||||
private int minWordLen = -1;
|
private int minWordLen = -1;
|
||||||
private int maxWordLen = -1;
|
private int maxWordLen = -1;
|
||||||
private Boolean boostTerms = null;
|
private float boostTerms = -1;
|
||||||
private float boostTermsFactor = -1;
|
|
||||||
private float boost = -1;
|
private float boost = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,20 +144,11 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether to boost terms in query based on "score" or not. Defaults to
|
|
||||||
* <tt>false</tt>.
|
|
||||||
*/
|
|
||||||
public MoreLikeThisJsonQueryBuilder boostTerms(boolean boostTerms) {
|
|
||||||
this.boostTerms = boostTerms;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
* Sets the boost factor to use when boosting terms. Defaults to <tt>1</tt>.
|
||||||
*/
|
*/
|
||||||
public MoreLikeThisJsonQueryBuilder boostTermsFactor(float boostTermsFactor) {
|
public MoreLikeThisJsonQueryBuilder boostTerms(float boostTerms) {
|
||||||
this.boostTermsFactor = boostTermsFactor;
|
this.boostTerms = boostTerms;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,12 +198,9 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
|
|||||||
if (maxWordLen != -1) {
|
if (maxWordLen != -1) {
|
||||||
builder.field("max_word_len", maxWordLen);
|
builder.field("max_word_len", maxWordLen);
|
||||||
}
|
}
|
||||||
if (boostTerms != null) {
|
if (boostTerms != -1) {
|
||||||
builder.field("boost_terms", boostTerms);
|
builder.field("boost_terms", boostTerms);
|
||||||
}
|
}
|
||||||
if (boostTermsFactor != -1) {
|
|
||||||
builder.field("boost_terms_factor", boostTermsFactor);
|
|
||||||
}
|
|
||||||
if (boost != -1) {
|
if (boost != -1) {
|
||||||
builder.field("boost", boost);
|
builder.field("boost", boost);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import org.elasticsearch.index.Index;
|
|||||||
import org.elasticsearch.index.mapper.AllFieldMapper;
|
import org.elasticsearch.index.mapper.AllFieldMapper;
|
||||||
import org.elasticsearch.index.query.QueryParsingException;
|
import org.elasticsearch.index.query.QueryParsingException;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
import org.elasticsearch.util.Booleans;
|
|
||||||
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
|
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
|
||||||
import org.elasticsearch.util.settings.Settings;
|
import org.elasticsearch.util.settings.Settings;
|
||||||
|
|
||||||
@ -81,8 +80,7 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
|
|||||||
} else if ("max_word_len".equals(currentFieldName)) {
|
} else if ("max_word_len".equals(currentFieldName)) {
|
||||||
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
|
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
|
||||||
} else if ("boost_terms".equals(currentFieldName)) {
|
} else if ("boost_terms".equals(currentFieldName)) {
|
||||||
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
|
mltQuery.setBoostTerms(true);
|
||||||
} else if ("boost_terms_factor".equals(currentFieldName)) {
|
|
||||||
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
|
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
|
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
|
||||||
@ -101,8 +99,7 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
|
|||||||
} else if ("max_word_len".equals(currentFieldName)) {
|
} else if ("max_word_len".equals(currentFieldName)) {
|
||||||
mltQuery.setMaxWordLen(jp.getIntValue());
|
mltQuery.setMaxWordLen(jp.getIntValue());
|
||||||
} else if ("boost_terms".equals(currentFieldName)) {
|
} else if ("boost_terms".equals(currentFieldName)) {
|
||||||
mltQuery.setBoostTerms(jp.getIntValue() != 0);
|
mltQuery.setBoostTerms(true);
|
||||||
} else if ("boost_terms_factor".equals(currentFieldName)) {
|
|
||||||
mltQuery.setBoostTermsFactor(jp.getIntValue());
|
mltQuery.setBoostTermsFactor(jp.getIntValue());
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(jp.getIntValue());
|
mltQuery.setPercentTermsToMatch(jp.getIntValue());
|
||||||
@ -110,7 +107,8 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
|
|||||||
mltQuery.setBoost(jp.getIntValue());
|
mltQuery.setBoost(jp.getIntValue());
|
||||||
}
|
}
|
||||||
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
|
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
|
||||||
if ("boost_terms_factor".equals(currentFieldName)) {
|
if ("boost_terms".equals(currentFieldName)) {
|
||||||
|
mltQuery.setBoostTerms(true);
|
||||||
mltQuery.setBoostTermsFactor(jp.getFloatValue());
|
mltQuery.setBoostTermsFactor(jp.getFloatValue());
|
||||||
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
} else if ("percent_terms_to_match".equals(currentFieldName)) {
|
||||||
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
|
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
|
||||||
|
@ -61,8 +61,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
|
|||||||
mltRequest.maxDocFreq(request.paramAsInt("max_doc_freq", -1));
|
mltRequest.maxDocFreq(request.paramAsInt("max_doc_freq", -1));
|
||||||
mltRequest.minWordLen(request.paramAsInt("min_word_len", -1));
|
mltRequest.minWordLen(request.paramAsInt("min_word_len", -1));
|
||||||
mltRequest.maxWordLen(request.paramAsInt("max_word_len", -1));
|
mltRequest.maxWordLen(request.paramAsInt("max_word_len", -1));
|
||||||
mltRequest.boostTerms(request.paramAsBoolean("boost_terms", null));
|
mltRequest.boostTerms(request.paramAsFloat("boost_terms", -1));
|
||||||
mltRequest.boostTermsFactor(request.paramAsFloat("boost_terms_factor", -1));
|
|
||||||
|
|
||||||
mltRequest.searchType(parseSearchType(request.param("search_type")));
|
mltRequest.searchType(parseSearchType(request.param("search_type")));
|
||||||
mltRequest.searchIndices(request.paramAsStringArray("search_indices", null));
|
mltRequest.searchIndices(request.paramAsStringArray("search_indices", null));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user