fergiemcdowall / norch

A search server that can be installed with npm
655 stars 45 forks source link

/totalHits not working as expected? #140

Closed eklem closed 7 years ago

eklem commented 7 years ago

I was guessing that /totalHits would take the same q.query as input as the /search endpoint. That seems to not be the case:

My search query: http://oppskrift.klemespen.com:3030/search?q={"query":{"AND":{"*":["eple"]}}}

The totalHits q/count query: http://oppskrift.klemespen.com:3030/totalHits?q={"query":{"AND":{"Varenavn":["eple"]}}} http://oppskrift.klemespen.com:3030/totalHits?count={"query":{"AND":{"Varenavn":["eple"]}}}

First /totalHits-query gives me an error:

{"code":"InternalError","message":"q.query.forEach is not a function"}

Second /totalHits-query gives me the same as docCount - the total amount of docs in the index, but as an object.

search-index API for totalHits: https://github.com/fergiemcdowall/search-index/blob/7faf44f328e87c6c5bed0ada9d90d552db195d10/doc/API.md#totalhits

fergiemcdowall commented 7 years ago

Yes it should take the exact same query. Investigating...

fergiemcdowall commented 7 years ago

Its because totalHits expects an Array. So

http://oppskrift.klemespen.com:3030/totalHits?q=[{"query":{"AND":{"Varenavn":["eple"]}}}]

...works

http://oppskrift.klemespen.com:3030/totalHits?q={"query":{"AND":{"Varenavn":["eple"]}}} should also work though- need to fix

eklem commented 7 years ago

Wohooo! Works like a charm. And nice that it doesn't error on additonal stuff like pageSize. I'll make an issue on accepting the short-version of the q-object.