Package com.esri.gpt.catalog.discovery

Examples of com.esri.gpt.catalog.discovery.DiscoveryResult


    // determine records counts
    QueryOptions qOptions = context.getRequestOptions().getQueryOptions();
    DiscoveryQuery query = this.getDiscoveryContext().getDiscoveryQuery();
    OperationResponse opResponse = context.getOperationResponse();
    Document responseDom = opResponse.getResponseDom();
    DiscoveryResult result = query.getResult();
    int numberOfRecordsMatched = result.getNumberOfHits();
    int numberOfRecordsReturned = 0;
    int nextRecord = 0;
    String rtname = qOptions.getResultType();
    boolean isHits = rtname.equalsIgnoreCase(CswConstants.ResultType_Hits);
    if (isHits || (query.getFilter().getMaxRecords() <= 0)) {
      if (numberOfRecordsMatched > 0) {
        nextRecord = 1;
      }
    } else {
      numberOfRecordsReturned = result.getRecords().size();
      if (numberOfRecordsReturned > 0) {
        if (numberOfRecordsReturned < numberOfRecordsMatched) {
          nextRecord = query.getFilter().getStartRecord() + numberOfRecordsReturned;
          if (nextRecord > numberOfRecordsMatched) nextRecord = 0;
        }
View Full Code Here


      boolean bExecuteQuery = true;
      boolean bProcessHits = true;
      RequestContext reqContext = this.getIndexAdapter().getRequestContext();
      BooleanQuery rootQuery = new BooleanQuery();
      DiscoveryFilter discoveryFilter = discoveryQuery.getFilter();
      DiscoveryResult discoveryResult = discoveryQuery.getResult();
      Discoverables returnables = discoveryQuery.getReturnables();
      if ((returnables == null) || (returnables.size() == 0) ||
          (discoveryFilter.getMaxRecords() <= 0)) {
        bProcessHits = false;
      }
     
      // CSW query provider options
      boolean isDublinCoreResponse = true;
      boolean isBriefResponse = false;
      boolean isSummaryResponse = false;
      QueryOptions cswQueryOptions = (QueryOptions)reqContext.getObjectMap().get(
          "com.esri.gpt.server.csw.provider.components.QueryOptions");
     
      // build the query (if no query was supplied, we'll query everything)
      LogicalClauseAdapter logicalAdapter = new LogicalClauseAdapter(this);
      LogicalClause rootClause = discoveryFilter.getRootClause();
      if ((rootClause == null) || (rootClause.getClauses().size() == 0)) {
        if (discoveryFilter.getMaxRecords() <= QUERYALL_THRESHOLD) {
          LOGGER.finer("No filter was supplied, querying all...");
          logicalAdapter.appendSelectAll(rootQuery);
        } else {
          LOGGER.finer("No filter was supplied, query will not be executed.");
          bExecuteQuery = false;
        }
      } else {
        logicalAdapter.adaptLogicalClause(rootQuery,rootClause);
        if ((rootQuery.clauses() == null) && (rootQuery.clauses().size() > 0)) {
          bExecuteQuery = false;
        }
      }
      if (!bExecuteQuery) return;
    
       
      // execute the query and process the hits if required
     
      // set the sort option
      Sort sortOption = null;
      if (bProcessHits && (searcher.maxDoc() > 0)) {
        sortOption = makeSortOption(discoveryQuery);
      }
     
      // filters
      Filter filter = null;
     
      // make the access control filter
      MetadataAcl acl = new MetadataAcl(reqContext);
      AuthenticationStatus auth = reqContext.getUser().getAuthenticationStatus();
      boolean bAdmin = auth.getAuthenticatedRoles().hasRole("gptAdministrator");
      if (!bAdmin && !acl.isPolicyUnrestricted()) {
        String[] aclValues = acl.makeUserAcl();
        filter = new AclFilter(Storeables.FIELD_ACL,aclValues);
      }
     
      // isPartOf filter
      filter = IsPartOfFilter.make(reqContext,filter);
     
      // make the schema filter
      if (cswQueryOptions != null) {
        String schemaName = Val.chkStr(cswQueryOptions.getSchemaFilter());
        if (schemaName.length() > 0) {
          filter = new SchemaFilter(schemaName,filter);
          isDublinCoreResponse = cswQueryOptions.isDublinCoreResponse();
          if (!isDublinCoreResponse) {
            String elementSetType = Val.chkStr(cswQueryOptions.getElementSetType());
            if (elementSetType.equalsIgnoreCase("brief")) {
              isBriefResponse = true;
            } else if (elementSetType.equalsIgnoreCase("summary")) {
              isSummaryResponse = true;
            }
          }
        }
      }
     
     
      // determine the start/end positions
      int startRecord = discoveryFilter.getStartRecord() - 1;
      int maxRecords = discoveryFilter.getMaxRecords();
      if (startRecord < 0) startRecord = 0;
      int recordsPerPage = maxRecords;
      if (recordsPerPage <= 0) recordsPerPage = 1;
      int hitsToReturn = startRecord + recordsPerPage;
      int nextRecord = 0;
      int numDocs = 0;
     
      // execute the query
      LOGGER.finer("Executing Lucene Query:\n"+rootQuery);
      TopDocs topDocs = null;
      if (filter != null) {
        if (sortOption != null) {
          topDocs = searcher.search(rootQuery,filter,hitsToReturn,sortOption);
        } else {
          topDocs = searcher.search(rootQuery,filter,hitsToReturn);
        }
      } else {
        if (sortOption != null) {
          topDocs = searcher.search(rootQuery,filter,hitsToReturn,sortOption);
        } else {
          topDocs = searcher.search(rootQuery,hitsToReturn);
        }
      }
     
      // determine the hit count
      int totalHits = topDocs.totalHits;
      ScoreDoc[] scoreDocs = topDocs.scoreDocs;
      if ((scoreDocs != null) && (scoreDocs.length) > 0) {
        numDocs = scoreDocs.length;
        if (totalHits > numDocs) {
          nextRecord = numDocs + 1;
        }
      }
      discoveryResult.setNumberOfHits(totalHits);
      LOGGER.finer("Total query hits: "+totalHits);
     
      if (startRecord > (totalHits - 1)) bProcessHits = false;     
      if (maxRecords <= 0) bProcessHits = false;
      int nTotal = numDocs - startRecord;
      if (!bProcessHits) return;
       
      // warn if many records were requested
      if (nTotal >= TOOMANY_WARNING_THRESHOLD) {
        LOGGER.warning("A request to process "+nTotal+
            " discovery records was recieved and will be exceuted.\n"+discoveryQuery.toString());
      }
              
      // process the hits, build the results
      LOGGER.finer("Processing "+nTotal+" records from: "+(startRecord+1)+" to: "+numDocs);
      Storeable storeable;
      DiscoveredRecords records = discoveryResult.getRecords();
      IndexReader reader = searcher.getIndexReader();
      for (int i=startRecord; i<numDocs; i++) {
        ScoreDoc scoreDoc = scoreDocs[i];
        Document document = reader.document(scoreDoc.doc);
        DiscoveredRecord record = new DiscoveredRecord();
View Full Code Here

TOP

Related Classes of com.esri.gpt.catalog.discovery.DiscoveryResult

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.