locked
Make Search result dynamically load and append RRS feed

  • Question

  • User325035487 posted

    My current working solution goes like this

    if (IsPost)
            {
                if (Request["Search"] != null)
                {
                    var search = Request.Form["searchcontent"];
                    var sqlppgs = "SELECT PPGIndex,PdfFileName,CatCode,PPGTitle FROM PPGs p INNER JOIN PPGCat c ON p.PPCID=c.PPCID WHERE p.Hospital_Id=@0";
                    var ppgs = db.Query(sqlppgs, hospital_temp);
                    foreach (var r in ppgs)
                    {
                        string filename = Server.MapPath("~/App_Data/PPG/" + r.CatCode + "/" + r.PdfFileName);
                        int pdfmatch = Functions.SearchPdfFile(filename, search);
                        if (pdfmatch !=0)
                        {
                            string title = r.PPGTitle;
                            string url = "/PPG/" + r.CatCode + "/" + r.PdfFileName;
                            <tr class="indexColumn">
                                <td>@r.PPGIndex</td>
                                <td><a href="PPG/Download.ashx?File=@url" target="_blank">@title.Replace("-", " ")</a> on page: @pdfmatch</td>
                            </tr>
                        }
                    }
                }
            }

    The Function is like this

     public static int SearchPdfFile(string fileName, String searchText)
     {
         if (!File.Exists(fileName))
             throw new FileNotFoundException("File not found", fileName);
    
         using (iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(fileName))
         {
             var strategy = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
    
             for (int page = 1; page <= reader.NumberOfPages; page++)
             {
                 var currentPageText = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page, strategy);
                 if (currentPageText.Contains(searchText))
                 {
                     return page;
                 }               
             }
         }
         return 0;
     }

    This searches through about 1000 pdfs and returns the page number. But takes about a minute.

    I am wondering if its possible to use jquery or ajax to populate the results one row at a time as the search function finds it. I use the iTextSharp library

    Tuesday, November 3, 2015 3:35 PM

Answers

  • User-84896714 posted

    Hi jkjhse,

    I am wondering if its possible to use jquery or ajax to populate the results one row at a time as the search function finds it. I use the iTextSharp library

    Yes, you could use ajax to send a async request to server and update your html when data received from server. Code below is for your reference.

    <script type="text/javascript">
        $(document).ready(function () {
            $("#search").click(function () {
                var keywords = "";
                var files = [];
                for (var i = 0; i < files.length; i++) {
                    $.post("url", { file: files[i], key: keywords }, function (data) {
                        //update html accroding data
                    });
                }
            });
        });
    </script>

    Best Regards,
    Wang Li

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 12, 2015 4:39 AM

All replies

  • User-84896714 posted

    Hi jkjhse,

    I am wondering if its possible to use jquery or ajax to populate the results one row at a time as the search function finds it. I use the iTextSharp library

    Yes, you could use ajax to send a async request to server and update your html when data received from server. Code below is for your reference.

    <script type="text/javascript">
        $(document).ready(function () {
            $("#search").click(function () {
                var keywords = "";
                var files = [];
                for (var i = 0; i < files.length; i++) {
                    $.post("url", { file: files[i], key: keywords }, function (data) {
                        //update html accroding data
                    });
                }
            });
        });
    </script>

    Best Regards,
    Wang Li

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 12, 2015 4:39 AM
  • User325035487 posted

    Thank you

    Tuesday, November 17, 2015 12:25 PM