views:

72

answers:

4

I have SOLR configured to return fragments with a fragsize of 500.

Sometimes, the whole field is 500 characters or less, so the fragment is identical to the field. For fields that are longer than that, SOLR just returns the fragment without any indication (or so it seems) that the fragment only represents part of the content of a field. That means the fragment could start mid-sentence.

I want to make it clear to users that they're looking at a fragment and simply display ellipsis at the end and/or start of such a fragment. Is that functionality built into SOLR? If not, how would you go about inserting ellipsis?

A: 

Solr won't return an indicator, you're right.

Set your fragsize to 501. Then its a quick bit of logic in your UI to determine whether ellipsis should be displayed or not.

Truncate anything 501 to 500 and add ellipsis.

kareem
Yeah, I was just hoping that there is a built-in way to do that.Also, that still leaves me with the problem of not knowing whether to display the ellipsis at the beginning or the end of the fragment (or both).
Stefan
A: 

Here's another better approach. While creating the index, add a "teaser" attribute that has this logic already applied. Push that effort out of your requests altogether. That's exactly how I would do this.

kareem
At index-time you don't know which part of the field matches and thus, what the fragment is going to be.
Stefan
A: 

What I ended up doing was returning both the fragment and the unaltered field from which the fragment was created.

I then wrote some logic that compared the two in order to determine whether ellipsis should be added to the fragment and if so, whether to add it before, after or both before and after the fragment.

Stefan
A: 

I just dealt with the same issue. The way I went about doing this is the following:

  1. Get the original string
  2. Get both the first and last 10 characters of the original string
  3. Get both the first and last 10 characters of the fragment returned by the Solr search
  4. Compare both, and fill in a variable when needed!

    $f_ellip = NULL;
    $l_ellip = NULL;
    if ($orig_body_beggining != substr((string)$hl_content->str, 0, 10)) {
        $f_ellip = "… ";
    }
    if ($orig_body_end != substr((string)$hl_content->str, 0, -10)) {
         $l_ellip = " …";
    }
    $entry_body = $f_ellip.(string)$hl_content->str.$l_ellip;
    
fholgado