public static void BuildIndex() { var indexPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Index"); var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(indexPath), true); using (var indexService = new IndexService(indexWriter)) { var result = indexService.IndexEntities(OnTimeItemRepository.GetItems(), new OnTimeItemIndexDefinition()); } }
public static void BuildIndex(HttpContext ctx) { var indexPath = ctx.Server.MapPath("~/App_Data/Index"); var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(indexPath), true); var documentPath = ctx.Server.MapPath("~/Documentation"); using (var indexService = new IndexService(indexWriter)) { indexService.IndexEntities( Directory.EnumerateFiles(documentPath, "*.markdown", SearchOption.AllDirectories), f => { var doc = new Document(); var name = Path.GetFileNameWithoutExtension(f); var text = File.ReadAllText(f); doc.Add(new Field("Id", name, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Url", "~/Documentation/" + name, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", name.Replace('-', ' '), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Text", text, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Summary", MarkdownExtensions.ExtractSummary(text), Field.Store.YES, Field.Index.NOT_ANALYZED)); return doc; }); } }
public void CreateIndex(Offers newOffer) { // index location var indexLocation = new FileSystemIndexLocation(new DirectoryInfo(Server.MapPath("~/Index"))); var definition = new OfferIndexDefinition(); var task = new EntityUpdateTask<Offers>(newOffer, definition, indexLocation); task.IndexOptions.RecreateIndex = false; task.IndexOptions.OptimizeIndex = true; //IndexQueue.Instance.Queue(task); var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(Server.MapPath("~/Index")), false); using (var indexService = new IndexService(indexWriter)) { task.Execute(indexService); } }