Package org.apache.solr.search

Examples of org.apache.solr.search.SolrIndexSearcher$TermDocsState


      onDeckSearchers++;
    }

    // open the index synchronously
    // if this fails, we need to decrement onDeckSearchers again.
    SolrIndexSearcher tmp;
    try {
      if (onDeckSearchers < 1) {
        // should never happen... just a sanity check
        log.severe("ERROR!!! onDeckSearchers is " + onDeckSearchers);
        // reset to 1 (don't bother synchronizing)
        onDeckSearchers=1;
      } else if (onDeckSearchers > 1) {
        log.info("PERFORMANCE WARNING: Overlapping onDeckSearchers=" + onDeckSearchers);
      }
      tmp = new SolrIndexSearcher(schema, "main", index_path, true);
    } catch (Throwable th) {
      synchronized(searcherLock) {
        onDeckSearchers--;
        // notify another waiter to continue... it may succeed
        // and wake any others.
        searcherLock.notify();
      }
      // need to close the searcher here??? we shouldn't have to.
      throw new RuntimeException(th);
    }

    final SolrIndexSearcher newSearcher=tmp;

    RefCounted<SolrIndexSearcher> currSearcherHolder=null;
    final RefCounted<SolrIndexSearcher> newSearchHolder=newHolder(newSearcher);
    if (returnSearcher) newSearchHolder.incref();

    // a signal to decrement onDeckSearchers if something goes wrong.
    final boolean[] decrementOnDeckCount=new boolean[1];
    decrementOnDeckCount[0]=true;

    try {

      boolean alreadyRegistered = false;
      synchronized (searcherLock) {
        if (_searcher == null) {
          // if there isn't a current searcher then we may
          // want to register this one before warming is complete instead of waiting.
          if (SolrConfig.config.getBool("query/useColdSearcher",false)) {
            registerSearcher(newSearchHolder);
            decrementOnDeckCount[0]=false;
            alreadyRegistered=true;
          }
        } else {
          // get a reference to the current searcher for purposes of autowarming.
          currSearcherHolder=_searcher;
          currSearcherHolder.incref();
        }
      }


      final SolrIndexSearcher currSearcher = currSearcherHolder==null ? null : currSearcherHolder.get();

      //
      // Note! if we registered the new searcher (but didn't increment it's
      // reference count because returnSearcher==false, it's possible for
      // someone else to register another searcher, and thus cause newSearcher
View Full Code Here


          _searcher.decref();   // dec refcount for this._searcher
          _searcher=null;
        }

        _searcher = newSearcherHolder;
        SolrIndexSearcher newSearcher = newSearcherHolder.get();

        newSearcher.register(); // register subitems (caches)
        log.info("Registered new searcher " + newSearcher);

      } catch (Throwable e) {
        log(e);
      } finally {
View Full Code Here

      }
      BrowseResult res = null;
      if (shardsVal == null && !solrParams.getBool(ShardParams.IS_SHARD, false))
    {

      SolrIndexSearcher searcher=rb.req.getSearcher();
     
      SolrIndexReader solrReader = searcher.getReader();
      BoboIndexReader reader = (BoboIndexReader)solrReader.getWrappedReader();
     
      if (reader instanceof BoboIndexReader){
          try {
            List<Query> filters = rb.getFilters();
View Full Code Here

  {
      SolrParams params = req.getParams();
     
      int flags = 0;
     
      SolrIndexSearcher s = req.getSearcher();
      IndexSchema schema = req.getSchema();
           
      Map<String,Float> queryFields = U.parseFieldBoosts(params.getParams(DMP.QF));
      Map<String,Float> phraseFields = U.parseFieldBoosts(params.getParams(DMP.PF));

      float tiebreaker = params.getFloat(DMP.TIE, 0.0f);
           
      int pslop = params.getInt(DMP.PS, 0);
      int qslop = params.getInt(DMP.QS, 0);

      /* a generic parser for parsing regular lucene queries */
      QueryParser p = schema.getSolrQueryParser(null);

      /* a parser for dealing with user input, which will convert
       * things to DisjunctionMaxQueries
       */
      U.DisjunctionMaxQueryParser up =
        new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
      up.addAlias(IMPOSSIBLE_FIELD_NAME,
                  tiebreaker, queryFields);
      up.setPhraseSlop(qslop);
     
      /* for parsing sloppy phrases using DisjunctionMaxQueries */
      U.DisjunctionMaxQueryParser pp =
        new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
      pp.addAlias(IMPOSSIBLE_FIELD_NAME,
                  tiebreaker, phraseFields);
      pp.setPhraseSlop(pslop);
           
           
      /* the main query we will execute.  we disable the coord because
       * this query is an artificial construct
       */
      BooleanQuery query = new BooleanQuery(true);

      /* * * Main User Query * * */
      Query parsedUserQuery = null;
      String userQuery = params.get( Q );
      Query altUserQuery = null;
      if( userQuery == null || userQuery.trim().length() < 1 ) {
        // If no query is specified, we may have an alternate
        String altQ = params.get( DMP.ALTQ );
        if (altQ != null) {
          altUserQuery = p.parse(altQ);
          query.add( altUserQuery , Occur.MUST );
        } else {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "missing query string" );
        }
      }
      else {
        // There is a valid query string
        userQuery = U.partialEscape(U.stripUnbalancedQuotes(userQuery)).toString();
           
        String minShouldMatch = params.get(DMP.MM, "100%");
        Query dis = up.parse(userQuery);
        parsedUserQuery = dis;
 
        if (dis instanceof BooleanQuery) {
          BooleanQuery t = new BooleanQuery();
          U.flattenBooleanQuery(t, (BooleanQuery)dis);
          U.setMinShouldMatch(t, minShouldMatch);               
          parsedUserQuery = t;
        }
        query.add(parsedUserQuery, Occur.MUST);
       

        /* * * Add on Phrases for the Query * * */
             
        /* build up phrase boosting queries */

        /* if the userQuery already has some quotes, stip them out.
         * we've already done the phrases they asked for in the main
         * part of the query, this is to boost docs that may not have
         * matched those phrases but do match looser phrases.
         */
        String userPhraseQuery = userQuery.replace("\"","");
        Query phrase = pp.parse("\"" + userPhraseQuery + "\"");
        if (null != phrase) {
          query.add(phrase, Occur.SHOULD);
        }
      }

           
      /* * * Boosting Query * * */
      String[] boostParams = params.getParams(DMP.BQ);
      List<Query> boostQueries = U.parseQueryStrings(req, boostParams);
      if (null != boostQueries) {
        if(1 == boostQueries.size() && 1 == boostParams.length) {
          /* legacy logic */
          Query f = boostQueries.get(0);
          if (1.0f == f.getBoost() && f instanceof BooleanQuery) {
            /* if the default boost was used, and we've got a BooleanQuery
             * extract the subqueries out and use them directly
             */
            for (Object c : ((BooleanQuery)f).clauses()) {
              query.add((BooleanClause)c);
            }
          } else {
            query.add(f, BooleanClause.Occur.SHOULD);
          }
        } else {
          for(Query f : boostQueries) {
            query.add(f, BooleanClause.Occur.SHOULD);
          }
        }
      }

      /* * * Boosting Functions * * */

      String[] boostFuncs = params.getParams(DMP.BF);
      if (null != boostFuncs && 0 != boostFuncs.length) {
        for (String boostFunc : boostFuncs) {
          if(null == boostFunc || "".equals(boostFunc)) continue;
          List<Query> funcs = U.parseFuncs(schema, boostFunc);
          for (Query f : funcs) {
            query.add(f, Occur.SHOULD);         
          }
        }
      }
           
      /* * * Restrict Results * * */

      List<Query> restrictions = U.parseFilterQueries(req);
           
      /* * * Generate Main Results * * */

      flags |= U.setReturnFields(req,rsp);
     
      DocListAndSet results = new DocListAndSet();
      NamedList facetInfo = null;
      if (params.getBool(FACET,false)) {
        results = s.getDocListAndSet(query, restrictions,
                                     SolrPluginUtils.getSort(req),
                                     req.getStart(), req.getLimit(),
                                     flags);
        facetInfo = getFacetInfo(req, rsp, results.docSet);
      } else {
        results.docList = s.getDocList(query, restrictions,
                                       SolrPluginUtils.getSort(req),
                                       req.getStart(), req.getLimit(),
                                       flags);
      }
      rsp.add("response",results.docList);
View Full Code Here

    writer.write('[');

    incLevel();
    boolean first=true;

    SolrIndexSearcher searcher = req.getSearcher();
    DocIterator iterator = ids.iterator();
    for (int i=0; i<sz; i++) {
      int id = iterator.nextDoc();
      Document doc = searcher.doc(id, fields);

      if (first) {
        first=false;
      } else {
        writer.write(',');
View Full Code Here

    } else {
      writer.write('>');
    }

    incLevel();
    SolrIndexSearcher searcher = request.getSearcher();
    DocIterator iterator = ids.iterator();
    for (int i=0; i<sz; i++) {
      int id = iterator.nextDoc();
      Document doc = searcher.doc(id, fields);
      writeDoc(null, doc, fields, (includeScore ? iterator.score() : 0.0f), includeScore);
    }
    decLevel();

    if (doIndent) indent();
View Full Code Here

    */
   public static NamedList doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
      if (!isHighlightingEnabled(req))
         return null;
     
      SolrIndexSearcher searcher = req.getSearcher();
      NamedList fragments = new SimpleOrderedMap();
      String[] fieldNames = getHighlightFields(query, req, defaultFields);
      Document[] readDocs = new Document[docs.size()];
      {
        // pre-fetch documents using the Searcher's doc cache
        Set<String> fset = new HashSet<String>();
        for(String f : fieldNames) { fset.add(f); }
        // fetch unique key if one exists.
        SchemaField keyField = req.getSearcher().getSchema().getUniqueKeyField();
        if(null != keyField)
          fset.add(keyField.getName())
        searcher.readDocs(readDocs, docs, fset);
      }

      // Highlight each document
      DocIterator iterator = docs.iterator();
      for (int i = 0; i < docs.size(); i++) {
         int docId = iterator.nextDoc();
         Document doc = readDocs[i];
         NamedList docSummaries = new SimpleOrderedMap();
         for (String fieldName : fieldNames) {
            fieldName = fieldName.trim();
            String[] docTexts = doc.getValues(fieldName);
            if (docTexts == null) continue;

            // get highlighter, and number of fragments for this field
            Highlighter highlighter = getHighlighter(query, fieldName, req);
            int numFragments = getMaxSnippets(fieldName, req);

            String[] summaries;
            TextFragment[] frag;
            if (docTexts.length == 1) {
               // single-valued field
               TokenStream tstream;
               try {
                  // attempt term vectors
                  tstream = TokenSources.getTokenStream(searcher.getReader(), docId, fieldName);
               }
               catch (IllegalArgumentException e) {
                  // fall back to analyzer
                  tstream = new TokenOrderingFilter(searcher.getSchema().getAnalyzer().tokenStream(fieldName, new StringReader(docTexts[0])), 10);
               }
               frag = highlighter.getBestTextFragments(tstream, docTexts[0], false, numFragments);
            }
            else {
               // multi-valued field
               MultiValueTokenStream tstream;
               tstream = new MultiValueTokenStream(fieldName, docTexts, searcher.getSchema().getAnalyzer(), true);
               frag = highlighter.getBestTextFragments(tstream, tstream.asSingleValue(), false, numFragments);
            }
            // convert fragments back into text
            // TODO: we can include score and position information in output as snippet attributes
            if (frag.length > 0) {
               ArrayList<String> fragTexts = new ArrayList<String>();
               for (int j = 0; j < frag.length; j++) {
                  if ((frag[j] != null) && (frag[j].getScore() > 0)) {
                     fragTexts.add(frag[j].toString());
                  }
               }
               summaries = fragTexts.toArray(new String[0]);
               if (summaries.length > 0)
     docSummaries.add(fieldName, summaries);
            }
         }
         String printId = searcher.getSchema().printableUniqueKey(doc);
         fragments.add(printId == null ? null : printId, docSummaries);
      }
      return fragments;
   }
View Full Code Here

  @Override
  public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
    // SolbaseCoreContainer creates empty core for reading schema, etc. so
    // don't warm up this core. only warm up shard cores
    if (!core.getName().equals("") && core.getName().indexOf("~") > 0) {
      final SolrIndexSearcher searcher = newSearcher;
      log.info("QuerySenderListener sending requests to " + core.getName());

      for (NamedList nlst : (List<NamedList>) args.get("queries")) {
        try {
          SolrQueryResponse rsp = new SolrQueryResponse();
View Full Code Here

    SolrQueryResponse rsp = rb.rsp;
    SolrParams params = req.getParams();
    if (!params.getBool(COMPONENT_NAME, true)) {
      return;
    }
    SolrIndexSearcher searcher = req.getSearcher();

    if (rb.getQueryCommand().getOffset() < 0) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'start' parameter cannot be negative");
    }

    // -1 as flag if not set.
    long timeAllowed = (long) params.getInt(CommonParams.TIME_ALLOWED, -1);

    // Optional: This could also be implemented by the top-level searcher
    // sending
    // a filter that lists the ids... that would be transparent to
    // the request handler, but would be more expensive (and would preserve
    // score
    // too if desired).
    String ids = params.get(ShardParams.IDS);
    if (ids != null) {
      List<String> idArr = StrUtils.splitSmart(ids, ",", true);
      int[] luceneIds = new int[idArr.size()];
      int docs = 0;
      for (int i = 0; i < idArr.size(); i++) {
        luceneIds[docs++] = Integer.parseInt(idArr.get(i));
      }

      // we are indexing docId as solr uniq_id. by doing this, we are
      // bound to INTEGER.MAX_VALUE ~= 2 billion
      // docs is number of docs
      DocListAndSet res = new DocListAndSet();
      res.docList = new DocSlice(0, docs, luceneIds, null, docs, 0, null);
      if (rb.isNeedDocSet()) {
        List<Query> queries = new ArrayList<Query>();
        queries.add(rb.getQuery());
        List<Query> filters = rb.getFilters();
        if (filters != null)
          queries.addAll(filters);
        res.docSet = searcher.getDocSet(queries);
      }
      rb.setResults(res);
      rsp.add("response", rb.getResults().docList);
      return;
    }

    SolrIndexSearcher.QueryCommand cmd = rb.getQueryCommand();
    cmd.setTimeAllowed(timeAllowed);
    SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult();
   
    searcher.search(result, cmd);
   
    rb.setResult(result);

    rsp.add("response", rb.getResults().docList);
    rsp.getToLog().add("hits", rb.getResults().docList.matches());

    // The query cache doesn't currently store sort field values, and
    // SolrIndexSearcher doesn't
    // currently have an option to return sort field values. Because of
    // this, we
    // take the documents given and re-derive the sort values.
    boolean fsv = req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES, false);
    if (fsv) {
      Sort sort = rb.getSortSpec().getSort();
      SortField[] sortFields = sort == null ? new SortField[] { SortField.FIELD_SCORE } : sort.getSort();
      NamedList sortVals = new NamedList(); // order is important for the
                          // sort fields
      Field field = new Field("dummy", "", Field.Store.YES, Field.Index.NO); // a
                                          // dummy
                                          // Field

      SolrIndexReader reader = searcher.getReader();
      SolrIndexReader[] readers = reader.getLeafReaders();
      SolrIndexReader subReader = reader;
      if (readers.length == 1) {
        // if there is a single segment, use that subReader and avoid
        // looking up each time
View Full Code Here

        // Add docs here and modify object inline in code
        rsp.add("response", docs);

        try {
            final SolrIndexSearcher searcher = req.getSearcher();
            final AtomicReader rdr = searcher.getAtomicReader();
            BytesRef tmp = null;
            final Terms terms = rdr.terms(ENTROPY_DATA_FIELD);

            if (terms == null) {
                rsp.add("more", false);
View Full Code Here

TOP

Related Classes of org.apache.solr.search.SolrIndexSearcher$TermDocsState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.