-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sam
committed
May 5, 2012
1 parent
f109cfe
commit 358bbc0
Showing
10 changed files
with
381 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>solr_pager</name> | ||
<comment>Provides simple and fast paging for SOLR results</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
2011-08-25 Sam <samuel_._behan_(at)_dob_._sk> | ||
|
||
* version 0.2.4 for apache-solr-3.3.0 | ||
|
||
2010-07-22 Sam <samuel_._behan_(at)_dob_._sk> | ||
|
||
* version 0.2.3 | ||
* fixed incorrect last page entry and next/last navigators generation (thanks Marcel S. for reporting problem) | ||
|
||
2009-12-06 Sam <samuel_._behan_(at)_dob_._sk> | ||
|
||
* version 0.2.2 | ||
* upgraded libs to stable 1.4 version | ||
* pager did not worked for standard search handler, so now | ||
we always request result set from solr | ||
* added additional checks to prevent working on empty result set | ||
|
||
2009-12-06 Sam <samuel_._behan_(at)_dob_._sk> | ||
|
||
* version 0.2.1 | ||
* added first page navigator | ||
* improved first & last paging, now they appear only if first/last page is not visible | ||
|
||
2009-12-04 Sam <samuel_._behan_(at)_dob_._sk> | ||
|
||
* version 0.2.0 | ||
* initial stable version |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
################################################################################ | ||
|
||
Program : solr_pager | ||
Version : 0.2.4 | ||
Purpose : Pager component for SOLR | ||
License : GNU GPL v3 (see file COPYING) | ||
Author : Samuel Behan <samuel_._behan_(at)_dob_._sk> (c) 2000-2011 | ||
Web : http://devel.dob.sk/solr_pager | ||
Requirements : JAVA 1.5, SOLR 1.4+, ANT | ||
|
||
################################################################################ | ||
|
||
--------- | ||
- ABOUT - | ||
--------- | ||
solr_pager is a SOLR paging component. It adds paging records to SOLR | ||
search results, that can be easily transformed using XSLT writer. You will | ||
not need anymore to bother with slow recursive XSLT paging hacks. | ||
See PAGING for more info. | ||
|
||
----------------- | ||
- BUG REPORTING - | ||
----------------- | ||
Report bugs or feature request to me (Author). | ||
|
||
--------------- | ||
- INSTALATION - | ||
--------------- | ||
For use of solr_pager you might need to compile this against yours | ||
SOLR version. Altought this tarball contains some recent version of SOLR jars, | ||
they might be different and compiled version of solr_pager might not work with | ||
yours SOLR. So, you will have to copy your SOLR (located in <webapps>/solr/WEB-INF/lib) | ||
jars to libs directory or alter library paths in build.xml. | ||
|
||
After this simply type | ||
|
||
$ ant | ||
|
||
This will create solr_pager.jar in dist directory, that you should copy to yours | ||
SOLR lib dir (usually <webapps>/solr/WEB-INF/lib). | ||
|
||
Finaly you need to define new component that can SOLR use in solrconfig.xml: | ||
|
||
<searchComponent name="pager" class="sk.dob.search.solr.handler.component.PagerComponent"/> | ||
|
||
And add pager component to request processing: | ||
|
||
<requestHandler name="standard" class="solr.SearchHandler" default="true"> | ||
|
||
<!-- ... usual solr requestHandler configurations ... -> | ||
|
||
<!-- use pager as last request processing component --> | ||
<arr name="last-components"> | ||
<str>pager</str> | ||
</arr> | ||
</requestHandler> | ||
|
||
|
||
|
||
---------------------- | ||
- SOLR QUERY OPTIONS - | ||
---------------------- | ||
|
||
pager - number of following or preceding page starts to generate | ||
default: 0 (disabled) | ||
|
||
pager.pre - how many of preceding page starts should be generated | ||
default: 2 | ||
|
||
---------- | ||
- PAGING - | ||
---------- | ||
|
||
Response with start = 75 and rows = 25. | ||
|
||
<response> | ||
<lst name="pager"> | ||
<lst name="pages"> <!-- list of all pages --> | ||
<int name="2">25</int> | ||
<int name="3">50</int> | ||
<int name="4">75</int> <!-- this is actual page --> | ||
<int name="5">100</int> | ||
<int name="6">125</int> | ||
<int name="7">150</int> | ||
<int name="8">175</int> | ||
<int name="9">200</int> | ||
<int name="10">225</int> | ||
<int name="11">250</int> | ||
</lst> | ||
<int name="prev">50</int> <!-- previous page, with start = 50 --> | ||
<int name="next">100</int> <!-- next page, with start = 75 --> | ||
<int name="last">1225</int> <!-- last page, with start = 1225 --> | ||
<int name="actual">4</int> <!-- actual page number --> | ||
<int name="count">49</int> <!-- count of all pages --> | ||
</lst> | ||
</response> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
====================================================================== | ||
Fri Dec 4 19:12:18 CET 2009 | ||
solr_pager | ||
Provides simple and fast paging for SOLR results | ||
Samuel Behan <samuel_behan_(at)_dob_._sk> | ||
====================================================================== | ||
--> | ||
<project name="solr_pager" default="default"> | ||
<description> | ||
Provides simple and fast paging mechanism for SOLR results | ||
</description> | ||
<property name="src.dir" value="src"/> | ||
<property name="build.dir" value="build"/> | ||
<property name="dist.dir" value="dist"/> | ||
<property name="lib.dir" value="libs"/> | ||
<property name="solr.dir" value="${lib.dir}/solr"/> | ||
<property name="lucene.dir" value="${lib.dir}/lucene"/> | ||
<path id="lib.path"> | ||
<fileset dir="${solr.dir}"> | ||
<include name="*.jar"/> | ||
</fileset> | ||
<fileset dir="${lucene.dir}"> | ||
<include name="*.jar"/> | ||
</fileset> | ||
</path> | ||
|
||
<!-- ================================= | ||
target: default | ||
================================= --> | ||
<target name="default" depends="clean,compile,jar" description="--> Provide simple paging mechanism"> | ||
</target> | ||
<!-- - - - - - - - - - - - - - - - - - | ||
target: depends | ||
- - - - - - - - - - - - - - - - - --> | ||
<target name="depends"> | ||
<mkdir dir="${build.dir}"/> | ||
<mkdir dir="${dist.dir}"/> | ||
</target> | ||
<target name="clean"> | ||
<delete dir="${build.dir}"/> | ||
<delete dir="${dist.dir}"/> | ||
</target> | ||
<!-- ================================= | ||
target: compile | ||
================================= --> | ||
<target name="compile" depends="depends" description="--> Compile solr_pager sources"> | ||
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path" debug="on"> | ||
<!-- <compilerarg value="-Xlint:unchecked"/> --> | ||
</javac> | ||
</target> | ||
<!-- - - - - - - - - - - - - - - - - - | ||
target: jar | ||
- - - - - - - - - - - - - - - - - --> | ||
<target name="jar"> | ||
<jar destfile="${dist.dir}/${ant.project.name}.jar" basedir="${build.dir}"/> | ||
</target> | ||
|
||
</project> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
178 changes: 178 additions & 0 deletions
178
src/sk/dob/search/solr/handler/component/PagerComponent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/** PageComponent.java | ||
* Program : solr_pager | ||
* Version : 0.2.0 | ||
* Purpose : Pager component for SOLR | ||
* Provides simple and fast paging for SOLR results | ||
* License : GNU GPL v3 (see file COPYING) | ||
* Author : Samuel Behan <samkob_(at)_gmail_._com> (c) 2000-2009 | ||
* Web : http://devel.dob.sk/solr_pager | ||
* Requirements : JAVA 1.5, SOLR 1.4, ANT | ||
*/ | ||
package sk.dob.search.solr.handler.component; | ||
|
||
/* solr imports */ | ||
import org.apache.lucene.search.Query; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.handler.component.ResponseBuilder; | ||
import org.apache.solr.handler.component.SearchComponent; | ||
import org.apache.solr.handler.component.ShardRequest; | ||
import org.apache.solr.common.SolrException; | ||
import org.apache.solr.common.params.CommonParams; | ||
import org.apache.solr.common.params.SolrParams; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.common.util.SimpleOrderedMap; | ||
|
||
|
||
/* lf4j import */ | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/* java imports */ | ||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
|
||
/** | ||
* PagerComponent | ||
* Provides simple and fast paging for SOLR results | ||
* | ||
* @version 0.2.0 SamB $ | ||
* @since solr 1.4 | ||
*/ | ||
public class PagerComponent extends SearchComponent | ||
{ | ||
public static final String COMPONENT_NAME = "pager"; | ||
public static final String PARAM_PAGER = "pager"; | ||
public static final String PARAM_PAGER_PRE = "pager.pre"; | ||
// private static final Logger log = LoggerFactory.getLogger(PagerComponent.class); | ||
|
||
@Override | ||
public void prepare(ResponseBuilder rb) throws IOException | ||
{ | ||
/* notify solr we always need resultset ! */ | ||
if(rb.req.getParams().getInt(PARAM_PAGER, 0) != 0) | ||
rb.setNeedDocSet( true ); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void process(ResponseBuilder rb) throws IOException | ||
{ | ||
/* get request params */ | ||
SolrParams par = rb.req.getParams(); | ||
int rows = par.getInt(CommonParams.ROWS, 0); | ||
int start = par.getInt(CommonParams.START, 0); | ||
int pages = par.getInt(PARAM_PAGER, 0); | ||
int pages_pre = par.getInt(PARAM_PAGER_PRE, 2); | ||
|
||
/* neet to work ? */ | ||
if(pages == 0 || rows == 0 || rb == null | ||
|| rb.getResults() == null) | ||
return; | ||
|
||
/* select result list */ | ||
int doc_count = 0; | ||
|
||
if(rb.getResults().docSet != null) | ||
doc_count = rb.getResults().docSet.size(); | ||
else return; | ||
|
||
/* pager list */ | ||
NamedList lst = new SimpleOrderedMap<Object>(); | ||
NamedList lst2 = new SimpleOrderedMap<Object>(); | ||
|
||
/* paging pages */ | ||
int page_count = doc_count / rows; | ||
int page_actual = start / rows; | ||
int page_pre = pages_pre; | ||
int page_post = pages - page_pre - 1; | ||
|
||
/* last page */ | ||
if(doc_count % rows != 0) | ||
page_count++; | ||
|
||
/* page range */ | ||
if(page_actual - page_pre < 0) | ||
{ | ||
page_post += - (page_actual - page_pre); | ||
page_pre -= - (page_actual - page_pre); | ||
} | ||
else if(page_actual + page_post > page_count) | ||
{ | ||
page_post = pages - page_pre; | ||
page_pre = page_actual + pages - page_count; | ||
} | ||
|
||
/* sanity */ | ||
if(page_pre < 0) | ||
page_pre = 0; | ||
if(page_post < 0) | ||
page_post = 0; | ||
|
||
/* next pages list */ | ||
int i = (page_actual - page_pre); | ||
for(i = (i <= 0 ? 0 : i); | ||
i < page_count && i <= (page_actual + page_post); | ||
i++) | ||
lst2.add(Integer.toString(i + 1), i * rows); | ||
lst.add("pages", lst2); | ||
|
||
/* navi */ | ||
if(page_actual > 0) | ||
lst.add("prev", (page_actual - 1) * rows); | ||
if(page_actual - page_pre > 0) | ||
lst.add("first", 0); | ||
if(page_actual < (page_count - 1)) | ||
lst.add("next", (page_actual + 1) * rows); | ||
if(page_actual + page_post < (page_count - 1)) | ||
lst.add("last", (page_count - 1) * rows); | ||
lst.add("actual", page_actual + 1); | ||
lst.add("count", page_count); | ||
|
||
/* finish */ | ||
rb.rsp.add("pager", lst); | ||
} | ||
|
||
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) | ||
{ | ||
} | ||
|
||
@Override | ||
public void handleResponses(ResponseBuilder rb, ShardRequest sreq) | ||
{ | ||
} | ||
|
||
@Override | ||
public void finishStage(ResponseBuilder rb) | ||
{ | ||
} | ||
|
||
//////////////////////////////////////////// | ||
/// SolrInfoMBean | ||
//////////////////////////////////////////// | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Pager"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return "$Revision: 1 $"; | ||
} | ||
|
||
@Override | ||
public String getSourceId() { | ||
return "$Id: $"; | ||
} | ||
|
||
@Override | ||
public String getSource() { | ||
return "$URL: http://devel.dob.sk/solr_pager $"; | ||
} | ||
|
||
@Override | ||
public URL[] getDocs() { | ||
return null; | ||
} | ||
} |