my changes to make it compile, also minor build file cleanup

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150887 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2003-05-12 14:32:23 +00:00
parent 620516c21c
commit f667465102
4 changed files with 95 additions and 90 deletions

View File

@ -6,15 +6,14 @@
(and without typing -D each time it compiles it -->
<property file="${user.home}/lucene.build.properties" />
<property file="${user.home}/build.properties" />
<property file="${basedir}/build.properties" />
<property file="${basedir}/default.properties" />
<property file="build.properties" />
<property file="default.properties" />
<property name="lib.dir" location="lib"/>
<!-- Build classpath -->
<path id="classpath">
<pathelement location="${build.classes}"/>
<pathelement location="${build.test.classes}"/>
<pathelement location="."/>
<fileset dir="lib.dir">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
@ -22,9 +21,8 @@
<path id="junit.classpath">
<pathelement location="${junit.classes}" />
<pathelement location="${build.classes}"/>
<fileset dir="lib.dir">
<include name="*.jar" />
</fileset>
<pathelement location="${build.test.classes}"/>
<path refid="classpath"/>
<pathelement path="${java.class.path}" />
</path>
@ -35,7 +33,6 @@
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.src}"/>
<mkdir dir="lib.dir"/>
<available
property="junit.present"
@ -109,7 +106,7 @@
includes="**/*.java"
destdir="${build.test.classes}"
debug="${debug}">
<classpath refid="classpath"/>
<classpath refid="junit.classpath"/>
</javac>
</target>
@ -133,7 +130,7 @@
includes="**/*.java"
destdir="${junit.classes}"
debug="${debug}">
<classpath refid="classpath"/>
<classpath refid="junit.classpath"/>
</javac>
<junit printsummary="yes" haltonfailure="no" >

View File

