You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2008/07/01 09:35:55 UTC
[Solr Wiki] Update of "SolrJS" by MatthiasEpheser
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The following page has been changed by MatthiasEpheser:
http://wiki.apache.org/solr/SolrJS
------------------------------------------------------------------------------
The library is written using the javascript toolkit jQuery [http://jquery.com/] (Version 1.2.5). SolrJS is included in one additional javascript file "solrjs.js" The idea is to create several (reusable and extensible) "widgets" that represent solr queries. 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. This method creates a dynamic script tag, making cross-domain solr requests possible.
- === Examples for widgets ===
+ == Examples and source code ==
- * Result widget: displaying a pageable view of the current result.
- * Facet widget: Create a faceted selection menu for one field in the solr document
+ The best way to get an idea how a widget may look like and how it can be integrated into html is to explore the documented source code and the test*.html example pages at [http://solrstuff.org/svn/solrjs/trunk].
+
+ Despite this, I'll try to describe some important implementation further on this page.
== Implementation ==
@@ -29, +30 @@
<script src="solrjs.js"/>
<script> var $sj = jQuery.noConflict(); </script>
}}}
- After that, all objects are accessible using $sj.solrjs.*
+ After that, all SolrJS objects are accessible using $sj.solrjs.*
=== The manager object ===
@@ -39, +40 @@
* addQueryItems: add a list of field:value pairs that restrict the current query
* removeQueryItems: remove the given items from the current query
* doRequest(start): performs the actual solr requests
+ * doRequestAll(): clears queryItems and requests all documents
==== How a query request works ====
@@ -112, +114 @@
}}}
+ === Example for an easily customized widget: ExtensibleResultWidget ===
-
+ The ExtensibleResultWidget is a showcase of a flexible widget. It provides 2 abstract methods:
+ * renderDataItem
+ * renderPageStatus
+
+ After the document result for the current page is returned, these methods are called and the user is able to use custom javascript code to render the result properly.
+
+ {{{
+
+ javascript:
+
+ var resultWidget = new $sj.solrjs.ExtensibleResultWidget({
+ id:"result",
+ target:"#result",
+ rows:20,
+ renderDataItem : function(item) {
+ jQuery('<div/>').html(item.id).appendTo(this.target);
+ // more custom code for rendering one single result item
+ },
+ renderPageStatus : function(first, last, total) {
+ // custom code for rendering the pagination status
+ jQuery('#pageStatus_start').html(first + "");
+ jQuery('#pageStatus_last').html(last + "");
+ jQuery('#pageStatus_total').html(total + "");
+ var navigation = $sj('#navigation').html("");
+ var pageSize = last - first + 1;
+ var lastpageFirst = Math.ceil(total / pageSize) * pageSize - pageSize;
+ // create navigation buttons for paging
+ }
+ });
+ solrjsManager.addWidget(resultWidget);
+
+
+ html:
+
+ <body>
+ <div id="pageStatus">
+ Showing <span id="pageStatus_start"></span> to <span id="pageStatus_last"></span> of <span id="pageStatus_total"></span>
+ </div>
+ <div id="navigation"></div>
+ <div id="result"></div>
+ </body>
+
+
+
+ }}}
+