Closed stephengoodwin closed 7 years ago
Or even:
index.search({'city': 'austin'})
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.
I've gotten around this by indexing the fields raw and as "
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?
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");
+1
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.
Closing this now as v2 is now available in npm.
Current query:
Desired query: