API Change: moreLikeThis, closes #109.

This commit is contained in:
kimchy 2010-04-04 23:36:52 +03:00
parent 52f193c849
commit 2d6c2d8586
7 changed files with 25 additions and 82 deletions

View File

@ -65,8 +65,7 @@ public class MoreLikeThisRequest implements ActionRequest {
private int maxDocFreq = -1;
private int minWordLen = -1;
private int maxWordLen = -1;
private Boolean boostTerms = null;
private float boostTermsFactor = -1;
private float boostTerms = -1;
private SearchType searchType = SearchType.DEFAULT;
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;
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;
}
/**
* 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
* more like this documents.
@ -483,10 +467,7 @@ public class MoreLikeThisRequest implements ActionRequest {
maxDocFreq = in.readVInt();
minWordLen = in.readVInt();
maxWordLen = in.readVInt();
if (in.readBoolean()) {
boostTerms = in.readBoolean();
}
boostTermsFactor = in.readFloat();
boostTerms = in.readFloat();
searchType = SearchType.fromId(in.readByte());
if (in.readBoolean()) {
searchQueryHint = in.readUTF();
@ -553,13 +534,7 @@ public class MoreLikeThisRequest implements ActionRequest {
out.writeVInt(maxDocFreq);
out.writeVInt(minWordLen);
out.writeVInt(maxWordLen);
if (boostTerms == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeBoolean(boostTerms);
}
out.writeFloat(boostTermsFactor);
out.writeFloat(boostTerms);
out.writeByte(searchType.id());
if (searchQueryHint == null) {

View File

@ -222,7 +222,6 @@ public class TransportMoreLikeThisAction extends BaseAction<MoreLikeThisRequest,
.likeText(likeText)
.percentTermsToMatch(request.percentTermsToMatch())
.boostTerms(request.boostTerms())
.boostTermsFactor(request.boostTermsFactor())
.minDocFreq(request.minDocFreq())
.maxDocFreq(request.maxDocFreq())
.minWordLen(request.minWordLen())

View File

@ -42,8 +42,7 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
private int maxDocFreq = -1;
private int minWordLen = -1;
private int maxWordLen = -1;
private Boolean boostTerms = null;
private float boostTermsFactor = -1;
private float boostTerms = -1;
private float boost = -1;
/**
@ -137,20 +136,11 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
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>.
*/
public MoreLikeThisFieldJsonQueryBuilder boostTermsFactor(float boostTermsFactor) {
this.boostTermsFactor = boostTermsFactor;
public MoreLikeThisFieldJsonQueryBuilder boostTerms(float boostTerms) {
this.boostTerms = boostTerms;
return this;
}
@ -194,12 +184,9 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
if (maxWordLen != -1) {
builder.field("max_word_len", maxWordLen);
}
if (boostTerms != null) {
if (boostTerms != -1) {
builder.field("boost_terms", boostTerms);
}
if (boostTermsFactor != -1) {
builder.field("boost_terms_factor", boostTermsFactor);
}
if (boost != -1) {
builder.field("boost", boost);
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.util.settings.Settings;
@ -87,8 +86,7 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
} else if ("max_word_len".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boost_terms".equals(currentFieldName)) {
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
} else if ("boost_terms_factor".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
@ -106,9 +104,8 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
mltQuery.setMinWordLen(jp.getIntValue());
} else if ("max_word_len".equals(currentFieldName)) {
mltQuery.setMaxWordLen(jp.getIntValue());
} else if ("boost_terms".equals(currentFieldName)) {
mltQuery.setBoostTerms(jp.getIntValue() != 0);
} else if ("boost_term_factor".equals(currentFieldName)) {
} else if ("boost_term".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
@ -116,7 +113,8 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
mltQuery.setBoost(jp.getIntValue());
}
} 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());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());

View File

@ -43,8 +43,7 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
private int maxDocFreq = -1;
private int minWordLen = -1;
private int maxWordLen = -1;
private Boolean boostTerms = null;
private float boostTermsFactor = -1;
private float boostTerms = -1;
private float boost = -1;
/**
@ -145,20 +144,11 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
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>.
*/
public MoreLikeThisJsonQueryBuilder boostTermsFactor(float boostTermsFactor) {
this.boostTermsFactor = boostTermsFactor;
public MoreLikeThisJsonQueryBuilder boostTerms(float boostTerms) {
this.boostTerms = boostTerms;
return this;
}
@ -208,12 +198,9 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
if (maxWordLen != -1) {
builder.field("max_word_len", maxWordLen);
}
if (boostTerms != null) {
if (boostTerms != -1) {
builder.field("boost_terms", boostTerms);
}
if (boostTermsFactor != -1) {
builder.field("boost_terms_factor", boostTermsFactor);
}
if (boost != -1) {
builder.field("boost", boost);
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.AllFieldMapper;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.util.settings.Settings;
@ -81,8 +80,7 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
} else if ("max_word_len".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boost_terms".equals(currentFieldName)) {
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
} else if ("boost_terms_factor".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
@ -101,8 +99,7 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
} else if ("max_word_len".equals(currentFieldName)) {
mltQuery.setMaxWordLen(jp.getIntValue());
} else if ("boost_terms".equals(currentFieldName)) {
mltQuery.setBoostTerms(jp.getIntValue() != 0);
} else if ("boost_terms_factor".equals(currentFieldName)) {
mltQuery.setBoostTerms(true);
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
@ -110,7 +107,8 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
mltQuery.setBoost(jp.getIntValue());
}
} 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());
} else if ("percent_terms_to_match".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());

View File

@ -61,8 +61,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
mltRequest.maxDocFreq(request.paramAsInt("max_doc_freq", -1));
mltRequest.minWordLen(request.paramAsInt("min_word_len", -1));
mltRequest.maxWordLen(request.paramAsInt("max_word_len", -1));
mltRequest.boostTerms(request.paramAsBoolean("boost_terms", null));
mltRequest.boostTermsFactor(request.paramAsFloat("boost_terms_factor", -1));
mltRequest.boostTerms(request.paramAsFloat("boost_terms", -1));
mltRequest.searchType(parseSearchType(request.param("search_type")));
mltRequest.searchIndices(request.paramAsStringArray("search_indices", null));