use of net.jforum.exceptions.SearchException in project jforum2 by rafaelsteil.
the class LuceneSearch method performSearch.
private SearchResult performSearch(SearchArgs args, LuceneResultCollector resultCollector, Filter filter) {
SearchResult result;
try {
StringBuffer criteria = new StringBuffer(256);
this.filterByForum(args, criteria);
this.filterByKeywords(args, criteria);
this.filterByDateRange(args, criteria);
Query query = new QueryParser("", new StandardAnalyzer()).parse(criteria.toString());
if (logger.isDebugEnabled()) {
logger.debug("Generated query: " + query);
}
Hits hits = filter == null ? this.search.search(query, this.getSorter(args)) : this.search.search(query, filter, this.getSorter(args));
if (hits != null && hits.length() > 0) {
result = new SearchResult(resultCollector.collect(args, hits, query), hits.length());
} else {
result = new SearchResult(new ArrayList(), 0);
}
} catch (Exception e) {
throw new SearchException(e);
}
return result;
}
use of net.jforum.exceptions.SearchException in project jforum2 by rafaelsteil.
the class LuceneSearch method analyzeKeywords.
private String[] analyzeKeywords(String contents) {
try {
TokenStream stream = this.settings.analyzer().tokenStream("contents", new StringReader(contents));
List tokens = new ArrayList();
while (true) {
Token token = stream.next();
if (token == null) {
break;
}
tokens.add(token.termText());
}
return (String[]) tokens.toArray(new String[0]);
} catch (IOException e) {
throw new SearchException(e);
}
}
use of net.jforum.exceptions.SearchException in project jforum2 by rafaelsteil.
the class LuceneSearch method newDocumentAdded.
/**
* @see net.jforum.search.NewDocumentAdded#newDocumentAdded()
*/
public void newDocumentAdded() {
try {
this.search.close();
this.openSearch();
} catch (Exception e) {
throw new SearchException(e);
}
}
use of net.jforum.exceptions.SearchException in project jforum2 by rafaelsteil.
the class LuceneIndexer method flushRAMDirectory.
public void flushRAMDirectory() {
synchronized (MUTEX) {
IndexWriter writer = null;
try {
writer = new IndexWriter(this.settings.directory(), this.settings.analyzer());
writer.addIndexes(new Directory[] { this.ramDirectory });
writer.optimize();
this.createRAMWriter();
} catch (IOException e) {
throw new SearchException(e);
} finally {
if (writer != null) {
try {
writer.flush();
writer.close();
this.notifyNewDocumentAdded();
} catch (Exception e) {
}
}
}
}
}
use of net.jforum.exceptions.SearchException in project jforum2 by rafaelsteil.
the class LuceneIndexer method createRAMWriter.
private void createRAMWriter() {
try {
if (this.ramWriter != null) {
this.ramWriter.close();
}
this.ramDirectory = new RAMDirectory();
this.ramWriter = new IndexWriter(this.ramDirectory, this.settings.analyzer(), true);
this.ramNumDocs = SystemGlobals.getIntValue(ConfigKeys.LUCENE_INDEXER_RAM_NUMDOCS);
} catch (IOException e) {
throw new SearchException(e);
}
}
Aggregations