#1




Solr and symfony in Harmony with SolrJs
                Doc. v. 0.1 - 21/04/09




                 Wildan Maulana ...
About SolrJs
• SolrJS is a JQuery based ajaxian
  interface to the Solr search engine
• One of the 2008 Google summer of
 ...
About SolrJs - Cont


• Written In Object
  Oriented JavaScript
Architectural Overview
    SolrJS → a collection of reusable and extendable “widget”
•
    A widget is a javascript object...
The Manager Object
    addSelectionView(widget)
•
    Adds a selection view to this manager.
    addWidget(widget)
•
    A...
Example
Document
<REUTERS TOPICS=quot;YESquot; LEWISSPLIT=quot;TRAINquot; CGISPLIT=quot;TRAINING-SETquot; OLDID=quot;5544quot; NEW...
Response Example on SolrAdmin: Cocoa

<response>                                        <str>SV</str>
<lst name=quot;respo...
Action and Template
Minimalistic Action

 public function executeJs() {
    return sfView::SUCCESS ;
 }


The Template

<d...
<html>
             <head>
The Layout   ...................
             ..............
             <script>
            ...
result.vm
   #foreach($item in $response.getResults())
    <div>
      <h3> $item.getFieldValue(quot;titlequot;); </h3>
  ...
facets.vm

#foreach($item in $response.getFacetFields())
 <div>
   #foreach($count in $item.getValues())
    <a href=quot;...
References
• SolrJS Wiki,
  http://wiki.apache.org/solr/SolrJS
Solr and symfony in Harmony with SolrJs
Upcoming SlideShare
Loading in …5
×

Solr and symfony in Harmony with SolrJs

