コード例 #1
0
ファイル: UserSearchDelete.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Initializes a new instance of the <see cref="UserSearchDelete"/> class.
        /// </summary>
        /// <param name="search">The search.</param>
        public UserSearchDelete(UserSearch search)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search");
            }

            this.Id = search.Id;
            this.Title = search.Title;
        }
コード例 #2
0
        public void Test_UserSearchService_Insert()
        {
            var search = new UserSearch
            {
                Title = "test2"
            };

            this.UserSearchService.Insert(search);

            Assert.AreEqual(2, search.Id, "Id");
            Assert.AreEqual(1, search.UserId, "UserId");
            Assert.AreEqual("test2", search.Title, "Title");
        }
コード例 #3
0
        public void Test_UserSearchCreate_ValueToModel()
        {
            var date = DateTime.Now;

            var value = new UserSearchCreate
            {
                Reputation = 1,
                Name = "test",
                EmailAddress = "test2",
                Title = "test3",
                Save = true,
                NameExact = true,
                ReputationAtLeast = true,
                CreatedBefore = date,
                CreatedAfter = date.AddDays(1),
                LastVisitBefore = date.AddDays(2),
                LastVisitAfter = date.AddDays(3),
                LastLogOnBefore = date.AddDays(4),
                LastLogOnAfter = date.AddDays(5),
            };

            var search = new UserSearch();

            value.ValueToModel(search);

            Assert.AreEqual(1, search.Reputation, "Reputation");
            Assert.AreEqual("test", search.Name, "Name");
            Assert.AreEqual("test2", search.EmailAddress, "EmailAddress");
            Assert.AreEqual("test3", search.Title, "Title");
            Assert.IsTrue(search.NameExact, "NameExact");
            Assert.IsTrue(search.ReputationAtLeast, "ReputationAtLeast");

            Assert.IsNotNull(search.CreatedBefore, "CreatedBefore");
            Assert.AreEqual(date, search.CreatedBefore.Value, "CreatedBefore Date");
            Assert.IsNotNull(search.CreatedAfter, "CreatedAfter");
            Assert.AreEqual(date.AddDays(1), search.CreatedAfter.Value, "CreatedAfter Date");

            Assert.IsNotNull(search.LastVisitBefore, "LastVisitBefore");
            Assert.AreEqual(date.AddDays(2), search.LastVisitBefore.Value, "LastVisitBefore Date");
            Assert.IsNotNull(search.LastVisitAfter, "LastVisitAfter");
            Assert.AreEqual(date.AddDays(3), search.LastVisitAfter.Value, "LastVisitAfter Date");

            Assert.IsNotNull(search.LastLogOnBefore, "LastLogOnBefore");
            Assert.AreEqual(date.AddDays(4), search.LastLogOnBefore.Value, "LastLogOnefore Date");
            Assert.IsNotNull(search.LastLogOnAfter, "LastLogOnAfter");
            Assert.AreEqual(date.AddDays(5), search.LastLogOnAfter.Value, "LastLogOnAfter Date");
        }
コード例 #4
0
 public void Update(UserSearch entity)
 {
 }
コード例 #5
0
 public void Insert(UserSearch entity)
 {
 }
コード例 #6
0
 public IPagedCollection<User> GetResults(UserSearch search, ISpecification<UserSearch> specification)
 {
     return new PagedCollection<User>(new List<User>(), 1, 1, 0);
 }
コード例 #7
0
 public void Delete(UserSearch entity)
 {
 }
コード例 #8
0
ファイル: UserSearcher.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Queries the index using the specified search.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="specification">The specification.</param>
        public void Query(UserSearch search, ISpecification<UserSearch> specification)
        {
            var searcher = new IndexSearcher(Setting.UserSearchIndexPath.Value);
            var query = new BooleanQuery();

            NameQuery(search, query);
            EmailAddressQuery(search, query);
            ReputationQuery(search, query);
            CreatedQuery(search, query);
            LastVisitQuery(search, query);
            LastLogOnQuery(search, query);

            var hits = searcher.Search(query);

            this.Total = hits.Length();
            this.Results = new List<int>();

            for (var k = specification.First; k < specification.Last && k < hits.Length(); k++)
            {
                var doc = hits.Doc(k);

                if (doc == null)
                {
                    continue;
                }

                this.Results.Add(doc.Get("id").AsInt());
            }

            searcher.Close();
        }
コード例 #9
0
ファイル: UserSearcher.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Builds the name query.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="query">The query.</param>
        private void NameQuery(UserSearch search, BooleanQuery query)
        {
            if (string.IsNullOrEmpty(search.Name))
            {
                return;
            }

            if (search.NameExact)
            {
                var user = this.UserService.GetBy(new UserNameSpecification(search.Name));

                if (user == null)
                {
                    return;
                }

                query.Add(new TermQuery(new Term("id", user.Id.ToString())), BooleanClause.Occur.MUST);
            }
            else
            {
                query.Add(new QueryParser("name", new SimpleAnalyzer()).Parse(search.Name), BooleanClause.Occur.SHOULD);
            }
        }
コード例 #10
0
ファイル: UserSearcher.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Builds the reputation query.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="query">The query.</param>
        private static void ReputationQuery(UserSearch search, BooleanQuery query)
        {
            if (!search.Reputation.HasValue)
            {
                return;
            }

            if (search.ReputationAtLeast)
            {
                query.Add(
                    new RangeQuery(
                            new Term("reputation", search.Reputation.ToString()),
                            new Term("reputation", int.MaxValue.ToString()),
                            false
                        ),
                        BooleanClause.Occur.SHOULD
                    );
            }
            else
            {
                query.Add(
                    new RangeQuery(
                            new Term("reputation", "0"),
                            new Term("reputation", search.Reputation.ToString()),
                            false
                        ),
                        BooleanClause.Occur.SHOULD
                    );
            }
        }
コード例 #11
0
ファイル: UserSearcher.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Builds the last visit query.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="query">The query.</param>
        private static void LastVisitQuery(UserSearch search, BooleanQuery query)
        {
            if (search.LastVisitBefore.HasValue)
            {
                query.Add(
                    new RangeQuery(
                            new Term("created", DateTime.MinValue.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)),
                            new Term("created", search.LastVisitBefore.Value.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)),
                            false
                        ),
                        BooleanClause.Occur.MUST
                    );
            }

            if (search.LastVisitAfter.HasValue)
            {
                query.Add(
                    new RangeQuery(
                            new Term("last_visit", search.LastVisitAfter.Value.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)),
                            new Term("last_visit", DateTime.Now.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)),
                            false
                        ),
                        BooleanClause.Occur.MUST
                    );
            }
        }
コード例 #12
0
ファイル: UserSearcher.cs プロジェクト: Mike343/Netcoders
        /// <summary>
        /// Builds the email address query.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="query">The query.</param>
        private static void EmailAddressQuery(UserSearch search, BooleanQuery query)
        {
            if (string.IsNullOrEmpty(search.EmailAddress))
            {
                return;
            }

            query.Add(new QueryParser("email", new SimpleAnalyzer()).Parse(search.EmailAddress), BooleanClause.Occur.SHOULD);
        }