Comments (4)
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.
Hi @robjbrain, have you tried the solution that we suggested? Do you have any other problems using the drivers?
from laravel-scout-typesense-driver.
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.
@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)
- Laravel 10 Support HOT 10
- Error from Typesense on Update of Model Instance which is not in index HOT 2
- PHP 8.2 deprecation warnings HOT 1
- Laravel Scout 10? HOT 1
- Error importing document: Field `itemStocks` not found. HOT 2
- "Undefined property: Laravel\\Scout\\Builder::$whereIns", HOT 1
- Filter in typesensne collection of objects in Laravel
- $model->unsearchable(); does not work HOT 7
- Import not working with array data. HOT 11
- Model update resets document auto-generated embeddings HOT 1
- Cannot index collection with a soft deleted first model when scout.soft_delete is true HOT 2
- Hotfix TypeError - Typesense\\Documents::import(): Argument #1 ($documents) must be of type string, array given. HOT 5
- Undefined property: Laravel\Scout\Builder::$whereIns HOT 1
- Passing "empty" values to search query results in "Parameter `q` is required"
- Please add possibility to use Laravel Scout Builder ->options() method
- Duplicate array keys in TypesenseEngine::buildSearchParams HOT 1
- Exception when searching large datasets for common query HOT 2
- Using Multi Search after merging to Laravel Scout HOT 2
- Typesense scout import fails in Laravel 11 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-scout-typesense-driver.