public ActionResult Index(Models.Search model)
        {
            if (!string.IsNullOrEmpty(model.Phrase))
            {

                //// Use this style query to search for documents - it returns all results
                //// including those matching only some of the terms
                //Query query = new QueryParser(
                //        Lucene.Net.Util.Version.LUCENE_29,
                //        "title",
                //        new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)
                //    ).Parse(model.Phrase);

                // Use this style query for products - all of the terms entered must match.
                QueryParser parser = new QueryParser(
                        Lucene.Net.Util.Version.LUCENE_29,
                        "title",
                        new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)
                    );

                //ISynonymEngine engine = new SpecialSynonymEngine();

                //// Same as above, but modified to handle synonyms
                //QueryParser parser = new QueryParser(
                //        Lucene.Net.Util.Version.LUCENE_29,
                //        "title",
                //        new SynonymAnalyzer(Lucene.Net.Util.Version.LUCENE_29, engine)
                //    );

                // This ensures all words must match in the phrase
                parser.SetDefaultOperator(QueryParser.Operator.AND);

                // This ensures similar words will match
                //parser.SetPhraseSlop(3);

                // Sets the current culture
                parser.SetLocale(System.Threading.Thread.CurrentThread.CurrentCulture);
                Query query = parser.Parse(model.Phrase);

                // Use query.Combine to merge this query with individual facets ??

                //// Get the terms from the query
                //string[] terms = model.Phrase.Split(" ".ToCharArray());

                //PhraseQuery query = new PhraseQuery();
                //query.SetSlop(4);

                //foreach (var term in terms)
                //{
                //    query.Add(new Term("title", term));
                //}

                BrowseResult result = this.PerformSearch(query, this.IndexDirectory, null);

                //// Build results for display
                //int totalHits = result.NumHits;
                //BrowseHit[] hits = result.Hits;

                //model.Hits = result.Hits;
                //model.FacetMap = result.FacetMap;
                ////model.TotalHitCount = totalHits;

                PopulateModelResult(model, result);
            }

            return View(model);
        }
Ejemplo n.º 2
0
		private void  AssertHits(int expected, System.String query, IndexSearcher is_Renamed)
		{
			QueryParser qp = new QueryParser("date", new WhitespaceAnalyzer());
			qp.SetLocale(new System.Globalization.CultureInfo("en-US"));
			Query q = qp.Parse(query);
			ScoreDoc[] hits = is_Renamed.Search(q, null, 1000).ScoreDocs;
			Assert.AreEqual(expected, hits.Length);
		}
        public ActionResult SubmitSearchSelections(Models.Search model)
        {
            // Use this style query for products - all of the terms entered must match.
            QueryParser parser = new QueryParser(
                    Lucene.Net.Util.Version.LUCENE_29,
                    "title",
                    new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)
                );

            // This ensures all words must match in the phrase
            parser.SetDefaultOperator(QueryParser.Operator.AND);

            // This ensures similar words will match
            //parser.SetPhraseSlop(3);

            // Sets the current culture
            parser.SetLocale(System.Threading.Thread.CurrentThread.CurrentCulture);
            Query query = parser.Parse(model.Phrase);

            // Use query.Combine to merge this query with individual facets

            BrowseResult result = this.PerformSearch(query, this.IndexDirectory, model.SelectionGroups);

            //// Build results for display
            //int totalHits = result.NumHits;
            //BrowseHit[] hits = result.Hits;

            //model.Hits = result.Hits;
            //model.FacetMap = result.FacetMap;
            ////model.TotalHitCount = totalHits;

            PopulateModelResult(model, result);

            return Json(model, "application/json");

            //return View("Index", new Models.Search());
        }