示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            rawQuery = Request.QueryString["text"];
            if (rawQuery == null)
            {
                return;
            }
            int page;

            int.TryParse(Request.QueryString["page"], out page);
            var rankResults = Request.QueryString["rank"] != null;

            text.Value   = rawQuery;
            rank.Checked = rankResults;
            var paradigms         = new List <Paradigm[]>();
            var selectedParadigms = new List <int>();

            terms = new List <string>();
            var parsedQuery        = RawQueryParser.Parse(rawQuery, paradigms, selectedParadigms, terms);
            IEnumerable <Hit> hits = Search(parsedQuery, page, rankResults);

            if (hits.Count() != 0)
            {
                rptSearchResults.Visible    = true;
                rptSearchResults.DataSource = hits;
                rptSearchResults.DataBind();
                BuildParadigms(paradigms, selectedParadigms);
            }
            else
            {
                lblNoData.Visible = true;
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string documentId = Request.QueryString["id"];

            if (documentId.Any(x => !char.IsDigit(x)))
            {
                GoAway();
            }
            Document document;

            try
            {
                document = new Document(documentId);
            }
            catch
            {
                GoAway();
                return;
            }
            string sourceQuery = Request.QueryString["sourceQuery"];
            var    highlighter = new TermHighlighter(
                RawQueryParser.Parse(sourceQuery, null, null, null).TermsWithSynonyms,
                "<span style='background-color: yellow'>",
                "</span>");

            if (!string.IsNullOrEmpty(sourceQuery))
            {
                document.Content = document.Content.Select(x => highlighter.Highlight(x));
            }
            string finalText = string.Join("", document.Content.Select(x => string.Format("<div>{0}</div>", x)).ToArray());

            lblOriginalText.Text = string.Format("<h1>{0}</h1><div>{1}</div>", highlighter.Highlight(document.Title), finalText);
        }
示例#3
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: IndexStats index-dir action [args]");
                Environment.Exit(1);
            }
            var index  = Index.Load(args[0]);
            var action = args[1];

            if (action == "termDocs")
            {
                var term  = args[2];
                var query = new ParsedQuery {
                    TermsWithSynonyms = new[] { new[] { term } }
                };
                Console.WriteLine(string.Join(" ", index.GetPostingsByQuery(query).Select(x => x.PostingId.ToString()).ToArray()));
            }
            else if (action == "playGame")
            {
                var urls = File.ReadAllLines("urls.txt");
                using (var output = new StreamWriter("ranking.txt"))
                {
                    var reqNum = 0;
                    foreach (var req in File.ReadAllLines("requests.txt"))
                    {
                        var parsedQuery = RawQueryParser.Parse(req, null, null, null, new MorphologyAnalyzer("127.0.0.1"));
                        var results     = index
                                          .GetPostingsByQuery(parsedQuery)
                                          .Rank()
                                          .Take(10);
                        var pos = 0;
                        foreach (var res in results)
                        {
                            output.WriteLine("{0} {1} {2}", reqNum, pos, urls[res.PostingId - 1]);
                            pos++;
                        }
                        reqNum++;
                    }
                }
            }
        }