Novicell / Novicell.Examine.ElasticSearch

Elasticsearch provider for Examine in Umbraco v8
MIT License
12 stars 5 forks source link

ContentPicker and MultinodePicker give no searchresults when startnode is set #17

Open mcl-sz opened 3 years ago

mcl-sz commented 3 years ago

Hi @bielu ,

One of our users noticed that the searchbox in the contentpicker en multinodepicker doesn't give any results when Novicell.ElasticSearch is used for searching. We've investigated this with a clean StarterKit installation of Umbraco 8.10.2. The "Home"-node has an "Call To Action Link" property which uses the ContentPicker editor. We found out that no items can be found when a startnode is set in the configuration of the picker. If the startnode is not specified, the search works fine.

Both pickers do an API call to /umbraco/backoffice/UmbracoApi/Entity/Search, for example https://localhost:44351/umbraco/backoffice/UmbracoApi/Entity/Search?query=p&type=Document&searchFrom=umb://document/ca4249ed2b234337b52263cabe5587d1&dataTypeKey=3ece86aa-61ad-45d5-b1dd-8f02f25df949. When the "searchFrom" parameter is removed or set to "-1" the search gives results, otherwise it won't.

With startnode specified afbeelding

Without startnode specified afbeelding

We've tried to debug the reason why the searchFrom gives no results. It looks like the nodeId (-1,1104) is set in the Lucene query but for some reason it's not giving any results. Could you please help us?

bielu commented 3 years ago

hi @mcl-sz, I will look over weekend into that issue :)

mcl-sz commented 3 years ago

I did some more research and figured out that the "-1" in the Lucene query is causing the problem so that no results can be found. The query that is generated is : +(+__Path:-1,1104,* +(nodeName:p^10.0 nodeName_en-us:p^10.0 nodeName:p* nodeName_en-us:p* id:p* __NodeId:p* __Key:p*) +__IndexType:content) When I run this query in Kibana, no results are found.

When I replace -1 to , results are found: `+(+__Path:,1104, +(nodeName:p^10.0 nodeName_en-us:p^10.0 nodeName:p nodeName_en-us:p id:p NodeId:p* Key:p*) +__IndexType:content)`

I only have basic knowledge of Lucene queries. Is -1 a special or an invalid value to use in a query?

mcl-sz commented 3 years ago

It looks like the minus-character is causing the trouble. When the minus-character is removed, the query gives results as well: +(+__Path:1,1104,* +(nodeName:p^10.0 nodeName_en-us:p^10.0 nodeName:p* nodeName_en-us:p* id:p* __NodeId:p* __Key:p*) +__IndexType:content)

bielu commented 3 years ago

@mcl-sz thanks for input, will look into over weekend! :)

mcl-sz commented 3 years ago

Thanks @bielu! For now I have solved it quick and dirty by using a regular expression to escape all negative numbers in the query with a slash.

https://github.com/Novicell/Novicell.Examine.ElasticSearch/blob/d9bcd257b2e4f8168e01b79816b332015c81731c/source/Novicell.Examine.ElasticSearch/ElasticSearchSearchResults.cs#L99

Query = Regex.Replace(_luceneQuery.ToString(), @"(\-\d+)", "\\$1"),

This may not be the best solution, but for now it works for us. If you later have time to look for a better solution, that would be nice, but for now our problem has been solved with this.

bielu commented 3 years ago

@mcl-sz we can't do that :), as you can have - as sign something should be not included :)

mcl-sz commented 3 years ago

That true, as i said it's not the best solution but it now only escapes negative numbers, other query components with a - sign are not affected by this. It's just more a quick fix for us at the moment :)

We've included the source in our project, we don't use the NuGet package. Therefore it is not necessary for us to update your NuGet build. It was more to indicate that this will (temporarily) fix the problem for us and that you can look for a better solution when you have the time.

bielu commented 3 years ago

@mcl-sz I looked into that issue already 2 times and hmmmm tricky one :) as it looks like umbraco returns incorrect lucene query :)

bielu commented 3 years ago

@mcl-sz ok find out, that was case of analyser, I fix that in that commit: https://github.com/Novicell/Novicell.Examine.ElasticSearch/commit/d574160313a2cceb224062b1dc40e97365445947 can you check and comfirm it does work on your end?

mcl-sz commented 3 years ago

Hi @bielu , unfortunately this doesn't work for us yet. I have removed the old indexes so that new ones are created on start. The indexes are filled but do not find any results when the start node is set.

bielu commented 3 years ago

@mcl-sz ok i looked more deeply into that look like that is handled magicly inside of lucene.net even if that is incorrect lucene query. :) will look how to resolve that :)

mcl-sz commented 3 years ago

@bielu something wierd is happening when the query is passed to var result = internalSearcher.CreateQuery().NativeQuery(sb.ToString())

https://github.com/umbraco/Umbraco-CMS/blob/230bf1052cde249587d4ce06a2fb23859094f414/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs#L139

afbeelding

bielu commented 3 years ago

@mcl-sz and later examine is operating on not escaped values, so wtf :) need go more deeply