use of org.compass.core.mapping.ResourceMapping in project Gemma by PavlidisLab.
the class SearchServiceImpl method performSearch.
/**
* Runs inside Compass transaction
*/
private Collection<SearchResult> performSearch(SearchSettings settings, CompassSession session) {
StopWatch watch = this.startTiming();
String enhancedQuery = settings.getQuery().trim();
// noinspection ConstantConditions // Not obvious to me why that would have to be false.
if (StringUtils.isBlank(enhancedQuery) || enhancedQuery.length() < SearchServiceImpl.MINIMUM_STRING_LENGTH_FOR_FREE_TEXT_SEARCH || enhancedQuery.equals("*"))
return new ArrayList<>();
CompassQuery compassQuery = session.queryBuilder().queryString(enhancedQuery).toQuery();
SearchServiceImpl.log.debug("Parsed query: " + compassQuery);
CompassHits hits = compassQuery.hits();
// highlighting.
if (((SearchSettingsImpl) settings).getDoHighlighting()) {
if (session instanceof InternalCompassSession) {
// always ...
CompassMapping mapping = ((InternalCompassSession) session).getMapping();
ResourceMapping[] rootMappings = mapping.getRootMappings();
// should only be one rootMapping.
this.process(rootMappings, hits);
}
}
watch.stop();
if (watch.getTime() > 100) {
SearchServiceImpl.log.info("Getting " + hits.getLength() + " lucene hits for " + enhancedQuery + " took " + watch.getTime() + " ms");
}
if (watch.getTime() > 5000) {
SearchServiceImpl.log.info("*****Extremely long Lucene Index Search! " + hits.getLength() + " lucene hits for " + enhancedQuery + " took " + watch.getTime() + " ms");
}
return this.getSearchResults(hits);
}
use of org.compass.core.mapping.ResourceMapping in project Gemma by PavlidisLab.
the class SearchServiceImpl method process.
/**
* Recursively cache the highlighted text. This must be done during the search transaction.
*
* @param givenMappings on first call, the root mapping(s)
*/
private void process(ResourceMapping[] givenMappings, CompassHits hits) {
for (ResourceMapping resourceMapping : givenMappings) {
// one for each property.
Iterator<Mapping> mappings = resourceMapping.mappingsIt();
for (; mappings.hasNext(); ) {
Mapping m = mappings.next();
if (m instanceof ComponentMapping) {
ClassMapping[] refClassMappings = ((ComponentMapping) m).getRefClassMappings();
this.process(refClassMappings, hits);
} else {
String name = m.getName();
for (int i = 0; i < hits.getLength(); i++) {
try {
// we might want to bail as soon as we find something?
hits.highlighter(i).fragment(name);
if (SearchServiceImpl.log.isDebugEnabled())
SearchServiceImpl.log.debug("Cached " + name);
} catch (Exception e) {
// skip this property entirely...
break;
}
}
}
}
}
}
Aggregations