More in this section

Forums / Developing with Sitefinity / Search Sitefinity content from C#

Search Sitefinity content from C#

2 posts, 0 answered
  1. Nagendra
    Nagendra avatar
    28 posts
    Registered:
    07 Jun 2010
    28 Jun 2010
    Link to this post
    Hi,

    I have setup a Sitefinity 3.7 successfully and created some of the categories, content. I have also configured the search Index and able to search the pages from Sitefinity site. 
    But I am unable to find a way for the following items using the API:

    1. Search the content from C# code using API.
    2. How to search the text inside the documents uplaoded in Sitefinity using API.

    Please provide some sample C# code for searching the content using the API.
    Any help on this would be very much appreciable.

    Thanks,
    Nagen
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jun 2010
    Link to this post
    Hi Nagendra,

    You can take a look at this blog post which shows how to use the API to perform a search.
    Searching text inside items uploaded to Images and Documents module is not supported out of the box.
    There is no built-in search index for Images and Documets module. You need to create a custom one. You could take a look at this blog post - In the mean time series (part 4): BONUS TRACK - "Products" module - implementing search index

    To extract text form any document you should use a 3rd party framework to extract the content of the files. We have API that will allow you to index the content, but we do not have API that allows you to extract the content from the PDF files. You could use some open source libraries as Apache PDFBox or iTextSharp.


    Sample code that uses ApachePDFBox - note we do not provide development support for this library

    PDDocument doc = null;
    java.io.InputStream stream = null;
    stream = new java.io.ByteArrayInputStream((Byte[])item.Content);
     doc = PDDocument.load(stream);
     if (stream != null)
     {
         stream.close();
     }
       
     PDFTextStripper stripper = new PDFTextStripper();
     String sText = String.Empty;
       
     if (doc != null)
     {
         sText = stripper.getText(doc);
     }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered