Giter Club home page Giter Club logo

larasearch's Introduction

Introduction

Larasearch is a Laravel package that aims to seamlessly integrate Elasticsearch functionality with the Eloquent ORM.

Features

  • Plug 'n Play searching functionality for Eloquent models
  • Automatic creation/indexing based on Eloquent model properties and relations
  • Aggregations, Suggestions, Autocomplete, Highlighting, etc. It's all there!
  • Load Eloquent models based on Elasticsearch queries
  • Automatic reindexing on updates of (related) Eloquent models

Installation

Laravel 5

NB: This is preliminary support. When L5 compatibility is stable I will tag it with a version.

Add Larasearch to your composer.json file:

"iverberk/larasearch": "dev-L5"

Add the service provider to your Laravel application config:

'Iverberk\Larasearch\LarasearchServiceProvider'

Laravel 4

Add Larasearch to your composer.json file:

"iverberk/larasearch": "0.8.0"

Add the service provider to your Laravel application config:

'Iverberk\Larasearch\LarasearchServiceProvider'

Wiki

Please see the Github wiki for the most up-to-date documentation.

Changelog

All releases are tracked and documented in the changelog.

Credits

This package is very much inspired by these excellent packages that already exist for the Ruby/Rails ecosystem.

A lot of their ideas have been reused to work within a PHP/Laravel environment.

larasearch's People

Contributors

iverberk avatar menthol avatar myselfhimself avatar nuzelac avatar skeezerx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

larasearch's Issues

Error during BulkImport

So I'm running into a strange error I haven't seen before. I re-added var_dump($errorItems) to the ImportException class and below is what I got during bulk import error:

[624]=>
  array(1) {
    ["index"]=>
    array(5) {
      ["_index"]=>
      string(20) "games_20141227034103"
      ["_type"]=>
      string(4) "game"
      ["_id"]=>
      string(4) "4958"
      ["status"]=>
      int(404)
      ["error"]=>
      string(61) "IndexShardMissingException[[games_20141227034103][0] missing]"
    }
  }

BadMethodCallException with Laravel 5