1,237 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,237
On SlideShare
0
From Embeds
0
Number of Embeds
67
Actions
Shares
0
Downloads
21
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Solr and symfony in Harmony with SolrJs

  1. 1. #1 Solr and symfony in Harmony with SolrJs Doc. v. 0.1 - 21/04/09 Wildan Maulana | wildan [at] tobethink.com
  2. 2. About SolrJs • SolrJS is a JQuery based ajaxian interface to the Solr search engine • One of the 2008 Google summer of code project topic • Still work in progress but already been useable, watch http://wiki.apache.org/solr/SolrJS for newest info
  3. 3. About SolrJs - Cont • Written In Object Oriented JavaScript
  4. 4. Architectural Overview SolrJS → a collection of reusable and extendable “widget” • A widget is a javascript object that is responsible for creating the according • solr query as well as render the result from the server to html One manager object acts as a container that holds these widgets, performs • the actual query using jQueries getJSON http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback method There are two base types of widgets: • – client side widgets: They get a Javascript JSON response from the server and render the needed html for the widget using jQuery javascript code. – server side widgets: They move the rendering logic to the server, using the VelocityResponseWriter (see https://issues.apache.org/jira/browse/SOLR-620. The widget then only quot;copiesquot; the html reponse from the server into the target div. The Js files is organized in “packages” like in a Java Application: • – core: The manager and other base classes. – server: server side widgets – client: client side widgets
  5. 5. The Manager Object addSelectionView(widget) • Adds a selection view to this manager. addWidget(widget) • Adds a widget to this manager. containsItem(item) • Checks if the given item is available in the current selection. deselectItem(widgetId) • Removes the given item from the current selection, regardless of widgets. deselectItems(widgetId) • Removes the given items from the current selection. doRequest(start, resultsOnly) • Creates a query out of the current selection and calls all bound widgets to request their data from the server. doRequestAll() • Sets the current selection to *:* and requests all docs. getLoadingDiv() • Helper method that returns an ajax-loading.gif inside a div. selectItems(widgetId, items) • Adds the given items to the current selection.
  6. 6. Example
  7. 7. Document <REUTERS TOPICS=quot;YESquot; LEWISSPLIT=quot;TRAINquot; CGISPLIT=quot;TRAINING-SETquot; OLDID=quot;5544quot; NEWID=quot;1quot;> <DATE>26-FEB-1987 15:01:01.79</DATE> <TOPICS><D>cocoa</D></TOPICS> <PLACES><D>el-salvador</D><D>usa</D><D>uruguay</D></PLACES> <PEOPLE></PEOPLE> <ORGS></ORGS> <EXCHANGES></EXCHANGES> <COMPANIES></COMPANIES> <UNKNOWN> C T f0704reute u f BC-BAHIA-COCOA-REVIEW 02-26 0105</UNKNOWN> <TEXT> <TITLE>BAHIA COCOA REVIEW</TITLE> <DATELINE> SALVADOR, Feb 26 - </DATELINE> <BODY> content here ........ </BODY> </TEXT> </REUTERS>
  8. 8. Response Example on SolrAdmin: Cocoa <response> <str>SV</str> <lst name=quot;responseHeaderquot;> <str>US</str> <int name=quot;statusquot;>0</int> <str>UY</str> <int name=quot;QTimequot;>35</int> </arr> <lst name=quot;paramsquot;> <date name=quot;datequot;>1987-02-26T08:01:01.079Z</date> <str name=quot;indentquot;>on</str> <str name=quot;datelinequot;>SALVADOR, Feb 26 -</str> <str name=quot;startquot;>0</str> <str name=quot;idquot;>1</str> <str name=quot;qquot;>cocoa</str> <arr name=quot;placesquot;> <str name=quot;versionquot;>2.2</str> <str>el-salvador</str> <str name=quot;rowsquot;>10</str> <str>usa</str> </lst> <str>uruguay</str> </lst> </arr> <result name=quot;responsequot; numFound=quot;1quot; start=quot;0quot;> <str name=quot;textquot;> <doc> Content here ... <arr name=quot;allTextquot;> </str> <str>BAHIA COCOA REVIEW</str> <str name=quot;titlequot;>BAHIA COCOA REVIEW</str> <str> <arr name=quot;topicsquot;> Content here ... <str>cocoa</str> </str> </arr> <str>el-salvador</str> </doc> <str>usa</str> </result> <str>uruguay</str> </response> <str>cocoa</str> </arr> <arr name=quot;countryCodesquot;>
  9. 9. Action and Template Minimalistic Action public function executeJs() { return sfView::SUCCESS ; } The Template <div id=quot;facetsquot; style=quot;float: left; width: 300px;quot;> <h3 style=quot;margin-top: 0pxquot;>topics</h3> <div id=quot;topicsquot;></div> </div> <div id=quot;resultquot; style=quot;margin-left: 300px;quot;></div>
  10. 10. <html> <head> The Layout ................... .............. <script> var $sj = jQuery.noConflict(); </script> <script> var solrjsManager; $sj(document).ready(function(){ solrjsManager = new $sj.solrjs.Manager({solrUrl:quot;http://localhost:8983/solr/selectquot;}); // a custom result widget var resultWidget = new $sj.solrjs.SimpleServerSideWidget({ id:quot;resultquot;, target:quot;#resultquot;, rows:5, templateName:quot;resultquot; }); solrjsManager.addWidget(resultWidget); solrjsManager.addWidget(new $sj.solrjs.FacetServerSideWidget({id:quot;topicsquot;, target:quot;#topicsquot;, fieldName:quot;topicsquot;})); solrjsManager.doRequestAll(); }); </script> </head> <body> <?php echo $sf_content ?> </body> </html>
  11. 11. result.vm #foreach($item in $response.getResults()) <div> <h3> $item.getFieldValue(quot;titlequot;); </h3> #if($item.getFieldValue(quot;topicsquot;)) <p> <i> $item.getFieldValue(quot;topicsquot;);</i> </p> #end <p> $item.getFieldValue(quot;textquot;); </p> </div> <hr/> #end
  12. 12. facets.vm #foreach($item in $response.getFacetFields()) <div> #foreach($count in $item.getValues()) <a href=quot;javascript:solrjsManager.selectItems('$request.getParams() .get('solrjs.widgetid')',[new jQuery.solrjs.QueryItem({field:'$count.getFacetField() .getName()',value:'$count.getName()'})])quot;> $count.getName()($count.getCount()) </a><br/> #end </div> #end
  13. 13. References • SolrJS Wiki, http://wiki.apache.org/solr/SolrJS

×