@ -25,37 +25,37 @@ import java.util.Comparator;
* @version 1.0
*/
public class HitsIterator {
//static Logger logger = Logger.getLogger(HitsIterator.class.getName());
private int currentPosition = 0;
private Hits hitsCollection = null;
private Object[] arrayOfIndividualHits = null;
private int totalHits = 0;
private int pageSize = 25; // default page size
private int currentPage = 1; // range from 1 to totalHits%pageSize
private int totalPages = -1; // set by constructor
private int endPagePosition = 0; // position currentPage ends
/** Creates new HitsIterator */
private HitsIterator() {
}
public HitsIterator(Hits hits) throws IOException{
this(hits,null);
}
public HitsIterator(Hits hits, String sortFlag) throws IOException{
this.hitsCollection = hits;
if (sortFlag != null){
if ((sortFlag != "") && (sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
//logger.debug("Sorting hits by field "+sortFlag);
if (sortFlag != "") {
System.out.println("Sorting hits by field "+sortFlag);
sortByField(sortFlag);
//logger.debug("Completed sorting by field "+sortFlag);
}
@ -63,7 +63,7 @@ public class HitsIterator {
totalHits = getTotalHits();
setPageCount();
}
/** sorts hits by the given sort flag
* fills an interal array
* @param sortFlag field to sort results on
@ -75,12 +75,12 @@ public class HitsIterator {
//logger.error("sort field is null");
return;
}
SortedField sf = SortedField.getSortedField(fieldName);
if (sf !=null){
c = (Comparator) new CompareDocumentsByField();
} else {
//logger.error("Sort field not found");
//logger.error("Sort field not found");
// use default sort of Lucene -- Relevance
// Should I throw an exception here?
arrayOfIndividualHits = null;
@ -94,32 +94,32 @@ public class HitsIterator {
}
long second = System.currentTimeMillis();
//logger.debug("HitsIterator.sortByField(): filling Obj[] took "+(second-first));
Arrays.sort(arrayOfIndividualHits, c);
//logger.debug("HitsIterator.sortByField(): sort took "+(System.currentTimeMillis()-second));
}
private void setPageCount() {
if (totalHits == 0){
totalPages = 0;
setCurrentPage(0);
} else {
totalPages = totalHits / pageSize;
//account for remainder if not exaxtly divisable
if (totalHits % pageSize != 0)
{ totalPages++;}
setCurrentPage(1); // reset currentPage to make sure not over the limit
}
}
public int getPageCount() {
return totalPages;
}
public org.apache.lucene.document.Document setPosition(int position) throws IOException{
if (position > totalHits) {
return null;
@ -127,34 +127,34 @@ public class HitsIterator {
currentPosition = position;
return getDoc();
}
public org.apache.lucene.document.Document next() throws IOException{
currentPosition++;
if (currentPosition > totalHits) {
currentPosition = totalHits;
return null ;
}
return getDoc();
}
public org.apache.lucene.document.Document previous() throws IOException{
currentPosition--;
if (currentPosition < 0)
{ return null;}
return getDoc();
}
public boolean hasNext() {
if (currentPosition < endPagePosition)
{ return true; }
return false;
}
public org.apache.lucene.document.Document getDoc() throws IOException {
// Determine if using relevnace or sorting by another field
if (arrayOfIndividualHits == null)
@ -164,7 +164,7 @@ public class HitsIterator {
return hitsCollection.doc(i);
}
}
public int getScore() throws Exception{
// Determine if using relevnace or sorting by another field
if (arrayOfIndividualHits == null)
@ -172,39 +172,39 @@ public class HitsIterator {
else
return (int) (((IndividualHit)arrayOfIndividualHits[currentPosition - 1]).getScore()*100.0f);
}
public int getTotalHits() {
return hitsCollection.length();
}
public int getCurrentPosition() {
return currentPosition;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
setPageCount();
}
public void setCurrentPage(int currentPage) throws IndexOutOfBoundsException{
if (currentPage > totalPages){
currentPage = totalPages; // don't allow to go over max
//throw new IndexOutOfBoundsException("currentPage greater than total pages");
}
this.currentPage = currentPage;
currentPosition = ((currentPage - 1) * pageSize);
endPagePosition = Math.min( ((currentPage - 1)*pageSize) + pageSize, totalHits);
}
public int getCurrentPage() {
return currentPage;
}
/**
* set page number to next page, unless last page, then
* always return last page number
@ -214,7 +214,7 @@ public class HitsIterator {
setCurrentPage(currentPage++);
return getCurrentPage();
}
/**
* set page number to previous page, unless first page,
* then always return first page number

View File

@ -1,6 +1,7 @@
package org.apache.lucene.beans;
import java.util.Iterator;
import java.io.IOException;
/**
* Acts as an adapter for HitsIterator to comply with the Collections
@ -25,7 +26,13 @@ public final class IteratorAdapter implements Iterator
public Object next()
{
return hitsIterator.next();
Object obj = null;
try {
obj = hitsIterator.next();
} catch (IOException e) {
// ignore for now, returning null might be good enough?
}
return obj;
}
public void remove()

View File

@ -32,7 +32,7 @@ import java.io.IOException;
* @version 1.0
*/
public class SearchBean extends Object {
static final String SORT_FIELD_RELEVANCE = "relevance";
private String queryString = "";
private String querySortField = SORT_FIELD_RELEVANCE; // default
@ -44,17 +44,17 @@ public class SearchBean extends Object {
private Searcher searcher = null;
// static Logger logger = Logger.getLogger(SearchBean.class.getName());
// static Logger searchLogger = Logger.getLogger("searchLog");
private SearchBean(){
}
/** Creates new SearchBean
* @param path to index
*/
public SearchBean(Directory directory) {
this.directory = directory;
}
/** Creates new SearchBean
* @param directory index
* @param queryString string to search with
@ -63,7 +63,7 @@ public class SearchBean extends Object {
this(directory);
setQueryString(queryString);
}
/** Creates new SearchBean
* @param directory index
* @param queryString string to search with
@ -74,7 +74,7 @@ public class SearchBean extends Object {
setQueryString(queryString);
setQuerySortField(querySortField);
}
/** Creates new SearchBean
* @param directory index
* @param queryString string to search with
@ -87,20 +87,20 @@ public class SearchBean extends Object {
setQuerySortField(querySortField);
setQueryType(queryType);
}
/** main search method
*/
public HitsIterator search() throws IOException, ParseException{
return search(queryString,querySortField);
}
/** main search method
* @param queryString string to search with
*/
public HitsIterator search(String queryString) throws IOException, ParseException{
return search(queryString,queryString);
}
/** main search method
* @param queryString string to search with
* @param querySortField field to sort on
@ -108,7 +108,7 @@ public class SearchBean extends Object {
public HitsIterator search(String queryString, String querySortField) throws IOException, ParseException{
return search(queryString, querySortField, queryType);
}
/** main search method
* @param queryString string to search with
* @param querySortField field to sort on
@ -117,10 +117,10 @@ public class SearchBean extends Object {
public HitsIterator search(String queryString, String querySortField, String queryType) throws IOException, ParseException {
long startTime = System.currentTimeMillis();
Hits hits = searchHits(queryString, queryType);
//if (hits == null) {return null;}
//if (hits.length() == 0) {return null;}
HitsIterator hi = new HitsIterator(hits, querySortField);
long endTime = System.currentTimeMillis();
setSearchTime(endTime - startTime);
@ -128,51 +128,52 @@ public class SearchBean extends Object {
//searchLogger.info("queryString = "+queryString + "sort field = "+ querySortField +" #results = "+hits.length());
return hi;
}
/** does the actual searching
*/
private Hits searchHits(String queryString, String queryType) throws IOException, ParseException{
System.out.println("queryString = " + queryString);
if (queryString == "") {
return null;
}
// Provide for multiple indices in the future
searcher = new IndexSearcher(directory);
Query query = getQuery(queryString, defaultSearchField);
//System.out.println("###querystring= "+query.toString(defaultSearchField));
System.out.println("###querystring= "+query.toString(defaultSearchField));
Hits hits = searcher.search(query);
//System.out.println("Number hits = "+hits.length());
//logger.debug("queryString = "+query.toString(searchField)+" hits = "+hits.length()+" queryType = "+queryType+" indexPath = "+indexPath );
return hits;
}
/**
* frees resources associated with SearchBean search
*/
public void close() throws IOException{
searcher.close();
}
/** <queryString> | <queryType> | <querySortField>
*/
public String toString(){
return queryString+"|"+queryType+"|"+querySortField;
}
/** setter for queryString
*/
public void setQueryString
(String queryString) {
this.queryString = queryString;
}
/** getter for queryString
*/
public String getQueryString(){
return queryString;
}
/** getter for Lucene Query
*/
private Query getQuery(String queryString, String searchField) throws ParseException {
@ -182,89 +183,89 @@ public class SearchBean extends Object {
//System.out.println(query.toString());
return query;
}
/** Getter for property defaulSearchField.
* @return Value of property defaulSearchField.
*/
public String getDefaultSearchField() {
return defaultSearchField;
}
/** Setter for property defaulSearchField.
* @param defaulSearchField New value of property defaulSearchField.
*/
public void setDefaultSearchField(java.lang.String defaultSearchField) {
this.defaultSearchField = defaultSearchField;
}
/** Getter for property searchTime.
* @return Value of property searchTime.
*/
public long getSearchTime() {
return searchTime;
}
/** Setter for property searchTime.
* @param searchTime New value of property searchTime.
*/
public void setSearchTime(long searchTime) {
this.searchTime = searchTime;
}
/** Getter for property querySortField.
* @return Value of property querySortField.
*/
public java.lang.String getQuerySortField() {
return querySortField;
}
/** Setter for property querySortField.
* @param querySortField New value of property querySortField.
*/
public void setQuerySortField(String querySortField) {
this.querySortField = querySortField;
}
/** Getter for property hitsIterator.
* @return Value of property hitsIterator.
*/
public HitsIterator getHitsIterator() {
return hitsIterator;
}
/** Setter for property hitsIterator.
* @param hitsIterator New value of property hitsIterator.
*/
public void setHitsIterator(HitsIterator hitsIterator) {
this.hitsIterator = hitsIterator;
}
/** Getter for property queryType.
* @return Value of property queryType.
*/
public java.lang.String getQueryType() {
return queryType;
}
/** Setter for property queryType.
* @param queryType New value of property queryType.
*/
public void setQueryType(java.lang.String queryType) {
this.queryType = queryType;
}
/** Getter for property directory.
* @return Value of property directory.
*/
public org.apache.lucene.store.Directory getDirectory() {
return directory;
}
}
/** Setter for property directory.
* @param directory New value of property directory.
*/
public void setDirectory(org.apache.lucene.store.Directory directory) {
this.directory = directory;
}
}