SearchEngine.java revision 1195
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Micosystems. All rights reserved.
* Use is subject to license terms.
*/
/**
* This is an encapsulation of the details on how to seach in the index
* database.
*
* @author Trond Norbye 2005
* @author Lubos Kosco 2010 - upgrade to lucene 3.0.0
*/
public class SearchEngine {
/** Message text used when logging exceptions thrown when searching. */
//NOTE below will need to be changed after new lucene upgrade, if they
//increase the version - every change of below makes us incompatible with the
//old index and we need to ask for reindex
/** version of lucene index common for whole app*/
/**
* Holds value of property definition.
*/
private String definition;
/**
* Holds value of property file.
*/
/**
* Holds value of property freetext.
*/
/**
* Holds value of property history.
*/
/**
* Holds value of property symbol.
*/
/**
* Holds value of property indexDatabase.
*/
private Context sourceContext;
private HistoryContext historyContext;
private Summarizer summarizer;
// internal structure to hold the results from lucene
private final static boolean docsScoredInOrder = false;
int totalHits=0;
private TopScoreDocCollector collector;
boolean allCollected;
/**
* Creates a new instance of SearchEngine
*/
public SearchEngine() {
}
/**
* Create a QueryBuilder using the fields that have been set on this
* SearchEngine.
*
* @return a query builder
*/
private QueryBuilder createQueryBuilder() {
return new QueryBuilder()
}
public boolean isValidQuery() {
boolean ret;
try {
} catch (Exception e) {
ret = false;
}
return ret;
}
/**
*
* @param paging whether to use paging (if yes, first X pages will load faster)
* @param root which db to search
* @throws IOException
*/
if (!paging) {
}
}
}
/**
*
* @param paging whether to use paging (if yes, first X pages will load faster)
* @param root list of projects to search
* @throws IOException
*/
int ii=0;
IndexReader ireader = (IndexReader.open(FSDirectory.open(new File(droot,project.getPath()) ),true));
}
if (!paging) {
}
}
}
}
/**
* Execute a search. Before calling this function, you must set the
* appropriate seach critera with the set-functions.
* Note that this search will return the first cachePages of hitsPerPage, for more you need to call more
*
* @return The number of hits
*/
public int search() {
try {
if (env.hasProjects()) {
// search all projects
//TODO support paging per project (in search.java)
//TODO optimize if only one project by falling back to SingleDatabase ?
} else {
// search the index database
searchSingleDatabase(root,true);
}
}
} catch (Exception e) {
}
summarizer = null;
try {
if(sourceContext.isEmpty()) {
}
} catch (Exception e) {
}
try {
if(historyContext.isEmpty()) {
}
} catch (Exception e) {
}
}
}
/**
* get results , if no search was started before, no results are returned
* this method will requery if end end is more than first query from search,
* hence performance hit applies, if you want results in later pages than number of cachePages
* also end has to be bigger than start !
* @param start start of the hit list
* @param end end of the hit list
*/
//return if no start search() was done
return;
}
//TODO check if below fits for if end=old hits.length, or it should include it
//do the requery, we want more than 5 pages
try {
} catch (Exception e) { // this exception should never be hit, since search() will hit this before
}
try {
} catch (Exception e) {
}
}
allCollected=true;
}
//TODO generation of ret(results) could be cashed and consumers of engine would just print them in whatever form they need, this way we could get rid of docs
// the only problem is that count of docs is usually smaller than number of results
boolean hasContext = false;
try {
}
if(sourceContext != null) {
try {
int l = 0;
r = new TagFilter(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(data + "/xref" + filename+".gz"))))); }
else {
try {
} finally {
}
//TODO FIX below fragmenter according to either summarizer or context (to get line numbers, might be hard, since xref writers will need to be fixed too, they generate just one line of html code now :( )
}
hasContext = true;
}
}
} else {
}
} catch (FileNotFoundException exp) {
OpenGrokLogger.getLogger().warning("Couldn't read summary from "+filename+" ("+exp.getMessage()+")");
}
}
if (historyContext != null) {
}
if(!hasContext) {
}
} catch (IOException e) {
} catch (ClassNotFoundException e) {
} catch (HistoryException e) {
}
}
}
/**
* Getter for property definition.
*
* @return Value of property definition.
*/
public String getDefinition() {
return this.definition;
}
/**
* Setter for property definition.
*
* @param definition New value of property definition.
*/
this.definition = definition;
}
/**
* Getter for property file.
*
* @return Value of property file.
*/
return this.file;
}
/**
* Setter for property file.
*
* @param file New value of property file.
*/
}
/**
* Getter for property freetext.
*
* @return Value of property freetext.
*/
public String getFreetext() {
return this.freetext;
}
/**
* Setter for property freetext.
*
* @param freetext New value of property freetext.
*/
}
/**
* Getter for property history.
*
* @return Value of property history.
*/
public String getHistory() {
return this.history;
}
/**
* Setter for property history.
*
* @param history New value of property history.
*/
}
/**
* Getter for property symbol.
*
* @return Value of property symbol.
*/
return this.symbol;
}
/**
* Setter for property symbol.
*
* @param symbol New value of property symbol.
*/
}
}