Skip to content

Instantly share code, notes, and snippets.

@MadsBuus
Created June 5, 2013 11:12
Show Gist options
  • Save MadsBuus/5713165 to your computer and use it in GitHub Desktop.
Save MadsBuus/5713165 to your computer and use it in GitHub Desktop.
revised goto-strategy
def goto_result
return nil unless @goto_search and autolink_match?
options = { queries: autolink_query, sort: 'chunkno asc', rows: 100, fl: 'topid,docid,chunkno,docverstype,productkeys' }
hits = Solr::Chunk.find(options)
if hits.docs.empty?
hits = Solr::Chunk.find(options, :searchable)
end
chunks = hits.docs.sort_by { |d| [ Document::PREFERRED_DOCVERSTYPE_ORDER.index(d[:docverstype]), d[:chunkno].to_i ] }
uniq_documents = chunks.uniq { |c| c[:topid] }
# only return first if its the only one of its kind
chunks.first unless uniq_documents.select { |d| d['docverstype'] == chunks.first['docverstype'] && !(d['ophmark'] == '1' or d['histmark'] == '1' or d['histprod'] == '1') }.size > 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment