public async Task <IActionResult> AddNote(string title, string text, string isPrivate) { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(text)) { return(BadRequest("Title or text is empty")); } if (title.Length > MaxTitleLength || text.Length > MaxTextLength) { return(BadRequest("Title or text is too long")); } var user = await FindUserAsync(User?.Identity?.Name); var note = new Note { Author = user?.Name, Title = title, Text = text, Time = DateTime.UtcNow }; var gen = LuceneIndex.AddNote(user, note, isPrivate == "on"); Response.Cookies.Append(IndexGenerationCookieName, gen.ToString()); return(Ok("Ok")); }
public virtual async Task <ActionResult> Delete(int id) { _postService.Delete(id); await _unitOfWork.SaveAllChangesAsync(); LuceneIndex.ClearLucenePostIndexRecord(id); return(Json("ok")); }
public void Init() { var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient(); _store = new AzureStore(client, false, null); // Do not snapshot and do tracing! _store.CreateContainerIfNotExists("testindexer"); var store = new SecureStore(_store); _indexer = new LuceneIndex(store, "testindexer", "basePath", null); }
private void btnClearIndex_Click(object sender, EventArgs e) { if (LuceneIndex.ClearLuceneIndex()) { MessageBox.Show("Search index was cleared successfully!"); } else { MessageBox.Show("Index is locked and cannot be cleared, try again later or clear manually!"); } }
public LuceneIndexDiagnostics( LuceneIndex index, ILogger <LuceneIndexDiagnostics> logger, IHostingEnvironment hostingEnvironment, IOptionsMonitor <LuceneDirectoryIndexOptions> indexOptions) { _hostingEnvironment = hostingEnvironment; _indexOptions = indexOptions.Get(index.Name); Index = index; Logger = logger; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void verifyDeferredConstraints(org.neo4j.storageengine.api.NodePropertyAccessor nodePropertyAccessor) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException public override void VerifyDeferredConstraints(NodePropertyAccessor nodePropertyAccessor) { try { LuceneIndex.verifyUniqueness(nodePropertyAccessor, Descriptor.schema().PropertyIds); } catch (IOException e) { throw new UncheckedIOException(e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void verifyDeferredConstraints(org.neo4j.storageengine.api.NodePropertyAccessor accessor) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException public override void VerifyDeferredConstraints(NodePropertyAccessor accessor) { try { LuceneIndex.verifyUniqueness(accessor, _propertyKeyIds); } catch (IOException e) { throw new UncheckedIOException(e); } }
public override IEnumerable <IIndex> Create() { var index = new LuceneIndex("AlbumIndex", CreateFileSystemLuceneDirectory("AlbumIndex"), //by default, all fields are just "FullText" new FieldDefinitionCollection( new FieldDefinition("id", FieldDefinitionTypes.Integer), new FieldDefinition("Title", FieldDefinitionTypes.FullTextSortable)), new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)); return(new[] { index }); }
public void Save() { var data = PrepareData(); LuceneIndex db = new LuceneIndex(typeName, directory, mockDocBuilder.Object, mockPathBuilder.Object, Version.LUCENE_30); foreach (var d in data) { db.AddDocument(d); } db.Save(); db.Close(); }
public void IndexSpellCheckDictionary(string dbIndexName, string spellIndex) { LuceneIndex index = (LuceneIndex)ContentSearchManager.GetIndex(dbIndexName); IndexReader reader = index.CreateReader(LuceneIndexAccess.ReadOnly); FSDirectory dir = FSDirectory.Open(spellIndex); var spell = new SpellChecker.Net.Search.Spell.SpellChecker(dir); string fieldName = "description"; LuceneDictionary dictionary = new LuceneDictionary(reader, fieldName); spell.IndexDictionary(dictionary, 10, 32); }
public void CannotWriteTwoLuceneIndexesOnSameStore() { _indexer.DeleteAll().Wait(); var store = new SecureStore(_store); using (var indexer2 = new LuceneIndex(store, "testindexer", "basePath", null)) { Assert.Throws<LockObtainFailedException>(() => { indexer2.DeleteAll().Wait(); }); } }
public void Init() { var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient(); _store = new AzureStore(client, false, null); // Do not snapshot and do tracing! _store.CreateContainerIfNotExists("testindexer"); // Use a file based cache for tests (more common use case) _tempDir = IO.Path.Combine(IO.Path.GetTempPath(), IO.Path.GetFileNameWithoutExtension(IO.Path.GetRandomFileName())); IO.Directory.CreateDirectory(_tempDir); var store = new SecureStore(_store); _indexer = new LuceneIndex(store, "testindexer", "basePath", null, _tempDir); }
/// <summary> /// Return the number of indexed documents in Lucene /// </summary> /// <param name="indexer"></param> /// <returns></returns> public static int GetIndexDocumentCount(this LuceneIndex indexer) { if (!((indexer.GetSearcher() as LuceneSearcher)?.GetLuceneSearcher() is IndexSearcher searcher)) { return(0); } using (searcher) using (var reader = searcher.IndexReader) { return(reader.NumDocs()); } }
/// <summary> /// Return the total number of fields in the index /// </summary> /// <param name="indexer"></param> /// <returns></returns> public static int GetIndexFieldCount(this LuceneIndex indexer) { if (!((indexer.GetSearcher() as LuceneSearcher)?.GetLuceneSearcher() is IndexSearcher searcher)) { return(0); } using (searcher) using (var reader = searcher.IndexReader) { return(reader.GetFieldNames(IndexReader.FieldOption.ALL).Count); } }
protected void Page_Load(object sender, EventArgs e) { string term = Request["q"]; if (!IsPostBack && !string.IsNullOrEmpty(term)) { txtSearchText.Text = term; string indexName = string.Format("sitecore_{0}_index", Sitecore.Context.Database.Name); LuceneIndex index = (LuceneIndex)ContentSearchManager.GetIndex(indexName); using (var searchContext = index.CreateSearchContext(Sitecore.ContentSearch.Security.SearchSecurityOptions.Default)) { var results = GetSearchResults(term, searchContext); // Code for getting similar words or Did you mean string spellIndex = Settings.IndexFolder + "/custom_spellcheck_index"; IndexSpellCheckDictionary(indexName, spellIndex); string[] suggestions = GetSuggestedWords(spellIndex, term, 3); /// bool hasNoResult = (results.Count < 1 && suggestions.Length > 0); if (hasNoResult) { results = GetSearchResults(suggestions[0], searchContext); } if (results.Count() > 0) { StringBuilder strSuggestion = new StringBuilder(); if (suggestions.Length > 0) { if (hasNoResult) { strSuggestion.Append("No results found for: <i>" + term + "</i><br/>Instead showing results for: "); } else { strSuggestion.Append("Did you mean? "); } lblDidYouMean.Text = strSuggestion.ToString(); foreach (string str in suggestions) { lblDidYouMean.Text += string.Format("<a href='?q={0}'>{0}</a> ", str); } } repeaterResults.DataSource = results; repeaterResults.DataBind(); } } } }
public void CanDisposeAndRead() { _indexer.WriteToIndex(CreateIpsumDocs(2000), true).Wait(); _indexer.Dispose(); _indexer = new LuceneIndex(new SecureStore(_store), "testindexer", "basePath", null); var number = _indexer.SearchDocuments(ind => { var query = new TermQuery(new Term("words", "ipsum")); return(ind.Search(query, 20)); }).ToList(); Assert.Greater(number.Count, 0); }
public void WaitsForNewGenerationOnReader() { var store = new SecureStore(_store); using (var readIndexer = new LuceneIndex(store, "testindexer", "basePath", null)) { // Hit the reader initially readIndexer.SearchDocuments(s => s.Search(new MatchAllDocsQuery(), int.MaxValue)).Count(); _indexer.WriteToIndex(CreateIpsumDocs(3000), true).Wait(); var stream = readIndexer.SearchDocuments(s => s.Search(new MatchAllDocsQuery(), int.MaxValue), true); Assert.AreEqual(3000, stream.Count()); } }
public void RecreatingWriterDoesNotRefreshIndex() { LeoTrace.WriteLine = Console.WriteLine; _indexer.WriteToIndex(CreateIpsumDocs(3), true).Wait(); _indexer.Dispose(); _indexer = new LuceneIndex(new SecureStore(_store), "testindexer", "basePath", null); _indexer.WriteToIndex(CreateIpsumDocs(3), true).Wait(); _indexer.Dispose(); _indexer = new LuceneIndex(new SecureStore(_store), "testindexer", "basePath", null); var number = _indexer.SearchDocuments(s => s.Search(new MatchAllDocsQuery(), int.MaxValue)).Count(); Assert.AreEqual(6, number); }
public async Task CannotWriteTwoLuceneIndexesOnSameStore() { var docs = CreateIpsumDocs(1); await _indexer.WriteToIndex(docs, true).ConfigureAwait(false); var store = new SecureStore(_store); using (var indexer2 = new LuceneIndex(store, "testindexer", "basePath", null)) { Assert.ThrowsAsync <LockObtainFailedException>(() => { return(indexer2.WriteToIndex(docs)); }); } }
public async Task <IActionResult> Search(string query, string myOnly) { if (query?.Length > MaxQueryLength) { return(BadRequest("Query is too long")); } var user = await FindUserAsync(User?.Identity?.Name); var to = DateTime.UtcNow; var from = to.AddMinutes(-LastMinutesToSearch); var gen = Request.Cookies[IndexGenerationCookieName].TryParseOrDefault(); return(Ok(LuceneIndex.Search(query, user, myOnly == "on", from, to, 1000, gen))); }
public virtual async Task <ActionResult> Add(AddPostViewModel postModel) { if (!ModelState.IsValid) { ViewData["CategoriesSelectList"] = new SelectList(await _postCategoryService.GetAll(), "Id", "Name"); return(View(postModel)); } var post = new DomainClasses.Post { PostedByUserId = User.Identity.GetUserId <int>() }; _mappingEngine.Map(postModel, post); if (postModel.Id.HasValue) { _postService.Edit(post); TempData["message"] = "پست مورد نظر با موفقیت ویرایش شد"; } else { _postService.Add(post); TempData["message"] = "پست جدید با موفقیت در سیستم ثبت شد"; } await _unitOfWork.SaveAllChangesAsync(); if (postModel.Id.HasValue) { LuceneIndex.ClearLucenePostIndexRecord(postModel.Id.Value); } LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { PostId = post.Id, Title = post.Title, Image = post.Image, Description = post.Body.RemoveHtmlTags(), Category = await _postCategoryService.GetCategoryName(postModel.CategoryId.Value), SlugUrl = post.SlugUrl }); return(RedirectToAction(MVC.Post.Admin.ActionNames.Index)); }
/// <summary> /// Checks if the index can be read/opened /// </summary> /// <param name="indexer"></param> /// <param name="ex">The exception returned if there was an error</param> /// <returns></returns> public static bool IsHealthy(this LuceneIndex indexer, out Exception ex) { try { using (indexer.IndexWriter.IndexWriter.GetReader(false)) { ex = null; return(true); } } catch (Exception e) { ex = e; return(false); } }
public override IEnumerable <IIndex> Create() { var index = new LuceneIndex("TweetIndex", CreateFileSystemLuceneDirectory("TweetIndex"), new FieldDefinitionCollection( new FieldDefinition("Content", FieldDefinitionTypes.FullTextSortable), new FieldDefinition("Username", FieldDefinitionTypes.FullText), new FieldDefinition("Screenname", FieldDefinitionTypes.FullText), new FieldDefinition("Avatar", FieldDefinitionTypes.FullText), new FieldDefinition("TweetedOn", FieldDefinitionTypes.FullText), new FieldDefinition("NumberOfTweets", FieldDefinitionTypes.FullText), new FieldDefinition("Url", FieldDefinitionTypes.FullText) ), new StandardAnalyzer(Version.LUCENE_30)); return(new[] { index }); }
protected virtual void Dispose(bool disposing) { Logging.Debug("LibraryIndex::Dispose({0}) @{1}", disposing, dispose_count); WPFDoEvents.SafeExec(() => { if (dispose_count == 0) { // Get rid of managed resources // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (word_index_manager_lock) { // l1_clk.LockPerfTimerStop(); word_index_manager?.Dispose(); word_index_manager = null; } //this.library?.Dispose(); } }); WPFDoEvents.SafeExec(() => { //this.word_index_manager = null; library = null; }); WPFDoEvents.SafeExec(() => { //Utilities.LockPerfTimer l4_clk = Utilities.LockPerfChecker.Start(); lock (pdf_documents_in_library_lock) { //l4_clk.LockPerfTimerStop(); pdf_documents_in_library?.Clear(); pdf_documents_in_library = null; } }); ++dispose_count; }
public override async Task RunAsync() { if (this.IsShuttingDown || this.Pause) { return; } LuceneIndex.ClearLuceneIndex(); var productService = IoC.Container.GetInstance <IProductService>(); var postService = IoC.Container.GetInstance <IPostService>(); foreach (var product in await productService.GetAllForLuceneIndex()) { LuceneIndex.ClearLuceneIndexRecord(product.Id); LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { ProductId = product.Id, Title = product.Title, Image = product.Image, Description = product.Description.RemoveHtmlTags(), Category = "کالاها", SlugUrl = product.SlugUrl, Price = product.Price.ToString(CultureInfo.InvariantCulture), ProductStatus = product.ProductStatus.ToString() }); } foreach (var post in await postService.GetAllForLuceneIndex()) { LuceneIndex.ClearLucenePostIndexRecord(post.Id); LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { PostId = post.Id, Title = post.Title, Image = post.Image, Description = post.Description.RemoveHtmlTags(), Category = post.Category, SlugUrl = post.SlugUrl }); } }
public virtual async Task <ActionResult> DeleteProduct(int id) { _productService.DeleteProduct(id); var deletedImages = await _productService.GetProductImages(id); await _unitOfWork.SaveAllChangesAsync(); LuceneIndex.ClearLuceneIndexRecord(id); foreach (var productImage in deletedImages) { var path = Server.MapPath("~/UploadedFiles/ProductImages/" + productImage); var thumbPath = Server.MapPath("~/UploadedFiles/ProductImages/Thumbs/" + productImage); System.IO.File.Delete(path); System.IO.File.Delete(thumbPath); } return(Json(true)); }
public LibraryIndex(Library library) { this.library = library; // Try to load a historical progress file if (File.Exists(Filename_DocumentProgressList)) { pdf_documents_in_library = (Dictionary <string, PDFDocumentInLibrary>)SerializeFile.LoadSafely(Filename_DocumentProgressList); } // If there was no historical progress file, start afresh if (null == pdf_documents_in_library) { Logging.Warn("Cound not find any indexing progress, so starting from scratch."); pdf_documents_in_library = new Dictionary <string, PDFDocumentInLibrary>(); } word_index_manager = new LuceneIndex(library.LIBRARY_INDEX_BASE_PATH); word_index_manager.WriteMasterList(); }
protected virtual void Dispose(bool disposing) { Logging.Debug("LibraryIndex::Dispose({0}) @{1}", disposing, dispose_count); try { if (dispose_count == 0) { // Get rid of managed resources Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (word_index_manager_lock) { l1_clk.LockPerfTimerStop(); word_index_manager?.Dispose(); word_index_manager = null; } //this.library?.Dispose(); } //this.word_index_manager = null; library = null; Utilities.LockPerfTimer l4_clk = Utilities.LockPerfChecker.Start(); lock (pdf_documents_in_library_lock) { l4_clk.LockPerfTimerStop(); pdf_documents_in_library?.Clear(); pdf_documents_in_library = null; } } catch (Exception ex) { Logging.Error(ex); } ++dispose_count; }
public virtual async Task <ActionResult> Index(int id) { var post = await _postService.GetPost(id); await _unitOfWork.SaveAllChangesAsync(false); ViewBag.Keywords = post.CategoryName; ViewBag.MetaDescription = post.MetaDescription; ViewBag.Author = post.AuthorName; ViewBag.LastModified = post.PostedDate.ToUniversalTime().ToString("ddd MMM dd yyyy HH:mm:ss \"GMT\"K"); if (post.CategoryId.HasValue) { ViewData["SimilarProducts"] = LuceneIndex.GetMoreLikeThisPostItems(id) .Where(item => item.Category != "کالاها").Skip(1).Take(8).ToList(); } return(View(post)); }
public virtual async Task <ActionResult> ReIndex() { LuceneIndex.ClearLuceneIndex(); var productService = IoC.Container.GetInstance <IProductService>(); var postService = IoC.Container.GetInstance <IPostService>(); foreach (var product in await productService.GetAllForLuceneIndex()) { LuceneIndex.ClearLuceneIndexRecord(product.Id); LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { ProductId = product.Id, Title = product.Title, Image = product.Image, Description = product.Description.RemoveHtmlTags(), Category = "کالاها", SlugUrl = product.SlugUrl, Price = product.Price.ToString(CultureInfo.InvariantCulture), ProductStatus = product.ProductStatus.ToString() }); } foreach (var post in await postService.GetAllForLuceneIndex()) { LuceneIndex.ClearLucenePostIndexRecord(post.Id); LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { PostId = post.Id, Title = post.Title, Image = post.Image, Description = post.Description.RemoveHtmlTags(), Category = post.Category, SlugUrl = post.SlugUrl }); } return(Content("ReIndexing Complete.")); }
public virtual async Task <ActionResult> AutoCompleteSearch(string term) { if (string.IsNullOrWhiteSpace(term)) { return(Content(string.Empty)); } var categories = await _categoryService.SearchCategory(term, 5); var items = LuceneIndex.Search(term, "Title", "Description").Take(10).ToList(); var luceneList = items.Where(x => x.Category == "کالاها").Select(item => new AutoCompleteSearchViewModel { Label = item.Title, Url = Url.Action(MVC.Product.Home.ActionNames.Index, MVC.Product.Home.Name, new { area = MVC.Product.Name, id = item.ProductId, slugUrl = item.SlugUrl }), Category = item.Category, Image = item.Image, }).ToList(); luceneList.AddRange(items.Where(x => x.Category != "کالاها").Select(item => new AutoCompleteSearchViewModel { Label = item.Title, Url = Url.Action(MVC.Post.Home.ActionNames.Index, MVC.Post.Home.Name, new { area = MVC.Post.Name, id = item.PostId, slugUrl = item.SlugUrl }), Category = item.Category, Image = item.Image })); var data = categories.Select(x => new AutoCompleteSearchViewModel { Label = x.Name, Url = $"{Url.Action(MVC.Product.SearchProduct.ActionNames.Index, MVC.Product.SearchProduct.Name, new { area = MVC.Product.Name })}#/page/{x.Id}", Category = "گروهها" }).Concat(luceneList); return(Json(data, JsonRequestBehavior.AllowGet)); }
public virtual async Task <ActionResult> Index(int id) { var model = await _productService.GetProductPage(id); ViewData["SimilarProducts"] = LuceneIndex.GetMoreLikeThisProjectItems(id) .Where(item => item.Category == "کالاها").Skip(1).Take(8).ToList(); await _unitOfWork.SaveAllChangesAsync(false); var keywords = ""; if (model.Categories != null && model.Categories.Any()) { keywords = model.Categories.Aggregate(keywords, (current, category) => current + (category.Name + "-")); } keywords = keywords.Substring(0, keywords.Length - 1); ViewBag.Keywords = keywords; ViewBag.MetaDescription = model.MetaDescription; return(View(model)); }
public void CanDisposeAndRead() { _indexer.WriteToIndex(CreateIpsumDocs(2000), true).Wait(); _indexer.Dispose(); _indexer = new LuceneIndex(new SecureStore(_store), "testindexer", "basePath", null); var number = _indexer.SearchDocuments(ind => { var query = new TermQuery(new Term("words", "ipsum")); return ind.Search(query, 20); }).ToList(); Assert.Greater(number.Count, 0); }