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

will scout support mapping? #85

Closed
mehrdad-shokri opened this issue Oct 2, 2016 · 4 comments
Closed

will scout support mapping? #85

mehrdad-shokri opened this issue Oct 2, 2016 · 4 comments

Comments

@mehrdad-shokri
Copy link

What I want to do is to use language analyzers (https://www.elastic.co/guide/en/elasticsearch/guide/current/using-language-analyzers.html), but seems like scout doesn't support custom mapping between models and documents.
Is there any way I can accomplish this?

@Melcus
Copy link

Melcus commented Oct 16, 2016

I'm interested in this as well.

@toby1991
Copy link

as well too

@brino
Copy link
Contributor

brino commented Oct 27, 2016

There is no reason you couldn't overwrite the mapping with a custom one, or index settings for that matter. You just post them with a REST client to the elastic cluster directly. Then, index your data. Granted you're still somewhat limited, but the point is you can quickly accomplish this outside of scout without too much trouble. You could also make a console command to do this.

@mehrdad-shokri
Copy link
Author

mehrdad-shokri commented Oct 27, 2016

Actually, you can create you custom mapping with a curl command in your cluster, the import your data from scout via scout:import laravel scout will respect your mapping, but you need to override toSearchableArray to match with your custom mapping.
An example would be:

curl -XPUT 'localhost:9200/yourApp' -d '
{
  "settings":{
    "analysis":{
      "char_filter":{
        "zero_width_spaces":{
          "type":"mapping",
          "mappings":[
            "\\u200C=> "
          ]
        }
      },
      "filter":{
        "persian_stop":{
          "type":"stop",
          "stopwords":"_persian_"
        },
        "autocomplete_filter":{
          "type":"edge_ngram",
          "min_gram":1,
          "max_gram":20
        }
      },
      "analyzer":{
        "autocomple":{
          "type":"custom",
          "tokenizer":"standard",
          "char_filter":[
            "zero_width_spaces"
          ],
          "filter":[
            "autocomplete_filter",
            "lowercase",
            "arabic_normalization",
            "persian_normalization",
            "persian_stop"
          ]
        },
        "persian":{
          "type":"custom",
          "tokenizer":"standard",
          "char_filter":[
            "zero_width_spaces"
          ],
          "filter":[
            "lowercase",
            "arabic_normalization",
            "persian_normalization",
            "persian_stop"
          ]
        }
      }
    }
  },
  "mappings":{
    "places":{
      "properties":{
        "name":{
          "type":"string",
          "analyzer":"persian"
        },
        "name_suggest":{
          "type":"string",
          "analyzer":"autocomple"
        }
      }
    }
  }
}'

And your toSearchableArray would be like:

public function toSearchableArray()
    {
        $array = array("name" => $this->name, "name_suggest" => $this->name, $this->getKeyName() => $this->getKey());
        return $array;
    }

If you get any more problems, just mention me.

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

4 participants