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

Is there a score per result? #55

Closed
t2thec opened this issue Nov 25, 2016 · 3 comments
Closed

Is there a score per result? #55

t2thec opened this issue Nov 25, 2016 · 3 comments

Comments

@t2thec
Copy link

t2thec commented Nov 25, 2016

I LOVE this package. Thanks very much for putting it together.

I am using the Laravel driver and search multiple models in turn. I would like to then rank the results from all models by a score.

I presume from my digging around that this currently isn't possible? Or am I wrong?

One again, thanks for this. So simple and affective.

@fishgrind
Copy link

fishgrind commented Dec 13, 2016

@t2thec

there are some fields in the database that show this will be added. see answer here: #56

for now you could use the php similar_text function to add a weighting to the results array..

something like this:

foreach ($res['ids'] as $result) {

//fetch data for id from database here.

similar_text(strtolower($yourSearchQuery), strtolower($resultArray['arrayKeyToSort']), $percent);

//push data to array and include the $percent
}

After this you can sort the array using usort

@t2thec
Copy link
Author

t2thec commented Dec 14, 2016

Sweet. Thanks @fishgrind. Legendary work!

@t2thec t2thec closed this as completed Dec 14, 2016
@fishgrind
Copy link

fishgrind commented Dec 14, 2016

@t2thec no worries. Just remember similar_text is case sensitive hence the strtolower()

probably better and faster is using levenshtein() though see http://www.w3schools.com/php/func_string_levenshtein.asp

it4need added a commit to Duplexmedia/tntsearch that referenced this issue Jul 29, 2022
…ssibile to reorder result after multiple searches (see: teamtnt#55)
it4need added a commit to Duplexmedia/laravel-scout-tntsearch-driver that referenced this issue Jul 29, 2022
it4need added a commit to Duplexmedia/laravel-scout-tntsearch-driver that referenced this issue Jul 29, 2022
it4need added a commit to Duplexmedia/laravel-scout-tntsearch-driver that referenced this issue Jul 29, 2022
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

2 participants