GithubHelp home page GithubHelp logo

Comments (4)

karakhanyans avatar karakhanyans commented on July 21, 2024

Hi @robjbrain,
The search method is not accepting an array, it accepts a search query string.

So you should use this as following: Post::search($searchTerm)->orderBy('created_at', 'asc');

If you have any further questions, please let us know.

from laravel-scout-typesense-driver.

karakhanyans avatar karakhanyans commented on July 21, 2024

Hi @robjbrain, have you tried the solution that we suggested? Do you have any other problems using the drivers?

from laravel-scout-typesense-driver.

robjbrain avatar robjbrain commented on July 21, 2024

Hey sorry not replying sooner. I realised later that you're reliant on Scout to only accept a string, but that this is pretty limiting.

The orderBy syntax isn't documented in the readme for this package. A quick test shows it's working.

However at the moment i'm exclusively using the driver using "SearchMulti" to allow more advanced search.

e.g.

            $filter = ['status:=enabled'];
            if ($forumId = $request->input('forum_id')) {
                $filter[] = 'forum_id:='.$forumId;
            }

            $rawResults = Topic::search('')->searchMulti(
                [
                    [
                        'collection' => 'content',
                        'q' => $searchTerm,
                        'sort_by' => '_text_match:desc,created_at:desc',
                        'per_page' => 30,
                        'filter_by' => implode(' && ', $filter)
                    ]
                ]
            ))->raw();

            $ids = Arr::pluck(data_get($rawResults, 'results.0.hits', []), 'document.id');
            
            if ($ids) {
                $results = Topic::query()
                    ->find($ids)
                    ->sortBy(function(ContentItem $item) use ($ids) {
                        return array_search($item->getKey(), $ids);
                    });
            } else {
                $results = collect();
            }

If there isn't a better way of doing the above i'd be all ears. But it's not clear from your docs. It does feel like a very dirty hack though.

from laravel-scout-typesense-driver.

karakhanyans avatar karakhanyans commented on July 21, 2024

@robjbrain you can rewrite it like this


$results = Topic::search($searchTerm)
            ->where('status', 'enabled')
            ->where('forum_id', $request->input('forum_id'))
            ->orderBy('created_at', 'desc')
            ->paginate(30);

from laravel-scout-typesense-driver.

Related Issues (20)

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.