npms-io / npms-api

The https://npms.io API
MIT License
189 stars 30 forks source link

Advanced queries #29

Closed montogeek closed 8 years ago

montogeek commented 8 years ago

Hi!

Great project!

I would like to ask about advanced queries, such as search by author or keywords as http://npmsearch.com/ do.

mikeerickson commented 8 years ago

In addition to @montogeek request, looking for the ability to search for multiple terms (ala npm install)

$http.get('https://api.npms.io/search', {
        json: true,
        query: {
          term: 'gulp-messenger gulp-phpunit gulp-phpspec',
        }

In addition, this could be expanded to support @montogeek request

$http.get('https://api.npms.io/search', {
        json: true,
        query: {
           author: 'mikeerickson',
           keyword: 'gulp'
        }
satazor commented 8 years ago

Support searching by keywords and author seems a good addition, we will definitively add those.

@mikeerickson we support multiple terms but they are used as AND and not OR.

satazor commented 8 years ago

I'm currently looking into implementing this.

Regarding author:

If you open https://www.npmjs.com/~satazor, it shows all modules that I am qualified as a maintainer. When people are filtering by author what are they expecting? As you see author is a bit ambiguous.

Possible solutions:

Suggestions?

satazor commented 8 years ago

//cc @sindresorhus

sindresorhus commented 8 years ago

Agreed. Should be the npm users with publish rights. ?maintainer=satazor looks good.

satazor commented 8 years ago

@sindresorhus thanks for the feedback

The way I'm implementing it is not as a query parameter, but instead with ?q=query, where the query must obey a DSL. It looks similar to GitHub when you are searching for issues. Examples:

maintainer:satazor exclude:deprecated keywords:windows,macosx cross-spawn maintainer:sindresorhus exclude:insecure promise score-effect:10 maintenance-weight:20 test runner

This is a breaking change in the search API but I will support the old ?term API until December. Having that said, it will support maintainer:satazor and also add author and publisher support as I described above.

satazor commented 8 years ago

I've done some work and I got this stuff working locally. But since this is a breaking change I got to setup API versioning and ensure everything is done smoothly. Here's the API doc for the query DSL that allows advanced filtering and modifiers:

screen shot 2016-09-17 at 13 38 52

I expect to get this deployed in the next 4 days.

satazor commented 8 years ago

I've deployed this yesterday in api v2. Check out the changelog and the API docs