Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • blockingHD 3 posts 33 karma points
    25 days ago
    blockingHD
    0

    Cannot parse '__IndexType:content': Encountered "<EOF>" Error using

    We are creating an API to access some of the content stored in Umbraco from a separate app. When we make the calls initially it pulls the data down correctly after that however it starts throwing this error:

    Cannot parse '__IndexType:content': Encountered "<EOF>" at line 1, column 0. Was expecting one of:
        <NOT> ...
        "+" ...
        "-" ...
        <BAREOPER> ...
        "(" ...
        "*" ...
        <QUOTED> ...
        <TERM> ...
        <PREFIXTERM> ...
        <WILDTERM> ...
        <REGEXPTERM> ... ...
    

    The API code is:

    [HttpGet("search")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
    public ActionResult<IEnumerable<DocumentInfo>> GetBySearchTerm([FromQuery] string term)
    {
        if (string.IsNullOrWhiteSpace(term))
        {
            return NotFound("Missing parameter 'term'");
        }
    
        List<DocumentInfo> documentDetails;
        try
        {
            var publishedSearchResults = _publishedContentQuery.Search(term).ToList();
    
            documentDetails = publishedSearchResults.Select(x => PopulateDocumentInfo(x.Content))
                .ToList();
        }
        catch (Exception ex)
        {
            //  _logger.LogError(ex, $"Get notifications for user {id} failed for type {notificationType}");
            return StatusCode(StatusCodes.Status500InternalServerError, "Get By Search Term failed");
        }
    
        return documentDetails;
    }
    

    Any ideas where this could be coming from or have we found a V9 bug?

  • Bjarke Berg 29 posts 251 karma points hq
    25 days ago
    Bjarke Berg
    0

    Your code seems correct, it works fine for me..

    Try to rebuild the external index in backoffice, and the if the error still occurs..

    My simple example looks like this

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using Umbraco.Cms.Core;
    using Umbraco.Cms.Core.Models.PublishedContent;
    using Umbraco.Cms.Web.Common.Controllers;
    
    namespace UmbracoTestSite
    {
        public class SearchController : UmbracoApiController
        {
            private readonly IPublishedContentQuery _publishedContentQuery;
    
            public SearchController(IPublishedContentQuery publishedContentQuery)
            {
                _publishedContentQuery = publishedContentQuery;
            }
    
            [HttpGet("search")]
            [ProducesResponseType(StatusCodes.Status200OK)]
            [ProducesResponseType(StatusCodes.Status404NotFound)]
            [ProducesResponseType(StatusCodes.Status500InternalServerError)]
            public ActionResult<IEnumerable<DocumentInfo>> GetBySearchTerm([FromQuery] string term)
            {
                if (string.IsNullOrWhiteSpace(term))
                {
                    return NotFound("Missing parameter 'term'");
                }
    
                List<DocumentInfo> documentDetails;
                try
                {
                    var publishedSearchResults = _publishedContentQuery.Search(term).ToList();
    
                    documentDetails = publishedSearchResults.Select(x => PopulateDocumentInfo(x.Content))
                        .ToList();
                }
                catch (Exception ex)
                {
                    //  _logger.LogError(ex, $"Get notifications for user {id} failed for type {notificationType}");
                    return StatusCode(StatusCodes.Status500InternalServerError, "Get By Search Term failed");
                }
    
                return documentDetails;
            }
    
            private DocumentInfo PopulateDocumentInfo(IPublishedContent argContent)
            {
                return new DocumentInfo(argContent);
            }
        }
    
        public class DocumentInfo
        {
            public DocumentInfo(IPublishedContent content)
            {
                Name = content.Name;
            }
    
            public string Name { get; init; }
        }
    }
    

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft