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

Lower level query interface #37

Closed olivernn closed 7 years ago

olivernn commented 11 years ago

A more advanced query interface is something that lunr definitely needs. I'm not entirely sure what the interface would look like for this, perhaps a different method on the index and a query object itself:

idx.query(function () {
    this.all('foo bar*') // these are AND query terms
    this.some('*baz') // these are OR query terms

    this.limit(10) // maximum number of results to return
    this.threshold(0.7) // minimum score for returned documents

    this.facet('herp', ['derp', 'burp']) // facets and values
})

This is just a very rough idea, but I think it is the right direction. It hopefully exposes a more powerful interface to the search. The idx.search method would still exist as a quick way to perform searches, but it would probably be built onto of this query method.

Any input or feedback is much appreciated.

Rameshv commented 11 years ago

Looks great to me :+1:

I like having a one search method, and rest of It derived from the query object.


var query =  new idx.query( {
    term:'foo AND bar',
    limit:10,
    page:1
}) 

idx.search(query)

this way idx.query will take care of all the parsing before passing it to search. And no need to include new method for new additions.

garysieling commented 11 years ago

I agree on this one - I tried playing around with it some but it was a little more than I wanted to take on. As an experiment, I tried building one of your 'index' objects for each attribute, then combine the results.

I was imagining a json interface, because you could always have a query language that parsed into that if it was really necessary.

orthecreedence commented 11 years ago

I would love this feature, and also to add in a search type: exclusion. For instance being able to do pageview -entry to show all "pageview" terms that do not include "entry."

Just to throw in my two cents, I like the proposed interface a lot (the callback with specific search functions defined in scope)..

brockfanning commented 11 years ago

This seems great! Would love to have facets!

jglamine commented 10 years ago

OR based query support is a feature I could really use. What's the status on this?

KyleAMathews commented 9 years ago

+1

Prieul-Simon commented 9 years ago

I agree with this one. OR based queries are what I need. For now, i used the same trick as the one described here

olivernn commented 7 years ago

It turned out differently the described in this issue, but the latest version of Lunr does provide more control over performing queries.