-
Notifications
You must be signed in to change notification settings - Fork 149
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
Searching fields using boolean AND doesn't yield any results #8
Comments
Hi, @hydrajump , thanks for this feedback. Firstly, before indexing documents, you need to tell elasticlunr which field that you want to index by: var index = elasticlunr(function () {
this.addField('name');
this.addField('array1');
this.addField('array2')
this.setRef('id');
}); then, index your json data, to make it clear, I defined two json data by your data: var doc1 = {
"name": "my name is A",
"array1": [
"array1 value1",
"array1 value2"
],
"array2": [
"array2 value1",
"array2 value2"
],
"id": "nameA"
}
var doc2 = {
"name": "my name is B",
"array1": [
"array1 value4",
"array1 value10"
],
"array2": [
"array2 value1",
"array2 value5"
],
"id": "nameB"
} and then, index these two documents: index.addDoc(doc1);
index.addDoc(doc2); then search, index.search("my name is B", {
fields: {
name: {}
},
bool: "AND"
}); and the results is:
And, you are right, currently elasticlunr has some issue about find the documents from field that consist of array. Thanks very much for reporting this issue. I will fix this issue as soon as possible. |
@weixsong thanks for your quick reply! Yeah, I've done all the things that you said, but as you confirmed the issue with array fields is unfortunately the reason that the results are not what they should be. |
Hi, @hydrajump , finally fixed this issue. Follow the following codes: var index = elasticlunr(function () {
this.addField('name');
this.addField('array1');
this.addField('array2')
this.setRef('id');
});
var doc1 = {
"name": "my name is A",
"array1": [
"array1 value1",
"array1 value2"
],
"array2": [
"array2 value1",
"array2 value2"
],
"id": "nameA"
}
var doc2 = {
"name": "my name is B",
"array1": [
"array1 value4",
"array1 value10"
],
"array2": [
"array2 value1",
"array2 value5"
],
"id": "nameB"
}
index.addDoc(doc1);
index.addDoc(doc2);
index.search("my name is B", {
fields: {
name: {}
},
bool: "AND"
}); Query results:
And another query: index.search("array1 value1", {
fields: {
array1: {}
},
bool: "AND"
}); Query results:
Thanks very much for reporting this issue. |
Hey @weixsong, thank you for fixing this issue so fast 😄 |
Hi,
I'm coming from
lunrjs
because I'm interested in your field searching feature.My index json looks similar to this:
What I need to be able to do is search this index using queries such as this (I know the syntax is not correct):
The problem is that when I use my real json file and run the searches above I don't get the expected results.
I hope you understand what I mean and can help me find a solution to these issues. Thanks.
The text was updated successfully, but these errors were encountered: