fergiemcdowall / search-index

A persistent, network resilient, full text search library for the browser and Node.js
MIT License
1.39k stars 149 forks source link

Problem quering over fields with multiple values #328

Closed fdelavega closed 7 years ago

fdelavega commented 8 years ago

Hi,

I am having some trouble making queries over list fields. In my use case, I have some offerings which can belong to different categories. Then it is possible to search all the offerings in a category both, including the id of the category or its name.

For example, creating the document with the following data, we have the fields categoriesId, and categoriesName:

[
   {
      "id":"offering:21",
      "originalId":"21",
      "sortedId":"000000000021",
      "body":[
         "And Filter Operator",
         ""
      ],
      "userId":"b0946ffa20357194688e54b1cf143c9c",
      "productSpecification":"000000000017",
      "categoriesId":[
         "1",
         "5"
      ],
      "categoriesName":[
         "WireCloud Component",
         "WireCloud Operator"
      ],
      "href":"http://store.lab.fiware.org/DSProductCatalog/api/catalogManagement/v2/catalog/19/productOffering/21:(0.1)",
      "name":"And Filter Operator",
      "lifecycleStatus":"Launched",
      "isBundle":false,
      "catalog":"19"
   }
]

If I execute queries like the following, It works perfectly:

{"query":[{"AND":[{"lifecycleStatus":["launched"]}],"NOT":[null]}]}
. But with the following query, it returns 0 hits:
{"query":[{"AND":[{"categoriesId":["5"]},{"lifecycleStatus":["launched"]}]}
**Edit**: If the provided id has 2 or more characters, it works ("categoriesId":["11", "15"])
fergiemcdowall commented 8 years ago

I think you have a little typo in your query, try this:

{
  query: [{
    AND: {
      categoriesId: ['5'],
      lifecycleStatus: ['launched']
    }
  }]
}

I put your case into the tests, just to be sure: https://github.com/fergiemcdowall/search-index/blob/master/test/node/general-tests/328-test.js (passing)

fdelavega commented 8 years ago

Hi,

I am obtaining the same result with that query:

{"query":[{"AND":[{"categoriesId":["5"],"lifecycleStatus":["launched"]}],"NOT":[null]}],"hits":[],"totalHits":0} 

Indeed the method getDocumentFreqencies of the searcher class is giving the same results with both queries (I mean the one I was using before) one hit for the status and 0 for the category Id, which results in a 0 hits result.

The estrange think about this, is that is not something that fails in all the cases, the following query:

{"query":[{"AND":[{"categoriesId":["13"]},{"lifecycleStatus":["launched"]}]}

and

"query":[{"AND":[{"categoriesId":["13"],"lifecycleStatus":["launched"]}]

Work properly. Making different queries I have seen that the only ones that are not giving me results are those that have a categoryIid of a single character (In my case 1, 5 and 7)

Taking into account that you have included it in a test, I think that there should be something in the environment

fergiemcdowall commented 8 years ago

I think the best way forward here is to create a reproducible test case that shows the broken behaviour, and then we can take it from there.

fdelavega commented 8 years ago

as a wokarround I have included a fixed string at the begining of the ids (now are cat:5), which this change it works properly

fergiemcdowall commented 8 years ago

It sounds like you have uncovered a bug that needs to be fixed possibly relating to the way that numeric strings are handled. Will leave this open in case anybody else experiences a similar problem

fergiemcdowall commented 7 years ago

I'm pretty sure that this is now fixed- but please reopen if it persists