Code Monkey home page Code Monkey logo

lumen-xunsearch's Introduction

Lumen XunSearch

Xunsearch Engine for Laravel Scout.

Installation

You can install the package via composer:

composer require liugj/lumen-xunsearch

You must add the Scout service provider and the package service provider in your bootstrap/app.php line 80 config:

$app->register(Liugj\Xunsearch\XunsearchServiceProvider::class);

Configuration

Publish the config file into your project by edit config/scout.php line 62:

    'xunsearch' => [
        'index'  => env('XUNSEARCH_INDEX_HOST', ''),
        'search' => env('XUNSEARCH_SEARCH_HOST', ''),
        'schema' => [
           'brand_index'=>app()->basePath()  .'/'. env('XUNSEARCH_SCHEMA_BRAND'),
        ]
    ],

Add Xunsearch settings into .env file:

SCOUT_DRIVER=xunsearch
XUNSEARCH_INDEX_HOST=127.0.0.1:8383
XUNSEARCH_SEARCH_HOST=127.0.0.1:8384
XUNSEARCH_SCHEMA_BRAND=config/brand.ini

Usage

Now you can use Laravel Scout as described in the official documentation.

Where Clauses

This enginge allows you to add more advanced "where" clauses.

  • addRange
   $users = App\User::search('Star Trek')
            ->where('age', new \Liugj\Xunsearch\Operators\RangeOperator(30,50))->get();
  • setCollapse
   $users = App\User::search('Star Trek')
            ->where('city', new \Liugj\Xunsearch\Operators\CollapseOperator($num = 10))->get();
  • setFuzzy
   $users = App\Users::search('Star Trek')
           ->where('**', new \Liugj\Xunsearch\Operators\FuzzyOperator($fuzzy = false))->get();
  • setFacets
   $users = App\Users::search('Star Trek')
            ->where('***', new \Liugj\Xunsearch\Operators\FacetsOperator(array('age','city')))->get();
  • addWeight
   $users = App\User::search('Star Trek')
   ->where('country', new \Liugj\Xunsearch\Operators\WeightOperator('US'))->get();

Configuring Searchable Data

By default, the entire toArray form of a given model will be persisted to its search index. If you would like to customize the data that is synchronized to the search index, you may override the toSearchableArray method on the model:

<?php

namespace App;

use Liugj\Xunsearch\Searchable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Searchable;

    /**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {
        $array = $this->toArray();

        // Customize array...

        return $array;
    }
}

##Links

Credits

License

The MIT License (MIT).

lumen-xunsearch's People

Contributors

liugj avatar qinjianbo avatar

Watchers

James Cloos avatar  avatar

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.