SpaceDelimitedTags() 공개 메소드

Joins the tags with a space.
public SpaceDelimitedTags ( ) : string
리턴 string
예제 #1
0
        /// <summary>
        /// Adds the specified page to the search index.
        /// </summary>
        /// <param name="model">The page to add.</param>
        /// <exception cref="SearchException">An error occured with the lucene.net IndexWriter while adding the page to the index.</exception>
        public virtual void Add(PageViewModel model)
        {
            try
            {
                EnsureDirectoryExists();

                StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
                using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    Document document = new Document();
                    document.Add(new Field("id", model.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
                    document.Add(new Field("content", model.Content, Field.Store.YES, Field.Index.ANALYZED));
                    document.Add(new Field("contentsummary", GetContentSummary(model), Field.Store.YES, Field.Index.NO));
                    document.Add(new Field("title", model.Title, Field.Store.YES, Field.Index.ANALYZED));
                    document.Add(new Field("tags", model.SpaceDelimitedTags(), Field.Store.YES, Field.Index.ANALYZED));
                    document.Add(new Field("createdby", model.CreatedBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("createdon", model.CreatedOn.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    document.Add(new Field("contentlength", model.Content.Length.ToString(), Field.Store.YES, Field.Index.NO));

                    writer.AddDocument(document);
                    writer.Optimize();
                }
            }
            catch (Exception ex)
            {
                if (!ApplicationSettings.IgnoreSearchIndexErrors)
                    throw new SearchException(ex, "An error occured while adding page '{0}' to the search index", model.Title);
            }
        }
예제 #2
0
		public void spacedelimitedtags_should_return_tags_space_separated()
		{
			// Arrange
			PageViewModel model = new PageViewModel();
			model.RawTags = "tag1, tag2, tag3";

			// Act
			string joinedTags = model.SpaceDelimitedTags();

			// Assert
			Assert.That(joinedTags, Is.EqualTo("tag1 tag2 tag3"));
		}
예제 #3
0
		/// <summary>
		/// Creates the initial search index based on all pages in the system.
		/// </summary>
		/// <exception cref="SearchException">An error occurred with the lucene.net IndexWriter while adding the page to the index.</exception>
		public virtual void CreateIndex()
		{
			EnsureDirectoryExists();

			try
			{
				StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
				using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
				{
					foreach (Page page in PageRepository.AllPages().ToList())
					{
						PageViewModel pageModel = new PageViewModel(PageRepository.GetLatestPageContent(page.Id), _markupConverter);

						Document document = new Document();
						document.Add(new Field("id", pageModel.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
						document.Add(new Field("content", pageModel.Content, Field.Store.YES, Field.Index.ANALYZED));
						document.Add(new Field("contentsummary", GetContentSummary(pageModel), Field.Store.YES, Field.Index.NO));
						document.Add(new Field("title", pageModel.Title, Field.Store.YES, Field.Index.ANALYZED));
						document.Add(new Field("tags", pageModel.SpaceDelimitedTags(), Field.Store.YES, Field.Index.ANALYZED));
						document.Add(new Field("createdby", pageModel.CreatedBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
						document.Add(new Field("createdon", pageModel.CreatedOn.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
						document.Add(new Field("contentlength", pageModel.Content.Length.ToString(), Field.Store.YES, Field.Index.NO));

						writer.AddDocument(document);
					}

					writer.Optimize();
				}
			}
			catch (Exception ex)
			{
				throw new SearchException(ex, "An error occurred while creating the search index");
			}
		}