Java Code Examples for org.apache.solr.search.SolrIndexSearcher#cacheInsert()

The following examples show how to use org.apache.solr.search.SolrIndexSearcher#cacheInsert() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrCachingPathScorer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Factory method used to create {@link SolrCachingPathScorer} instances.
 * @param acceptDocs 
 */
public static SolrCachingPathScorer create(SolrCachingPathWeight weight,
                                           LeafReaderContext context,
                                           SolrIndexSearcher searcher,
                                           SolrPathQuery wrappedPathQuery) throws IOException
{
    DocSet results = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_PATH_CACHE, wrappedPathQuery);
    if (results == null)
    {
        // Cache miss: get path query results and cache them
        WrappedQuery wrapped = new WrappedQuery(wrappedPathQuery);
        wrapped.setCache(false);
        results = searcher.getDocSet(wrapped);
        searcher.cacheInsert(CacheConstants.ALFRESCO_PATH_CACHE, wrappedPathQuery, results);
    }
    
    return new SolrCachingPathScorer(weight, results, context, searcher);
}
 
Example 2
Source File: SolrOwnerScorer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static SolrOwnerScorer createOwnerScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException
{
    if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER)
    {
        DocSet ownedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority);

        if (ownedDocs == null)
        {
            // Cache miss: query the index for docs where the owner matches the authority. 
            ownedDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_OWNER, authority)));
            searcher.cacheInsert(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority, ownedDocs);
        }
        return new SolrOwnerScorer(weight, ownedDocs, context, searcher);
    }
    
    // Return an empty doc set, as the authority isn't a user.
    return new SolrOwnerScorer(weight, new BitDocSet(new FixedBitSet(0)), context, searcher);
}
 
Example 3
Source File: SolrOwnerSetScorer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static SolrOwnerSetScorer createOwnerSetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities) throws IOException
{
    
    DocSet authorityOwnedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authorities);
    
    if(authorityOwnedDocs == null)
    {
        // Split the authorities. The first character in the authorities String
        // specifies the separator, e.g. ",jbloggs,abeecher"
        String[] auths = authorities.substring(1).split(authorities.substring(0, 1));

        BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
        for(String current : auths)
        {
            if (AuthorityType.getAuthorityType(current) == AuthorityType.USER)
            {
                bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_OWNER, current)), Occur.SHOULD);
            }
        }
        
        WrappedQuery wrapped = new WrappedQuery(bQuery.build());
        wrapped.setCache(false);
        authorityOwnedDocs = searcher.getDocSet(wrapped);
    
        searcher.cacheInsert(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authorities, authorityOwnedDocs);
    }
    
    // TODO: Cache the final set? e.g. searcher.cacheInsert(authorities, authorityOwnedDocs)
    return new SolrOwnerSetScorer(weight, authorityOwnedDocs, context, searcher);
   
}
 
Example 4
Source File: FeatureLogger.java    From lucene-solr with Apache License 2.0 3 votes vote down vote up
/**
 * Log will be called every time that the model generates the feature values
 * for a document and a query.
 *
 * @param docid
 *          Solr document id whose features we are saving
 * @param featuresInfo
 *          List of all the {@link LTRScoringQuery.FeatureInfo} objects which contain name and value
 *          for all the features triggered by the result set
 * @return true if the logger successfully logged the features, false
 *         otherwise.
 */

public boolean log(int docid, LTRScoringQuery scoringQuery,
    SolrIndexSearcher searcher, LTRScoringQuery.FeatureInfo[] featuresInfo) {
  final String featureVector = makeFeatureVector(featuresInfo);
  if (featureVector == null) {
    return false;
  }

  return searcher.cacheInsert(fvCacheName,
      fvCacheKey(scoringQuery, docid), featureVector) != null;
}