olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

Sorting #67

Closed jbavington713 closed 8 years ago

jbavington713 commented 10 years ago

Hi!

I'm still learning so be gentle...

Is there a way to re-order or sort the results after a search?

I have a working implementation with some numeric data and I want to bring the largest values for a specific term to the top.

Any help would be really appreciated.

Thanks

olivernn commented 10 years ago

The results from search are sorted based on the relevance score, with the most relevant documents first. How do you want to sort the results? The results are returned as an array, so you can sort it however you want to.

jbavington713 commented 10 years ago

Thanks Oliver… I’ll keep the scoring as default but provide options to re-order the results by numerical significance (i.e. biggest number at the top) for four of the terms in my data set. I think I’ve found the code I need to play with (around scoring) so I’ll try the sort function there and see how I get on. Thanks again

From: Oliver Nightingale [mailto:notifications@github.com] Sent: 25 January 2014 12:10 To: olivernn/lunr.js Cc: James Bavington Subject: Re: [lunr.js] Sorting (#67)

The results from search are sorted based on the relevance score, with the most relevant documents first. How do you want to sort the results? The results are returned as an array, so you can sort it however you want to.

— Reply to this email directly or view it on GitHubhttps://github.com/olivernn/lunr.js/issues/67#issuecomment-33287517.


James Bavington Technical Sales Manager – Web Performance NCC Group Kings Court Kingston Road Leatherhead, KT22 7SL

Telephone: +44 1372 383874 Mobile: +44 7967 153048 Fax: +44 1372 383801 Website: www.nccgroup.comhttp://www.nccgroup.com Email: James.Bavington@nccgroup.commailto:James.Bavington@nccgroup.com [http://www.nccgroup.com/media/192418/nccgrouplogo.jpg] http://www.nccgroup.com/


This email is sent for and on behalf of NCC Group. NCC Group is the trading name of NCC Group Performance Testing Limited (Registered in England CRN: 4069379). Registered Office: Manchester Technology Centre, Oxford Road, Manchester, M1 7EF. The ultimate holding company is NCC Group plc (Registered in England CRN: 4627044).

Confidentiality: This e-mail contains proprietary information, some or all of which may be confidential and/or legally privileged. It is for the intended recipient only. If an addressing or transmission error has misdirected this e-mail, please notify the author by replying to this e-mail and then delete the original. If you are not the intended recipient you may not use, disclose, distribute, copy, print or rely on any information contained in this e-mail. You must not inform any other person other than NCC Group or the sender of its existence.

For more information about NCC Group please visit www.nccgroup.comhttp://www.nccgroup.com

P Before you print think about the ENVIRONMENT

For more information please visit http://www.mimecast.com
This email message has been delivered safely and archived online by Mimecast.

olivernn commented 8 years ago

Closing this now, feel free to re-open if you have any other questions.

nnmrts commented 7 years ago

I don't want to reopen here, but how could I sort the results by a given factor in an index entry. For example popularity or so.

olivernn commented 7 years ago

Well, the results are an array of score and document ref. So you can re-sort it however you want, including looking up the existing document by its ref from wherever you have it in memory. As a reminder, lunr does not keep a copy of the indexed documents itself.

nnmrts commented 7 years ago

@olivernn Okay, thanks! Just out of curiosity, can I set two or more refs in one lunr index? If not, wouldn't that be a cool feature? I mean, I just imagined setting two different refs, for example one with the filename in it for alphabetic sorting and one with a popularity number. I know, I just could load up the documents or make a store of these values by my own to access this data, but this would be an additional step and seems performance-heavy, especially in my case, when trying to handle 3 million different and changing documents.

By the way, thank you for this library! I really like it! 👍

olivernn commented 7 years ago

The problem is that Lunr is not intended to be the store of all your documents. How this data is stored would be very application specific, and trying to provide a reasonable interface would add quite a bit of complexity. The simplest thing for Lunr is to provide you with a key that you can use to lookup documents in whatever store you keep them in, be that locally in memory, or remotely via xhr.

I'm glad that Lunr is working well for you, especially with 3 million documents!