0

I've been wondering lately if the xml that Solr returns from a search isn't actually "true" xml, and by true, I mean searchable in the the sense that you can normally pull specific nodes from an xml document and return only that information.

I've been trying to figure out a way to make my responses from solr be more human-friendly. Solr will index my pdfs and dump the output from the pdfs into a _content node, and I can return that node on the screen which is all fine and well.

Even using highlighting in my queries though, it's still pretty unreadable by any useful standards.

Consider the following response to a query.

<response>
    <lst name="responseHeader">
         <int name="status">0</int>
         <int name="QTime">57</int>
         <lst name="params">
               <str name="q">_content:[search term]</str>
               <str name="hl">on</str>
               <str name="fl">_content</str>
               <str name="hl.fl">_content</str>
    </lst></lst>

    <result name="response" numFound="5" start="0">
         <doc>
               <arr name="_content">
                   <str>[block of content here with zero formatting]</str>
               </arr>
          </doc>
    </result>

While I'm glad that solr returned a response, it's really not very useful. I would have to have it return something that I could style with html and look presentable to the user.

I'm not currently using any custom search indexes...is that would I would need to do to be able to return something that I can mold and shape?

thanks!

2

If you use Sitecore, then you don't need to deserialize the response from Solr. For that Sitecore has an API for it. Offical documentation is here about LINQ to Sitecore.

LINQ to Sitecore provides access to search the indexes, using standard LINQ queries in the same way that other LINQ providers, such as LINQ to SQL and LINQ to Objects, work. It uses the standard IQueryable interface and supports most of the available operations.

Sitecore supports two search providers: Lucene and Solr. The LINQ layer is an abstract layer that converts common queries to something that these search providers understand.

Basicly the query above will look like this:

using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
{
    IQueryable<SearchResultItem> searchQuery = context
        .GetQueryable<SearchResultItem>()
        .Where(item => item.Content.Contains("[search term]"))
}

Worth to read the more about Sitecore Search API. Here is also a good post about it: https://soen.ghost.io/a-re-introduction-to-the-contentsearch-api-in-sitecore-part-1/

  • I will do some research into LINQ as well, I'm not familar with it. – Nick Feb 1 '18 at 22:31
1

In addition to Sitecore's ContentSearch as Tamas mentioned, you can use SolrNet library. It makes your life so much easier. It acts as a wrapper for all communications with Solr and you should be able to do all your shaping as you wish using simple models that map your index fields

Check this page for its basic usage or this article

  • Thanks, I will look into solrNet. I'm not too familiar with it. – Nick Feb 1 '18 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.