Esempio n. 1
0
        public void Search(string searchTerm, string searchField, bool?searchDefault, int?limit)
        {
            List <SampleData> _searchResults;


            _searchResults = (string.IsNullOrEmpty(searchField)
                                ? LuceneSearch.Search(searchTerm)
                                : LuceneSearch.Search(searchTerm, searchField)).ToList();
            if (string.IsNullOrEmpty(searchTerm) && !_searchResults.Any())
            {
                _searchResults = LuceneSearch.GetAllIndexRecords().ToList();
            }


            // limit display number of database records
            var limitDb = limit == null ? 3 : Convert.ToInt32(limit);
            List <SampleData> allSampleData;

            if (limitDb > 0)
            {
                allSampleData = SampleDataRepository.GetAll().ToList().Take(limitDb).ToList();
            }
            else
            {
                allSampleData = SampleDataRepository.GetAll();
            }


            var AllSampleData   = allSampleData;
            var SearchIndexData = _searchResults;
        }
Esempio n. 2
0
        public ActionResult UpdateIndex()
        {
            LuceneSearch.ClearLuceneIndex();
            var x = SampleDataRepository.GetAll();

            LuceneSearch.AddUpdateLuceneIndex(x);
            return(RedirectToAction("Index"));
        }
        private DefaultViewModel getDefaultViewModel(string searchTerm, string searchField, string type = "")
        {
            // create default Lucene search index directory
            if (!Directory.Exists(GoLucene._luceneDir))
            {
                Directory.CreateDirectory(GoLucene._luceneDir);
            }

            // perform Lucene search
            IEnumerable <SampleData> searchResults = new List <SampleData>();

            if (string.IsNullOrEmpty(type))
            {
                searchResults = string.IsNullOrEmpty(searchField)
                           ? GoLucene.Search(searchTerm)
                           : GoLucene.Search(searchTerm, searchField);
            }
            else if (type == "default")
            {
                searchResults = string.IsNullOrEmpty(searchField)
                           ? GoLucene.SearchDefault(searchTerm)
                           : GoLucene.SearchDefault(searchTerm, searchField);
            }

            // setup and return view model
            var search_field_list = new
                                    List <SelectedList> {
                new SelectedList {
                    Text = "(All Fields)", Value = ""
                },
                new SelectedList {
                    Text = "Id", Value = "Id"
                },
                new SelectedList {
                    Text = "Name", Value = "Name"
                },
                new SelectedList {
                    Text = "Description", Value = "Description"
                }
            };

            return(new DefaultViewModel {
                AllSampleData = SampleDataRepository.GetAll(),
                AllSearchIndexData = GoLucene.GetAllIndexRecords(),
                SampleData = new SampleData {
                    Id = 9, Name = "El-Paso", Description = "City in Texas"
                },
                SampleSearchResults = searchResults,
                SearchFieldList = search_field_list,
            });
        }
Esempio n. 4
0
 public ActionResult CreateIndex()
 {
     GoLucene.AddUpdateLuceneIndex(SampleDataRepository.GetAll());
     TempData["Result"] = "Search index was created successfully!";
     return(RedirectToAction("Index"));
 }
Esempio n. 5
0
        public ActionResult Index
            (string searchTerm, string searchField, bool?searchDefault, int?limit)
        {
            // create default Lucene search index directory
            if (!Directory.Exists(GoLucene._luceneDir))
            {
                Directory.CreateDirectory(GoLucene._luceneDir);
            }

            // perform Lucene search
            List <SampleData> _searchResults;

            if (searchDefault == true)
            {
                _searchResults = (string.IsNullOrEmpty(searchField)
                           ? GoLucene.SearchDefault(searchTerm)
                           : GoLucene.SearchDefault(searchTerm, searchField)).ToList();
            }
            else
            {
                _searchResults = (string.IsNullOrEmpty(searchField)
                           ? GoLucene.Search(searchTerm)
                           : GoLucene.Search(searchTerm, searchField)).ToList();
            }
            if (string.IsNullOrEmpty(searchTerm) && !_searchResults.Any())
            {
                _searchResults = GoLucene.GetAllIndexRecords().ToList();
            }


            // setup and return view model
            var search_field_list = new
                                    List <SelectedList> {
                new SelectedList {
                    Text = "(All Fields)", Value = ""
                },
                new SelectedList {
                    Text = "Id", Value = "Id"
                },
                new SelectedList {
                    Text = "Name", Value = "Name"
                },
                new SelectedList {
                    Text = "Description", Value = "Description"
                }
            };

            // limit display number of database records
            var limitDb = limit == null ? 3 : Convert.ToInt32(limit);
            List <SampleData> allSampleData;

            if (limitDb > 0)
            {
                allSampleData = SampleDataRepository.GetAll().ToList().Take(limitDb).ToList();
                ViewBag.Limit = SampleDataRepository.GetAll().Count - limitDb;
            }
            else
            {
                allSampleData = SampleDataRepository.GetAll();
            }

            return(View(new IndexViewModel {
                AllSampleData = allSampleData,
                SearchIndexData = _searchResults,
                SampleData = new SampleData {
                    Id = 9, Name = "El-Paso", Description = "City in Texas"
                },
                SearchFieldList = search_field_list,
            }));
        }
 private void createIndex()
 {
     GoLucene.AddUpdateLuceneIndex(SampleDataRepository.GetAll());
     litResult.Text = "Search index was created successfully!";
     bindData();
 }
Esempio n. 7
0
 public void CreateIndex()
 {
     LuceneSearch.AddUpdateLuceneIndex(SampleDataRepository.GetAll());
 }