use of org.apache.lucene.document.FeatureField in project BootForum by chipolaris.
the class IndexService method createDiscussionDocument.
/**
* utility method to create a Document based on Discussion entity
* @param discussion
* @return
*/
private Document createDiscussionDocument(Discussion discussion) {
Document document = new Document();
// store id as a String field
document.add(new StringField("id", discussion.getId() + "", Store.YES));
// also use id as a FeatureField to be factored in the scoring process during search
document.add(new FeatureField("features", "MoreRecent", discussion.getId()));
// use StoredField for attributes that do not get queried
document.add(new StoredField("createBy", discussion.getCreateBy()));
document.add(new StoredField("createDate", discussion.getCreateDate().getTime()));
// note: TextField vs. StringField: the former get tokenized while the later does not
document.add(new TextField("title", discussion.getTitle(), Store.YES));
document.add(new StringField("closed", String.valueOf(discussion.isClosed()), Store.YES));
for (Tag tag : discussion.getTags()) {
document.add(new StringField("tag", tag.getLabel(), Store.YES));
}
return document;
}
use of org.apache.lucene.document.FeatureField in project OpenSearch by opensearch-project.
the class RankFeatureFieldMapper method parseCreateField.
@Override
protected void parseCreateField(ParseContext context) throws IOException {
float value;
if (context.externalValueSet()) {
Object v = context.externalValue();
value = objectToFloat(v);
} else if (context.parser().currentToken() == Token.VALUE_NULL) {
// skip
return;
} else {
value = context.parser().floatValue();
}
if (context.doc().getByKey(name()) != null) {
throw new IllegalArgumentException("[rank_feature] fields do not support indexing multiple values for the same field [" + name() + "] in the same document");
}
if (positiveScoreImpact == false) {
value = 1 / value;
}
context.doc().addWithKey(name(), new FeatureField("_feature", name(), value));
}
Aggregations