Ejemplo n.º 1
0
        // https://github.com/SolrNet/SolrNet/blob/master/Documentation/CRUD.md
        public IActionResult Create()
        {
            PhotoSearch post = new PhotoSearch();

            post.PhotoId = "3410687";
            post.Name    = new string[] { "New Added " + DateTime.Now };
            solr.AddUpdate(post);

            SolrQueryResults <PhotoSearch> results = solr.GetAll();

            return(View("index", results));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(string Id)
        {
            var post = new PhotoSearch();

            post.PhotoId = "3410688";
            post.Name    = new string[] { "Updated " + DateTime.Now };
            post.id      = Id;
            solr.AddUpdate(post);

            SolrQueryResults <PhotoSearch> results = solr.GetAll();

            return(View("index", results));
        }
Ejemplo n.º 3
0
        public PagedResponse <PhotoDto, Photo> Execute(PhotoSearch search)
        {
            var query = _context.Photos.Include(p => p.Post).AsQueryable();

            if (!string.IsNullOrEmpty(search.PhotoCaption) && !string.IsNullOrWhiteSpace(search.PhotoCaption))
            {
                query = query.Where(g => g.Caption.ToLower().Contains(search.PhotoCaption.ToLower()));
            }

            query = query;

            return(new PagedResponse <PhotoDto, Photo>(query, search, _mapper));
        }
Ejemplo n.º 4
0
        public ActionResult Index(string searchTerm, string searchField, string type, string checkbox, int PageIndex = -1)
        {
            int totalResults = 0;

            if (!Directory.Exists(PhotoSearch._luceneDir))
            {
                Directory.CreateDirectory(PhotoSearch._luceneDir);
            }
            // perform Lucene search
            if (string.IsNullOrEmpty(type))
            {
                _searchResults = string.IsNullOrEmpty(searchField)
                                    ? PhotoSearch.Search(searchTerm)
                                    : PhotoSearch.Search(searchTerm, searchField);
            }
            else if (type == "default")
            {
                _searchResults = string.IsNullOrEmpty(searchField)
                                    ? PhotoSearch.SearchDefault(searchTerm)
                                    : PhotoSearch.SearchDefault(searchTerm, searchField);
            }


            List <SearchResultShoots> searchResultShoots = new List <SearchResultShoots>();

            foreach (var searchContent in _searchResults)
            {
                if (searchResultShoots.Count == 0)
                {
                    SearchResultsPhotos photo = new SearchResultsPhotos();
                    photo.fileName  = searchContent.fileName;
                    photo.photoSrc  = searchContent.photoSrc;
                    photo.photoHref = searchContent.photoHref;

                    SearchResultShoots shoot = new SearchResultShoots();
                    shoot.name         = searchContent.shootName;
                    shoot.shootHref    = searchContent.shootHref;
                    shoot.ListOfPhotos = new List <SearchResultsPhotos>();
                    shoot.ListOfPhotos.Add(photo);
                    searchResultShoots.Add(shoot);
                }
                else
                {
                    bool Found = false;
                    foreach (var resultsAlreadyIn in searchResultShoots)
                    {
                        if (resultsAlreadyIn.name == searchContent.shootName)
                        {
                            SearchResultsPhotos photo = new SearchResultsPhotos();
                            photo.fileName  = searchContent.fileName;
                            photo.photoSrc  = searchContent.photoSrc;
                            photo.photoHref = searchContent.photoHref;
                            resultsAlreadyIn.ListOfPhotos.Add(photo);
                            Found = true;
                        }
                    }
                    if (!Found)
                    {
                        SearchResultsPhotos photo = new SearchResultsPhotos();
                        photo.fileName  = searchContent.fileName;
                        photo.photoSrc  = searchContent.photoSrc;
                        photo.photoHref = searchContent.photoHref;

                        SearchResultShoots shoot = new SearchResultShoots();
                        shoot.name         = searchContent.shootName;
                        shoot.shootHref    = searchContent.shootHref;
                        shoot.ListOfPhotos = new List <SearchResultsPhotos>();
                        shoot.ListOfPhotos.Add(photo);
                        searchResultShoots.Add(shoot);
                    }
                }
                totalResults++;
            }
            if (checkbox != "on") //shoot seach
            {
                return(View(new PhotoIndexViewModel
                {
                    SampleSearchResults = searchResultShoots,
                    SearchTerm = searchTerm,
                    AllSearchIndexData = _searchResults
                }));
            }
            else // photo search
            {
                bool endResults = false;
                int  tPage      = totalResults;

                if (totalResults > 0)
                {
                    tPage = totalResults / 50;
                }
                if (PageIndex < 0)
                {
                    PageIndex = 0;
                }
                else
                {
                    PageIndex += 50;
                }
                if (PageIndex >= totalResults)
                {
                    tPage = PageIndex;
                }

                return(View("PhotoSearchResults",
                            new PhotoIndexViewModel {
                    SampleSearchResults = searchResultShoots,
                    SearchTerm = searchTerm,
                    AllSearchIndexData = _searchResults,
                    PageIndex = PageIndex,
                    totalPages = tPage,
                }
                            ));

                //PageIndex is how many photos are being displayed
            }
        }
 public IActionResult Get([FromQuery] PhotoSearch search, [FromServices] IGetPhotosQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }