lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yuhao <nfsvi...@yahoo.com>
Subject Re: Help: Creating another handler and template to display document attributes
Date Thu, 02 Feb 2012 15:22:22 GMT
Erik,

Thanks for the slides.  I followed the example on pages 24-25 (maybe too rigidly).  The
first line is giving me trouble:

#set($doc= $response.results.get(0))

This will always get the first document in the search results, which happens to be the first
document I indexed.  So, no matter which record I click on, I'm always taken to the details
of that first record.  I can't get to any other record even though I pass their ID to the
new handler.  So, my question is, is the line above supposed to give me the record I passed
the ID for, or is it just an example to get "some" record?

Here are the details of my implementation:
(I realize I've got a space in the ID field "Entrez ID".  However, that doesn't seem to be
the problem since it was able to get the first record)

I defined a SearchHandler named "/details".  Example url: http://localhost:920/solr/details?id=7391


schema.xml:
================================================
  <requestHandler name="/details" class="solr.SearchHandler">
     <lst name="defaults">
       <!-- VelocityResponseWriter settings -->
       <str name="wt">velocity</str>

       <str name="v.template">details</str>
       <str name="v.template.header">__this is configured in solrconfig.xml, str
name="v.template.header"__</str>
       <str name="v.layout">layout</str>
       <str name="title">Details</str>

       <str name="q">{!raw f="Entrez ID" v=$id}</str>

       <str name="facet">on</str>
       <str name="facet.limit">10</str>
       <str name="facet.sort">count</str>
       <str name="facet.field">Gene_Ontology_Associations</str>
       <str name="facet.field">Mouse_Phenotype_Associations</str>
       <str name="facet.field">BKL_Diagnostic_Marker_Associations</str>
       <str name="facet.field">BKL_Molecular_Mechanism_Associations</str>
       <str name="facet.field">BKL_Therapeutic_Target_Associations</str>
       <str name="facet.field">BKL_Negative_Correlation_Associations</str>
       <str name="facet.field">GAD_Positive_Disease_Associations</str>
       <str name="facet.field">GAD_Negative_Disease_Associations</str>
       <str name="facet.field">HuGENet_GeneProspector_Associations</str>
       <str name="facet.field">Expression_Specificity_according_to_GNF</str>
       <str name="facet.field">OMIM_Clinical_Synopses_Matches</str>
       <str name="facet.field">OMIM_Full_Text_Matches</str>
       <str name="facet.mincount">1</str>

       <!-- Highlighting defaults -->
       <str name="hl">on</str>
       <str name="hl.fl">text features name</str>
       <str name="f.name.hl.fragsize">0</str>
       <str name="f.name.hl.alternateField">name</str>
     </lst>
     <arr name="last-components">
       <str>spellcheck</str>
     </arr>
     <!--
     <str name="url-scheme">httpx</str>
     -->
  </requestHandler>



details.vm
=============================================
#set($doc= $response.results.get(0))
<span><a href="$doc.getFieldValue('Entrez ID')">$doc.getFieldValue('Entrez ID')</a></span>
<table>
#foreach($fieldname in $doc.fieldNames)
<tr>
<td>$fieldname:</td>
<td>
#foreach($value in $doc.getFieldValues($fieldname))
$esc.html($value)
#end
</td>
</tr>
#end
</table>




________________________________
 From: Erik Hatcher <erik.hatcher@gmail.com>
To: solr-user@lucene.apache.org 
Sent: Wednesday, February 1, 2012 8:26 PM
Subject: Re: Help: Creating another handler and template to display document attributes
 
I'm not following exactly what you're after here in detail, but I think this will help:

   <http://www.slideshare.net/erikhatcher/rapid-prototyping-with-solr-5675936>

See slides 24 and 25.  Note the use of $id in the /document request handler definition using
parameter substitution, a really cool technique.

    Erik

On Feb 1, 2012, at 17:17 , Yuhao wrote:

> Like the title says, I want to create a "page" to display a bunch of document attributes. 
I accomplished this by creating a new handler and a template for it.  However, I'm having
trouble pulling up the details of the document in the new handler.  Here's my code.  Is
this a good way to do it?  I first pass the doc ID to the handler, which I then use to pull
up the details.  
> 
> 
> ********************************* BEGIN *******************************
> #set($id = $params.get("id"))
> ## Note: id is the same thing as "Entrez ID"
> 
> 
> #foreach ($doc in $response.results)
>   #if ($doc.getFieldValue('Entrez ID') == $id) ## Only show attrs for the current doc
>     #foreach ($field_name in $doc.getFieldNames())
>       <b>$field_name</b>: $doc.getFieldValue($field_name)<br/><br/>
>     #end
>   #end
> #end
> ********************************* END *******************************
> 
> 
> This approach requires the document to be in the search results.  The way I pass the
ID to the handler right now, is to simply add "id=$id" to the URL, without the rest of the
querystring that was used to conceive the current query.  I need to get the rest of the querystring
and pass them along to the handler to ensure the document is in the search result.  However,
I don't know of a good way.  I tried the following code:
> 
> #set($querystring = "")
> #foreach ($param in $request.params.getParameterNamesIterator())
>   #set($querystring = $querystring + "&$param=$esc.url($request.params.get($param))"
)
> #end
> 
> 
> Unfortunately, the above code returns a lot of unnecessary params that are not part of
the querystring, and it fails to put the document in the search result.  Is there a better
way to get the URL querystring (and just the querystring, not other environment parameters)?
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message