Search in sources :

Example 1 with ResourceMapping

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);
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) InternalCompassSession(org.compass.core.spi.InternalCompassSession) CompassMapping(org.compass.core.mapping.CompassMapping) ResourceMapping(org.compass.core.mapping.ResourceMapping) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with ResourceMapping

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;
                    }
                }
            }
        }
    }
}
Also used : ClassMapping(org.compass.core.mapping.osem.ClassMapping) ResourceMapping(org.compass.core.mapping.ResourceMapping) ComponentMapping(org.compass.core.mapping.osem.ComponentMapping) ResourceMapping(org.compass.core.mapping.ResourceMapping) ClassMapping(org.compass.core.mapping.osem.ClassMapping) Mapping(org.compass.core.mapping.Mapping) CompassMapping(org.compass.core.mapping.CompassMapping) ComponentMapping(org.compass.core.mapping.osem.ComponentMapping) InvocationTargetException(java.lang.reflect.InvocationTargetException) CacheException(net.sf.ehcache.CacheException)

Aggregations

CompassMapping (org.compass.core.mapping.CompassMapping)2 ResourceMapping (org.compass.core.mapping.ResourceMapping)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CacheException (net.sf.ehcache.CacheException)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Mapping (org.compass.core.mapping.Mapping)1 ClassMapping (org.compass.core.mapping.osem.ClassMapping)1 ComponentMapping (org.compass.core.mapping.osem.ComponentMapping)1 InternalCompassSession (org.compass.core.spi.InternalCompassSession)1 SearchSettingsImpl (ubic.gemma.model.common.search.SearchSettingsImpl)1