Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model extension for supporting highlight #74

Open
lucian-dragomir opened this issue Mar 7, 2018 · 0 comments
Open

model extension for supporting highlight #74

lucian-dragomir opened this issue Mar 7, 2018 · 0 comments

Comments

@lucian-dragomir
Copy link

lucian-dragomir commented Mar 7, 2018

Hi,

This is an improvement feature i find useful in case of needing highlight support for defined models. Do you plan to add such capability in the future?

For example a starting point could be to add in the Query->getAll/getFirst methods a mapping logic for the $row["highlight"] to some special attribute of the model (could be something like $model->highlight)
Example:


--added in Query->getAll method
    //highlight extension support in model
    $model->setHighlight($row["highlight"] ?? null);

--added in Query->getFirst method
    //highlight extension support in model
    $model->setHighlight($data[0]["highlight"] ?? null);

--added to Model
    protected $_highlight;
    public function setHighlight($highlight){
        $this->highlight = $highlight;
    } 
    
    public function hasHighlightAttribute($name)
    {
        return $this->highlight && array_key_exists($name, $this->highlight);
    }

    public function getHighlightAttribute($name, $position = null)
    {
        if ($this->hasHighlightAttribute($name)) {
            if (!is_null($position)) {
                return $this->highlight[$name][$position];
            }
            return $this->highlight[$name];
        }
        return null;
    }

This can be very usefull in cases you set using the model->Body method the highlight raw request (or later on you can add dedicated method for instructing the EL to return highlights) and using the new mapping (above) the highlight can be accessible via a model specific getter method.

Still the highlight internal attribute must be removed from serialization of the model when saving:

--added in Model->save method
$fields = array_except($this->attributes, ["_index", "_type", "_id", "_score", "highlight"]);

Thx,
Lucian

CyberDracula pushed a commit to CyberDracula/elasticsearch that referenced this issue Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant