Copied to clipboard

Flag this post as spam?

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


  • Petras Surna 90 posts 144 karma points
    May 13, 2019 @ 02:06
    Petras Surna
    0

    Adding content in c# programatically generates Lucene exceptions - is this normal?

    I am adding content in c# code and it is generating exceptions

    Exception thrown: 'Lucene.Net.QueryParsers.QueryParser.LookaheadSuccess' in Lucene.Net.dll Exception thrown: 'System.IO.IOException' in Lucene.Net.dll Exception thrown: 'System.IO.IOException' in Lucene.Net.dll Exception thrown: 'System.NotSupportedException' in Lucene.Net.dll

    Is this normal behavior?

    This video shows the problem https://www.youtube.com/watch?v=0ZaZ5H0ZKQA

    The code is

    public class ProductsController : RenderMvcController {

    private static Random random = new Random();
    
    public override ActionResult Index(ContentModel model)
    {
      AddContent();
    
      return base.Index(model);
    }
    
    
    private void AddContent()
    {
      int length = Price(5, 20);
    
      string title = Title(length);
      string description = "description";
      string price = Price(0, 100).ToString();
    
      var content = Services.ContentService.Create(title, 1061, "product");
    
      content.SetValue("title", title);
      content.SetValue("description", description);
      content.SetValue("price", price);
    
      //exceptions thrown here
      Services.ContentService.Save(content);
    }
    
    
    public static string Title(int length)
    {
      const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      return new string(Enumerable.Repeat(chars, length)
        .Select(s => s[random.Next(s.Length)]).ToArray());
    }
    
    
    private int Title()
    {
      Random r = new Random();
      return r.Next(0, 100); //for ints
    }
    
    
    private int Price(int min, int max)
    {
      Random r = new Random();
      return r.Next(min, max); //for ints
    }
    

    }

    It also seems very slow to add content. To takes 7 seconds to add 10 records:

      for (int i = 0; i < 10; i++)
      {
        AddContent();
      }
    

    I was wondering if that was normal?

Please Sign in or register to post replies

Write your reply to:

Draft