projectblacklight / blacklight

Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr) index.
http://projectblacklight.org/
Other
757 stars 255 forks source link

Solr configuration for more_like_this #1558

Open beyto1974 opened 7 years ago

beyto1974 commented 7 years ago

I can't find any information besides https://groups.google.com/forum/#!topic/blacklight-development/V5U1n7iHjK4 about the activation of the more_like_this function. I also couldn't get it working.

Can a wiki page be created for this functionality?

beyto1974 commented 7 years ago

Hi,

In app/models/concerns/blacklight/document.rb I read:

#Implementations that support More-Like-This should override this method
#to return an array of documents that are like this one.
def more_like_this
 []
end

In my model:

  def more_like_this
    solr = RSolr.connect :url => 'http://localhost:8983/solr/blacklight-core/'
      solrMLTResponse = solr.get 'mlt', :params => {:q => 'id:'+self.id, :'mlt.fl' => 'subject_t', :rows => 5}

    list=[]
    solrMLTResponse['response']['docs'].each { |doc|
      doc=SolrDocument.new(doc)
      list.push(doc)
    }
    return list;
  end

In solrconfig.xml:

<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
        <str name="mlt">true</str>
        <str name="mlt.fl">subject_t</str>
        <str name="mlt.count">5</str>
        <str name="mlt.mintf">1</str>
        <str name="mlt.qf">person_t^5</str>
  </requestHandler>

Works.

atz commented 7 years ago

Is this a request for documentation or is there additional code that needs to be integrated for the feature to be exposed in a Blacklight app?

beyto1974 commented 7 years ago

Hi, A request for documentation.