I'm excited to start using this package as it looks awesome! I've followed the instructions in the wiki (https://github.com/iverberk/larasearch/wiki/Introduction) and my composer file has installed the latest version ("iverberk/larasearch": "0.8.*"), but when I include the 'Iverberk\Larasearch\LarasearchServiceProvider' in app.php, I get the following error:

"BadMethodCallException in ServiceProvider.php line 226: Call to undefined method [package]"

Any suggestions?

Also, the Readme.md file still says to use "iverberk/larasearch": "0.6.*" in the installation section.

Include callable trait

Yes but i can't include both

class User extends SentryUserModel {
   use Iverberk\Larasearch\Traits\CallableTrait;
   use Iverberk\Larasearch\Traits\SearchableTrait;

i get error

Trait method bootCallableTrait has not been applied, because there are collisions with other trait methods on User

Always need to connect to elasticsearch?

Hi,

First of all, I want to thank you for this great package. I am new to Laravel and Elasticsearch, it helps me a lot.

It works great with my app, but I got the error below when I am not connecting to elasticsearch service, could you please help?

{"error":{"type":"Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost","message":"Failed to connect to localhost port 9200: Connection refused","file":"Myapplication Root Directory\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\AbstractConnection.php","line":308}}

I know the error happended because my app cannot connect to elasticsearch service, but I do not want to connect to elasticsearch when login or other actions (no need to connect to elasticsearch), I only want to connect to elasticsearch when search. Could you please tell me is there anything I can do this?

I come from China, sorry for my poor English, if you do not know what I mean exactly, please let me know.

Thanks a lot!

Happy New Year!

Lee

The plugin isn't auto indexing

Hello , i had this issue for the start of using the plugin , i had to do a cron to index the tables but it consume a lot of resources .

the steps i followed are :

  • installing , add SearchableTrait to the model , add paths using --dir and it works with more than 30 models with the relations and everything ,

i think those are the steps please tell me if i forgot one .

Thank you

Bug with default getEsId() implementation in Proxy class

In the commit 58de9bd
you use $this->config['model']->idto get the current id of the current model instance.

$this->config['model'] is a empty model ! So you can't use it to get current model values.

public static function getProxy()
    {
        if ( ! static::$__es_proxy)
        {
            $instance = new static; # <<<<<< Empty model instance

            if ($instance instanceof Model)
            {
                static::$__es_proxy = App::make('iverberk.larasearch.proxy', $instance); # <<<<<< used to create the proxy instance

                return static::$__es_proxy;
            }
            else
            {
                throw new \Exception("This trait can ony be used in Eloquent models.");
            }
        }

        return static::$__es_proxy;
    }

I think getEsId() should be moved into SearchableTrait and be implemented as :

    public function getEsId()
    {
        return $this->getKey();
    }

SQL Syntax Error on 0 results

Hey there,

I believe I am having the same issue that was mentioned [https://github.com//issues/27], but I don't see a way to fix my problems. I am receiving the following error on the submission of a search query and returning 0 results

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 (SQL: select * from gameswhereid in ())

I am using the following code in my controller to pull the search results

$search = Request::query('search');
$games = Game::search($search)->getRecords();

With my model looking like this...

class Game extends Eloquent {

    use Iverberk\Larasearch\Traits\SearchableTrait;

Should I have something in place to stop the error after 0 results? I have an @if blade statement on the view page, but it never processes through to display the error.

Deleting a model record with "shouldIndex = false" shows errors

Hi,

Thanks for this great module, nice job!

I have a model with "use Iverberk\Larasearch\Traits\SearchableTrait;" and "shouldIndex always returns false". When I want to delete a model record, the record is deleted, but it shows some errors related to Elasticsearch like this:
{"error":{"type":"Elasticsearch\Common\Exceptions\Missing404Exception","message":"{"found":false,"_index":"model_20150318093910","_type":"model","_id":"15","_version":1}","file":"C:\xampp\htdocs\my_project\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\GuzzleConnection.php","line":260}}

I guess it is related to "index" thing, I reindex this model with a crontab command every 2 minutes, if the record is indexed, the deleting works great while if the record is not indexed, the deleting works just as I descriped above.

The reason why I don't use the "auto-reindex" and make "shouldIndex always returns false" is that I cannot make sure the elasticsearch is always connected, when I make it "auto-index" and the elasticsearch is not connected, my app will be not working anymore. Everything related to the model will not be working(e.g. I have a User model with "use Iverberk\Larasearch\Traits\SearchableTrait;", when the elasticsearch service is down, I cannot even login to my app, so I have to add "shouldIndex always returns false")

Is there any advices for this situation? Thanks a lot!
If you don't understand the description, leave a comment to let me know.

Again, thanks a lot for this great module and your hard work.

Auto index base model

I want to reindex User model when i update user for example

This is my User model

class User extends SentryUserModel {

  use Iverberk\Larasearch\Traits\SearchableTrait;

How to get auto reindex?

Issue appear when i use the custom search with json

Hello Guys ,

I had this issue for 2 days and i still can't figure out the issue , if anyone had any idea it will great

the issue is this

{"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[ez2RjvQjSGK423_AfwIYaw][news_20150224174544][0]: SearchParseException[[news_20150224174544][0]: from[0],size[50]: Parse Failure [Failed to parse source [{\"size\":50,\"from\":0,\"query\":{\"filtered\":{\"filter\":{\"nested\":{\"filter\":{\"bool\":{\"should\":[{\"term\":{\"author.id\":\"mlDelhwO8IfeGFqdXqFNWTgwLKcSwiNo\"}},{\"term\":{\"tags.id\":null}},{\"range\":{\"published_at\":{\"gte\":null,\"lte\":\"2015-02-24 19:52:11\"}}}]}}}}}}}]]]; nested: QueryParsingException[[news_20150224174544] No field specified for term filter]; }]","status":400}

the query is like this

$contents = News::search(null, ['json' =>
            ['query' =>
                ['filtered' =>
                    ['filter' =>
                        ['nested' =>
                            ['filter' =>
                                ['bool' =>
                                    ['should' => [
                                        ['term' => [
                                            'author.id' => (Input::has('author')) ? Input::get('author') : null]
                                        ],
                                        ['term' => [
                                            'tags.id' => (Input::has('tag')) ? Input::get('tag') : null]
                                        ],
                                        ['range' => [
                                            'published_at' => [
                                                "gte" => (Input::has('db')) ? Input::get('db') : null,
                                                "lte" => (Input::has('de')) ? Input::get('de') : Carbon::now()->toDateTimeString()]
                                        ]]
                                    ]]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]);

How to index a model instance upon change?

Is it possible to reindex a model instance (eg a User) by the time it is changed in the database?

If it is not doable with larasearch how would you suggest it to be done?

Nested Mappings [ErrorException] Undefined index: index

I have this error I cant fix with nested Mappings when we have a json column in PostgreSQL with nested mappings

I have this json [{"open":6420,"close":6810},{"open":6870,"close":7080}] stored in postgres but it wont create the index based on this mapping at config.php

'mappings' => [
'testtable' => [
'properties' => [
'open_hours' => ['type' => 'nested',
'properties' => [
'open' => ['type' => 'integer'],
'close' => ['type' => 'integer']
]
]
]
]
]

Document larasearch/config.php's analyzer => larasearch_{analyzer}_index correspondance

Hello,

it would be nice to write in README.md and config.php how analyzers configuration (name <=> implementation) works. Namely, that analyzers listed with a short name in config.php's elasticsearch.analyzers array, have their corresponding definition in elasticsearch.defaults.index.settings.analysis.analyzer.larasearch_{analyzer name}_index entries.

This would help people creating their own analyzers and understand what's corresponding to the analyzers short names they may write in the public $__es_config; array.

I have spent maybe 2 hours before finding that out... : /

Though, the lib is cool thanks!

Failed to connect to localhost port 9200: Connection refused

Hi guys,

congrats on this package, it seems very easy to use and ultra fun. I do have one problem though - . when I try to reindex or search, I always get the following error:

Failed to connect to localhost port 9200: Connection refused

I searched for 2-3 hours yesterday, but i didn't find a solution. Should I install something else as well? Do i have to do some extra configuration somewhere in order for the package to kick in and work?

Hoping you guys could help. :)

P.S. I'm using WAMP on Windows

Stable?

Hi,
this project looks really really great.
I don't want to rush anything, however, do you have ANY idea when this will be mostly stable?
Anything specific i can do to help?

Only flag Model for reindex when certain fields change versus when any do

So I have my User model indexed with Larasearch, and I'm having issues where during a login process because of how several things are changed, each time triggering a different "save" it causes on average 7-8 reindex Queue jobs for that User record. Even though nothing important or that I'm indexing changed.

How would you suggest going about limiting the Observer to only flag something for reindex if certain fields had changed? I thought perhaps using self::updating() instead but that would be triggered the every time as well.

Question about boosted fields in Multi Match Query

Hi Ivo,

Is it possible to apply boost on Individual fields with the caret (^) notation?
Like this sample:

{
  "multi_match" : {
    "query" : "this is a test",
    "fields" : [ "subject^3", "message" ] 
  }
}

Source: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#CO47-1

If it's possible, how to do this with your package?
Something like this?

$results = Wife::search('multi_match', [
    'query' => 'Lisa',
    'fields' => ['firstname^3', 'lastname']
])->getResults();

The firstname field is three times as important as the lastname field.

Cheers,
Tortue Torche

Error in raw JSON request

Hi iverberk,

Thanks for this great package so far!
I have been playing around with larasearch for a few days now but I can't get it to work.

The following function is working properly:

Product::search('jeans', ['fields' => ['name', 'description']])->getResults();

However when I want to pass a JSON query into the function as you mentioned in the Wiki like this:

Product::search(null, ['json' => '{"query": {"match": {"name": "jeans"}}}'])->getResults();

I am getting the following error:

array_merge(): Argument #2 is not an array

OK, so I change the query so that the second argument is an array:

Product::search(null, ['json' => ['{"query": {"match": {"name": "jeans"}}}']])->getResults();

In the end it will give me the following error which I can't get fixed:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[_klSaIzLSqm7nU3ABgL-bw][products_20150107005106][0]: SearchParseException[[products_20150107005106][0]: from[0],size[50]: Parse Failure [Failed to parse source [{\"size\":50,\"from\":0,\"0\":\"{\\\"query\\\": {\\\"match\\\": {\\\"name\\\": \\\"jeans\\\"}}}\"}]]]; nested: SearchParseException[[products_20150107005106][0]: from[0],size[50]: Parse Failure [No parser for element [0]]]; }]","status":400}

I also tried the searchByQuery($query) method as you mentioned in the wiki but it seems like this method does not exist.

Thanks!

How to sort case insensitive

I know by default ElasticSearch does this sorting where uppercase characters will come first no matter what and that an analyzer with a lowercase filter could/should be used...But I'm trying to figure out how to do this with Larasearch. I see a bunch of custom analyzers defined in the config, but I'm not sure how to apply them. Specifically for case insensitive sorting.

I couldn't find anything here in the wiki, any ideas? Thanks.

Exclude field(s) from the indexing.

Hello,

Is there a way to exclude field(s) from indexing. I got already running database that I would like to index but there is a problem. I get a lot of exceptions from one of the fields while trying to reindex it using
php artisian larasearch:reindex -v Model.
The exceptions are different but the they are on one field.
How to exclude it?

Allow ES key to be configured

The _id in ElasticSearch is going to be the Model's id/primary key. This is typically going to be a simple integer from MySQL, Postgres, whatever.

https://github.com/iverberk/larasearch/blob/develop/src/Iverberk/Larasearch/Index.php#L91

This puts all documents in ElasticSearch into a single shard which is problematic for scaling ElasticSearch. Up until the shard limit at least.

For example, I now have over 900 documents on a single shard. However, if I were using a hash of some sort, it would be split among several shards. My application has another field that contains a GUID and when I had previously created indexes in ElasticSearch I used that for the _id which resulted in even just 20 documented being distributed more evenly across 4 or 5 shards.

It would be nice to allow a different field to be used for the _id`` value instead of using$model->id``` ... And/or allow some sort of hashing strategy to be applied to the model id so that we can better control how the documents get indexed in ElasticSearch.

php artisan larasearch:reindex Model --relations not working.

php artisan larasearch:reindex Model --relations not working,
when i wrote php artisan larasearch:paths Model --relations --write-config command its work properly but when i wrote php artisan larasearch:reindex Model --relations command
It gives error like below :
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::()

Thanks.

Mappings are not being set the right way

Hi iverberk,

After some hours struggling I found out that the mappings are not being set as they are supposed to.
I ran into this problem when I was trying to use the autocomplete and suggest search.

When indexing a model for the first time, it apparently does not set the right mappings when (auto)creating the index. For example, when is set the es_config variable in a searchable model:

public static $__es_config = [
    'autocomplete' => ['name'],
    'suggest' => ['name'],
    'word_start' => ['name']
];

It does not apply this config in the index mapping when it auto creates that index. When I first set the mapping on the index manually, it works though.

Also, the wiki gives the following example in order to do a suggestion search:

$results = Husband::search('query_string', ['fields' => ['name'], 'suggest' => true])->getResults();

$suggestions = $results->first()->getSuggestions(['name']);

However, I am getting a Call to undefined method Iverberk\Larasearch\Response\Results::getSuggestions(['name']) error.

This works though:

$results = Husband::search('query_string', ['fields' => ['name'], 'suggest' => true]);

$suggestions = $results->getSuggestions(['name']);

It would be nice to have a flat array with only the suggestions as response.

Question about more space tolerant annotations parsing

Hello,

Thank you very much for Larasearch which works very well for the few things we have been able to test till now. We have looked through the annotations parsing code in PathsCommand.php :

    protected function checkDocHints($docComment, $model)
    {
        // Check if we never follow this relation
        if (preg_match('/@follow NEVER/', $docComment)) return false;

        // Check if we follow the relation from the 'base' model
        if (preg_match_all('/@follow UNLESS ' . str_replace('\\', '\\\\', get_class($model)) . '\b/', $docComment, $matches))
        {
            return false;
        }
    protected function getRelatedModels(Model $model)
    {
// ...
                // Check if this method returns an Eloquent relation
                if ($method->class == $modelClass &&
                    stripos($method->getDocComment(), '@return \Illuminate\Database\Eloquent\Relations')
                )

All of the above string searches assume annotations and their following terms are single-space-separated. I have not been able to find PHPDocumentor specfication or code for that, though, do you not think that the annotations parsing should be refined to tolerate [\s]+ separators or such ?

Model paths with no relations cannot be reindexed

Hello,

When a Model has all its relations set to @follow NEVER, the generated php larasearch:paths Model --relations [--write-config] looks like:

{
    "paths": {
        "Model": [
          ""
        ]
    },
    "reversedPaths": [
            "Model": [
          ""
        ]
    ]

This results in this error when running php artisan larasearch:reindex Model --relations -v
` [BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::()

Exception trace:
() at /home/jd/Productions/JAP/jobaproximite/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2117
`

Here's a generated json paths that works :

{
    "paths": {
        "JobApplication": [

        ]
    },
    "reversedPaths": {
        "JobApplication": [

        ]
    }
}

I'll propose a pull request for this soon.

Polymorphic relationships

Is there support for polymorphic relationships? I see there is a check in PathsCommand for polymorphic relationships. However when I run the command on my model it doesn't get past line 159 as the related model is an instance of the ancestor.

I have

namespace App\Models;
use App\Models\Eloquent;
use Iverberk\Larasearch\Traits\SearchableTrait;
class QuoteRequest extends Eloquent
{
    use SearchableTrait;
    /**
     * @return \Illuminate\Database\Eloquent\Relations
     */
    public function details()
    {
        return $this->morphTo();
    }
}

and

namespace App\Models\QuoteRequest\Letting;
use App\Models\Eloquent;
use Iverberk\Larasearch\Traits\TransformableTrait;
use Iverberk\Larasearch\Traits\CallableTrait;
class Details extends Eloquent
{
    use TransformableTrait, CallableTrait;
    /**
     * @return \Illuminate\Database\Eloquent\Relations
     */
    public function quoterequest()
    {
        return $this->morphOne('App\Models\QuoteRequest', 'details');
    }

}

but the path command only returns

{
    "paths": {
        "App\\Models\\QuoteRequest": [

        ]
    },
    "reversedPaths": {
        "App\\Models\\QuoteRequest": [
            ""
        ]
    }
}

When Model::search'ing with param 'select', cannot toJson() results

Hello,

For a code such as the following, when the 'select' parameter is provided and there are actual results received :

        $searchByTerms = JobAd::search(
            'assistant',
            ['fields' => ['title', 'reference'], 'select' => ['title']]
        )->getResults();

... when trying to toJson() the results :

        return '<pre>' . $searchByTerms->toJson(JSON_PRETTY_PRINT) . '</pre>';

An exception is raised, because Larasearch\Response\Result->toArray() tries to look up a non-existent _source key on the first Result in $searchByTerms:

// Result.php
    public function toArray()
    { // _source key does not exist
        return $this->hit['_source'];
    }

Example Result object print_r'ed:

Iverberk\Larasearch\Response\Result Object
(
    [hit:Iverberk\Larasearch\Response\Result:private] => Array
        (
            [_index] => job_ads_20140925161627
            [_type] => job_ad
            [_id] => 125956
            [_score] => 1.382851
            [fields] => Array
                (
                    [title] => Array
                        (
                            [0] => Assistant(e) responsable opérationnel 
                        )

                )

        )

)

PHP Fatal error: Maximum function nesting level of '100' reached, aborting!

PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in /home/vagrant/code/elasticsearch/vendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.php on line 317

Hello i had this issue when i try to use Many to many relationship, i add SearchableTrait to both Models 'articles' and 'tags' when i add the articles to the path it works but when i try to add the tags it shows me this error " PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in /home/vagrant/code/elasticsearch/vendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.php on line 317 "

Reindexing: got Killed

Hi there, when i'm trying to reindex by command:

php artisan larasearch:reindex CGCase\\Models\\Objects --relations

and it showing this:

php artisan larasearch:reindex CGCase\\Models\\Objects --relations
---> Reindexing CGCase\Models\Objects
* Batch 1
Killed

I dont know what that means :(
Please help :(

Invalid Index Name Exception - Must be lowercase

The tables in my database are captilized, for example:

  • Users
  • Pages
  • Content
    etc..

When trying to index a model, I'm given this exception

[Elasticsearch\Common\Exceptions\BadRequest400Exception]
  {"error":"InvalidIndexNameException[[Content_20141211174202] Invalid index name [Content_20141211174202], must be lowercase]","status":400}

Is there currently a way that I can specify the index name to be lowercase?

Laravel 5.0 update possible?

I myself do not know what is needed to change in order for this to work within Laravel 5.0 but I would love to see it, I imagine it's a few method name changes or something not too much.

Response->getRecords() does not keep retrieved ids orders

Hello,

When adding an order param to ElasticSearch, the retrieved is most probably correctly orderer. However, larasearch's Response->getRecords() uses Eloquent's whereIn('id', $ids)->get() which does not care about ids order anymore.
Expected behaviour would be to return the records in the order as they are retrieved from ElasticSearch.

Here's a related LaravelSnippet that "could" fix it though larasearch is meant to be database-agnostic:
http://laravelsnippets.com/snippets/get-all-items-at-once-ordered-by-the-current-order-of-ids-in-the-where-in-clause-using-eloquent

I may later propose soon a patch providing a Response->getRecordsQuery() that yields an Eloquent Query Builder and allows for finer tuning before ->get()'ing results.

Add relations

Apologies for the noob question, but I can't get the reindex command to run correctly, I have a model that is called Sitemap, I can run the following with no problems:

    $ php artisan larasearch:paths Sitemap --relations

    {
        "paths": {
            "Sitemap": [
                "article"
            ]
        },
        "reversedPaths": {
            "Sitemap": [
                ""
            ],
            "Article": [
                "sitemap"
            ]
        }
    }

However, when I run:

    $ php artisan larasearch:reindex Sitemap --relations --dir=app/models

I get the following error:

    [ErrorException]
      Argument 1 passed to Illuminate\Database\Eloquent\Builder::parseRelations() must be of the type array, null given, call
      ed in /home/vagrant/cybercms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php on line 717 and defi
      ned

Any direction would be much appreciated, thanks.

Usage: combining queries

Hello,

Thank you again very much for the Larasearch library.

I would like to query for documents having altogether :

  • given keywords within a set of analyzed fields,
  • some_field = NN,
  • some_other_field = NN
  • .. etc.

The first bullet is doable natively by following the examples in README.md.

For combining with other bullets it does not seem so. Looking at Query->getPayload() which is one of Larasearch's last step before telling the ES PHP Client to search, it does not seem feasible for now to have more queries within the dismax handler than the existing series of lookup for $this->term within the given analyzed fields.

How is that possible to search for multiple terms in different fields in Larasearch ?

Bulk import with errors

I am performing a reindex of one of my models and I am receiving a "Bulk import with errors" exception. It will almost always stop at "Batch 1". But if I add --batch=2 then I can make it through 53 batches. I am still not adding all of my rows from the database though. Let me know what code you may want to see... Thanks!

Response's getRecords() yields exception on 0 hits

Hello,

After a SomeModel::search(), when there are 0 hits, an exception is raised when calling Response->getRecords() with the following details :

select * from `table_name` where `table_name`.`deleted_at` is null and `id` in ()
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 (SQL: select * from `table_name` where `table_name`.`deleted_at` is null and `id` in ())

Paths generation : recording non-relations methods

Hello,

We have some custom Eloquent Model methods that return a constraint'ed Relation, that is not a relation anymore. Would there be a way to allow methods returning an Eloquent object to be included in generated paths ?
Or if you know some magic to improve below defaultFinger() method so that it returns a Relation object, I'd be glad.

Example :

class Hand extends Eloquent {
    use \Iverberk\Larasearch\Traits\SearchableTrait;

/**
 * This won't appear in 'php artisan larasearch:paths', but can appear during indexing if transform() is overridden.
  @return \Eloquent
 */
public function defaultFinger()
{
        return $this->fingers()->where('default_finger', '=', '1')->first();
}

/**
* This will appear in 'php artisan larasearch:paths'
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function fingers()
{
// return hasMany(Finger);
}
}

Thanks for your great support !

Problem with understating the workflow of the package

First of all I would like to thank you for the great job you have made to make this project succeeded. I have some problems with understanding the workflow of the plugin so let me describe me the issues I faced:

I don't know How this package works. I tried to read the instructions many time but with no luck.
So let me discribe the problems wich I face and wish you help me.

I think that when I just integrate the package in my Laravel installation and adding the following line to my model use Iverberk\Larasearch\Traits\SearchableTrait and It will index all inserted /updated / deleted ... etc data to Elastic search automatically without any need to run the command php artisan larasearch:reindex [Model Name] every time but this doesn't happened. what actually happened is that I have to run the command every time to get the results using this method User::search('sana')->getResults(); .

I also facing a problem with this method that the query string should be the exact string I inserted before not a part from it for example so if I tried to search using the word san not sana it returns empty data.

I also can't understand what paths means and it's relation with Elastic search. I run the command php artisan larasearch:path [Model Name] it gives me an array I don't know What is this array is for.

Thanks

Question about pagination and custom index

Hello , first of all i want to thank you for this amazing package and the hard work you put into it , i want to ask you about the pagination and if its an option , because it always return 50 results , and if its possible to custom that to a higher number , and about the index if its is possible to be a custom index.

thank you again

ReflectionException

Hi there, i installed larasearch today and very excited, but when i run this command:

php artisan larasearch:paths Husband

i got this error:

[ReflectionException]
Class iverberk.larasearch.proxy does not exist

Please help

Issues I can't seem to figure out

Hello all!

So I've implemented Larasearch into my library hosted at www.gamejerks.net and I'm having issues. I have several different object types such as Reviews, Articles, Games, Videos and Users. I have no issue indexing and searching against all the types except for Games. Obviously that doesn't help anyone but what I'm trying to figure out is whether or not I can figure out what may be tripping up the artisan command to reindex because I receive the error:

[Iverberk\Larasearch\Exceptions\ImportException]
  Bulk import with errors

And I can't seem to figure out why. The model Game has 3,000 records so I can't really go through them and try it out, only thing I can think of is that the error occurs while it still reads "* Batch 1" so I'm assuming that means the problem is within the first 750 records that are being indexed.

Eloquent model pulls and paginate

I tried some variations to use getRecords with Eloquent and paginate, but I was unsuccessful. Has anyone tried to paginate search terms - whether through getRecords or getResults?

Feature request: larasearch:reindex & :paths discover all models

It would nice that both php artisan larasearch:reindex and php artisan larasearch:paths commands have a sort of --auto mode that makes models discovered from laravel's own top level models that have a SearchableTrait.
When developping with lots of models, it helps not having to list all models each time as command line arguments or having to write a script file.

shouldIndex() method in dev-develop and dev-master

Hi Iverberk,

I am using this great package to implement Elasticsearch in my Laravel project. I have a problem with the shouldIndex() method. It seems not to be used in the "dev-master" branch.

The "dev-master" branch
public function saved(Model $model)
{
Queue::push('Iverberk\Larasearch\Jobs\ReindexJob',$this->findAffectedModels($model));
}

The "dev-develop" branch
public function saved(Model $model)
{
if ($model::$__es_enable && $model->shouldIndex())
{
Queue::push('Iverberk\Larasearch\Jobs\ReindexJob', $this->findAffectedModels($model));
}
}

I need this method and I don't know what to do, because the "dev-develop" branch is not stable. Could you pls help?

restore() event does not reindex deleted Models

For soft-deletable Models, for now save() and delete() actions do update and delete related documents within Elastic Search. However, restore() does not recreate a document within Elastic Search.

Create '@follow ONLY {base model}' annotation for white listing model relations

Hello,

At this time, the @follow UNLESS SomeModel annotation, repeated 1 line per exclude model helps building a black list of paths.

Similarly, it would be nice for the indexing paths detection engine to understand a @follow ONLY SomeModel annotation (repeatable in a same PHPDoc for as many lines/models we want) for whitelisting models. In projects with many models, this would spare us from annotating many relation methods with @follow UNLESS when the black list is greater than the whitelist.

Items not reindexing

I have the searchable trait, i have everything indexed via the artisan command, working perfect.

But when i update an item, it doesn't get reindexed. Looking in the queue logs, the reindex is being run successfully, but yet it doesn't show the changes in elasticsearch.

I'm using dev-develop, since i had the same issue on dev-master.

Is there a way i can debug on why it isn't working?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.