All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.groupbyinc.api.model.AbstractRecord Maven / Gradle / Ivy

The newest version!
package com.groupbyinc.api.model;

import com.groupbyinc.common.jackson.annotation.JsonProperty;

import java.util.Map;

/**
 * 
 * A Record represents a result from the search engine.
 * Each record has all the requested metadata as
 * specified in fields parameter.  Each record also has several special fields.
 *
 * - `id`: an MD5 hash of the unique URL of this record.
 * - `url`: the unique url of the record.
 * - `snippet`: If there is a keyword match, the snippet of text.  Matches have <b> tags surrounding them.
 * - `title`: The title of the record.
 * - `allMeta`: a map of key value pairs.  If a value is multi-assign, there will additionally be a <key>List
 * item, with all the values.
 * 
 *
 * @author will
 * @internal
 */
public abstract class AbstractRecord> {
    @JsonProperty("_id")
    private String id;
    @JsonProperty("_u")
    private String url;
    @JsonProperty("_snippet")
    private String snippet;
    @JsonProperty("_t")
    private String title;
    private Map allMeta;

    /**
     * @return The ID is generated from URL of this record which means it will
     * persist across updates.
     */
    public String getId() {
        return id;
    }

    /**
     * @param id
     *         Set the id
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public T setId(String id) {
        this.id = id;
        return (T) this;
    }

    /**
     * 
     * This URL is generated by the data upload service and follows the format
     *
     *     http://1.com/.html
     * 
     *
     * @return The URL represents the Unique ID of the record.
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url
     *         Set the record url
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public T setUrl(String url) {
        this.url = url;
        return (T) this;
    }

    /**
     * @return If a search was performed this result object may have a snippet
     * of matching text.
     */
    public String getSnippet() {
        return snippet;
    }

    /**
     * @param snippet
     *         Set the snippet
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public T setSnippet(String snippet) {
        this.snippet = snippet;
        return (T) this;
    }

    /**
     * @param name
     *         Get a specific metadata value. Essentially this represents an
     *         attribute of the record data.
     *
     * @return
     */
    public Object getMetaValue(String name) {
        return allMeta.get(name);
    }

    /**
     * @return A map of all the metadata associated with this record.
     */
    public Map getAllMeta() {
        return allMeta;
    }

    /**
     * @param allMeta
     *         Set the metadata.
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public T setAllMeta(Map allMeta) {
        this.allMeta = allMeta;
        return (T) this;
    }

    /**
     * 
     * The title of this record
     * 
     *
     * @return The title of this record.
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title
     *         Set the title
     */
    @SuppressWarnings("unchecked")
    public T setTitle(String title) {
        this.title = title;
        return (T) this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy