Created
June 5, 2013 11:12
-
-
Save MadsBuus/5713165 to your computer and use it in GitHub Desktop.
revised goto-strategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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