Search in sources :

Example 6 with FeatureField

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;
}
Also used : StoredField(org.apache.lucene.document.StoredField) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) Tag(com.github.chipolaris.bootforum.domain.Tag) Document(org.apache.lucene.document.Document) FeatureField(org.apache.lucene.document.FeatureField)

Example 7 with FeatureField

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));
}
Also used : FeatureField(org.apache.lucene.document.FeatureField)

Aggregations

FeatureField (org.apache.lucene.document.FeatureField)7 IndexableField (org.apache.lucene.index.IndexableField)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 TokenStream (org.apache.lucene.analysis.TokenStream)2 TermFrequencyAttribute (org.apache.lucene.analysis.tokenattributes.TermFrequencyAttribute)2 Document (org.apache.lucene.document.Document)2 StoredField (org.apache.lucene.document.StoredField)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 Query (org.apache.lucene.search.Query)2 TermQuery (org.apache.lucene.search.TermQuery)2 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)2 Strings (org.opensearch.common.Strings)2 List (org.opensearch.common.collect.List)2 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)2 Plugin (org.opensearch.plugins.Plugin)2 Tag (com.github.chipolaris.bootforum.domain.Tag)1 Source (net.htmlparser.jericho.Source)1