umco / umbraco-ezsearch

A simple search package for Umbraco
https://our.umbraco.org/projects/website-utilities/ezsearch
MIT License
6 stars 11 forks source link

Indexing errors when switching the upload field for media to a cropper #7

Open Shazwazza opened 9 years ago

Shazwazza commented 9 years ago

It's because of this code here:

        // Extract the filename from media items
        if(e.Fields.ContainsKey("umbracoFile"))
        {
            e.Fields["umbracoFileName"] = Path.GetFileName(e.Fields["umbracoFile"]);
        }

in the ezSearchBoostrapper class

If you change the file upload on a media item to be a cropper, then the umbracoFile value is Json and this throws a ysod.

akeilox commented 9 years ago

have you find a workaround Shannon, doing media ezsearch with file upload replaced as cropper?

Shazwazza commented 9 years ago

I haven't tried anything, if ezsearch get's updated that would be the best fix, would be pretty simple really.

Otherwise you can try to add your own indexing handler just like ez search does and parse the value properly.

akeilox commented 9 years ago

any pointers or quick fix you can share for changing the part to support cropper default data type? I am not sure how to update to code to support the json parsing accordingly...

// Extract the filename from media items if(e.Fields.ContainsKey("umbracoFile")) { e.Fields["umbracoFileName"] = Path.GetFileName(e.Fields["umbracoFile"]); }

garpunkal commented 7 years ago

This will support the imagecropdataset... not sure if there is any other way to detect if JSON exists rather than the URL.

if (e.Fields.ContainsKey(StaticValues.Properties.UmbracoFile)) { try { var imageCrop = JsonConvert.DeserializeObject(e.Fields[StaticValues.Properties.UmbracoFile]); e.Fields[StaticValues.Properties.UmbracoFileName] = Path.GetFileName(imageCrop.Src); } catch { e.Fields[StaticValues.Properties.UmbracoFileName] = Path.GetFileName(e.Fields[StaticValues.Properties.UmbracoFile]); } }

TwoMoreThings commented 6 years ago

This may be considered a bit hacky, but a quick fix would be to extract the filename using regex

if (e.Fields.ContainsKey("umbracoFile")) { var match = Regex.Match(e.Fields["umbracoFile"], @"(\/media.*?.(jpg|png|gif|jpeg|svg))"); if (match.Success) { e.Fields["umbracoFileName"] = match.Value; } }

of course this depends on specific media types, and it doesn't check if the image cropper or upload field has been used

t