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 it possible to query by field? #125

Closed
stephengoodwin opened this Issue Dec 18, 2014 · 8 comments

Comments

Projects
None yet
6 participants
@stephengoodwin

stephengoodwin commented Dec 18, 2014

Current query:

index.search('austin')

Desired query:

index.search('city:austin')
@jbohren

This comment has been minimized.

jbohren commented Dec 19, 2014

Or even:

index.search({'city': 'austin'})
@olivernn

This comment has been minimized.

Owner

olivernn commented Dec 20, 2014

Its currently not possible to search by field due to the way that the documents are scored and indexed. I'll take it into account as a feature for future releases though.

@shaun4477

This comment has been minimized.

shaun4477 commented Dec 21, 2014

I've gotten around this by indexing the fields raw and as ":". It only works for single word values but is reasonably effective for my use case.

@jbohren

This comment has been minimized.

jbohren commented Dec 21, 2014

I've gotten around this by indexing the fields raw and as ":". It only works for single word values but is reasonably effective for my use case.

Can you elaborate on what you mean?

@justinlinz

This comment has been minimized.

justinlinz commented May 21, 2015

Not sure if this is the solution shaun4477 was referring to, but you can prefix your value with propertyname: when indexing, and get decent results. There are probably some drawbacks with this approach as well, but depending on what you need might get the job done.

var data = [{
            refId:'68977',
            name:'Dilbert',
            title:'Engineer'
        },{
            refId:'45674',
            name:'Wally',
            title:'Engineer',
        },{
            refId:'00014',
            name:'Pointy-Haired Boss',
            title:'Manager'
        }
        ];

        var employees = lunr(function () {
            this.ref('refId');
            this.field('name');
            this.field('title');
        });

        data.forEach(function(r){
            employees.add({
                    refId:'refId:'+ r.refId,
                    name:'name:'+ r.name,
                    title:'title:'+ r.title
                }
            );
        });

        var results = employees.search("name:Dilbert title:Engineer");
@tirana

This comment has been minimized.

tirana commented Nov 20, 2015

+1

@olivernn

This comment has been minimized.

Owner

olivernn commented Jan 4, 2017

I have published an alpha release of the next version of lunr with support for query by field.

In addition I've put together a basic demo that should allow you to play around with the search by field feature.

@olivernn

This comment has been minimized.

Owner

olivernn commented Apr 10, 2017

Closing this now as v2 is now available in npm.

@olivernn olivernn closed this Apr 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment