Keyword search: Remove obsolete less writeToBlackBoard() from interface, use only the more efficient method.

Better error handling of Solr errors.
This commit is contained in:
adam-m 2012-04-05 13:46:05 -04:00
parent a2267f34f5
commit dd309abbe0
6 changed files with 29 additions and 61 deletions

View File

@ -141,7 +141,8 @@ class HighlightedMatchesSource implements MarkupSource, HighlightLookup {
return "<pre>" + highlightedContent + "</pre>"; return "<pre>" + highlightedContent + "</pre>";
} }
} catch (SolrServerException ex) { } catch (SolrServerException ex) {
throw new RuntimeException(ex); logger.log(Level.INFO, "Could not query markup. ", ex);
return "";
} }
} }

View File

@ -77,14 +77,6 @@ public interface KeywordSearchQuery {
*/ */
public Collection<Term>getTerms(); public Collection<Term>getTerms();
/**
* write search results to blackboard
* @param newFsHit new fscontent hit associated with the result to write to bb
* @param listname list name with the keyword query, or null
* @return collection of results (with cached bb artifacts/attributes) created and written
*/
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName);
/** /**
* write results to blackboard per single term and file hit * write results to blackboard per single term and file hit
* this method is useful if something else should keep track of partial results to write * this method is useful if something else should keep track of partial results to write

View File

@ -192,10 +192,6 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
return null; return null;
} }
@Override
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
throw new UnsupportedOperationException("writeToBlackBoard() unsupported by manager");
}
@Override @Override
public KeywordWriteResult writeToBlackBoard(String termHit, FsContent newFsHit, String listName) { public KeywordWriteResult writeToBlackBoard(String termHit, FsContent newFsHit, String listName) {

View File

@ -241,18 +241,17 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
//construct a Solr query using aggregated terms to get highlighting //construct a Solr query using aggregated terms to get highlighting
//the query is executed later on demand //the query is executed later on demand
StringBuilder highlightQuery = new StringBuilder(); StringBuilder highlightQuery = new StringBuilder();
Collection<Term> terms = tcq.getTerms();
if (terms.size() == 1) { if (tcqRes.keySet().size() == 1) {
//simple case, no need to process subqueries and do special escaping //simple case, no need to process subqueries and do special escaping
Term term = terms.iterator().next(); String term = tcqRes.keySet().iterator().next();
highlightQuery.append(term.getTerm()); highlightQuery.append(term);
} else { } else {
final int lastTerm = terms.size() - 1; final int lastTerm = tcqRes.keySet().size() - 1;
int curTerm = 0; int curTerm = 0;
for (Term term : terms) { for (String term : tcqRes.keySet()) {
//escape subqueries, they shouldn't be escaped again later //escape subqueries, they shouldn't be escaped again later
final String termS = KeywordSearchUtil.escapeLuceneQuery(term.getTerm(), true, false); final String termS = KeywordSearchUtil.escapeLuceneQuery(term, true, false);
if (!termS.contains("*")) { if (!termS.contains("*")) {
highlightQuery.append(termS); highlightQuery.append(termS);
if (lastTerm != curTerm) { if (lastTerm != curTerm) {
@ -292,7 +291,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
toPopulate.add(new KeyValueQueryContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped, tcq)); toPopulate.add(new KeyValueQueryContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped, tcq));
} }
//write to bb //write to bb
new ResultWriter(fsContents, tcq, theListName).execute(); new ResultWriter(tcqRes, tcq, theListName).execute();
return true; return true;
@ -378,7 +377,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
} }
//write to bb //write to bb
new ResultWriter(uniqueMatches, origQuery, "").execute(); new ResultWriter(matchesRes, origQuery, "").execute();
return true; return true;
} }
@ -427,16 +426,15 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
*/ */
static class ResultWriter extends SwingWorker { static class ResultWriter extends SwingWorker {
private static List<ResultWriter>writers = new ArrayList<ResultWriter>(); private static List<ResultWriter> writers = new ArrayList<ResultWriter>();
private ProgressHandle progress; private ProgressHandle progress;
private KeywordSearchQuery query; private KeywordSearchQuery query;
private String listName; private String listName;
private Set<FsContent> fsContents; private Map<String, List<FsContent>> hits;
final Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>(); final Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>();
ResultWriter(Set<FsContent> fsContents, KeywordSearchQuery query, String listName) { ResultWriter(Map<String, List<FsContent>> hits, KeywordSearchQuery query, String listName) {
this.fsContents = fsContents; this.hits = hits;
this.query = query; this.query = query;
this.listName = listName; this.listName = listName;
} }
@ -447,7 +445,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
deregisterWriter(this); deregisterWriter(this);
progress.finish(); progress.finish();
if (! this.isCancelled() && !na.isEmpty()) { if (!this.isCancelled() && !na.isEmpty()) {
IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na));
} }
} }
@ -456,7 +454,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
protected Object doInBackground() throws Exception { protected Object doInBackground() throws Exception {
registerWriter(this); registerWriter(this);
final String queryStr = query.getQueryString(); final String queryStr = query.getQueryString();
final String queryDisp = queryStr.length()>20?queryStr.substring(0,19) + " ..." : queryStr; final String queryDisp = queryStr.length() > 20 ? queryStr.substring(0, 19) + " ..." : queryStr;
progress = ProgressHandleFactory.createHandle("Saving results: " + queryDisp, new Cancellable() { progress = ProgressHandleFactory.createHandle("Saving results: " + queryDisp, new Cancellable() {
@Override @Override
@ -465,17 +463,19 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
} }
}); });
progress.start(fsContents.size()); progress.start(hits.keySet().size());
int processedFiles = 0; int processedFiles = 0;
for (final FsContent f : fsContents) { for (final String hit : hits.keySet()) {
progress.progress(hit, ++processedFiles);
if (this.isCancelled()) { if (this.isCancelled()) {
break; break;
} }
Collection<KeywordWriteResult> written = query.writeToBlackBoard(f, listName); for (FsContent f : hits.get(hit)) {
for (KeywordWriteResult w : written) { KeywordWriteResult written = query.writeToBlackBoard(hit, f, listName);
na.add(w.getArtifact()); if (written != null)
na.add(written.getArtifact());
} }
progress.progress(f.getName(), ++processedFiles);
} }
@ -497,6 +497,5 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
writers.remove(w); writers.remove(w);
} }
} }
} }
} }

View File

@ -163,8 +163,7 @@ public class LuceneQuery implements KeywordSearchQuery {
return query != null && !query.equals(""); return query != null && !query.equals("");
} }
@Override private Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
List<KeywordWriteResult> ret = new ArrayList<KeywordWriteResult>(); List<KeywordWriteResult> ret = new ArrayList<KeywordWriteResult>();
KeywordWriteResult written = writeToBlackBoard(query, newFsHit, listName); KeywordWriteResult written = writeToBlackBoard(query, newFsHit, listName);
if (written != null) { if (written != null) {

View File

@ -219,25 +219,6 @@ public class TermComponentQuery implements KeywordSearchQuery {
} }
@Override
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
Collection<KeywordWriteResult> writeResults = new ArrayList<KeywordWriteResult>();
//get unique term matches, all cases
Set<String> matches = new HashSet<String>();
for (Term term : terms) {
//caseInsMatches.put(term.getTerm().toLowerCase(), null);
matches.add(term.getTerm());
}
for (String regexMatch : matches) {
KeywordWriteResult written = writeToBlackBoard(regexMatch, newFsHit, listName);
if (written != null)
writeResults.add(written);
} //for each term
return writeResults;
}
@Override @Override
public Map<String, List<FsContent>> performQuery() { public Map<String, List<FsContent>> performQuery() {