Package org.apache.accumulo.examples.wikisearch.sample

Examples of org.apache.accumulo.examples.wikisearch.sample.Document


    for (String field : unevaluatedFieldList.split(","))
      this.unevaluatedFields.add(field);
  }
 
  public Document createDocument(Key key, Value value) {
    Document doc = new Document();

    eventFields.clear();
    ByteBuffer buf = ByteBuffer.wrap(value.get());
    eventFields.readObjectData(kryo, buf);
   
    // Set the id to the document id which is located in the colf
    String row = key.getRow().toString();
    String colf = key.getColumnFamily().toString();
    int idx = colf.indexOf(NULL_BYTE);
    String type = colf.substring(0, idx);
    String id = colf.substring(idx + 1);
    doc.setId(id);
    for (Entry<String,Collection<FieldValue>> entry : eventFields.asMap().entrySet()) {
      for (FieldValue fv : entry.getValue()) {
        Field val = new Field();
        val.setFieldName(entry.getKey());
        val.setFieldValue(new String(fv.getValue(), Charset.forName("UTF-8")));
        doc.getFields().add(val);
      }
    }
   
    // Add the pointer for the content.
    Field docPointer = new Field();
    docPointer.setFieldName("DOCUMENT");
    docPointer.setFieldValue("DOCUMENT:" + row + "/" + type + "/" + id);
    doc.getFields().add(docPointer);
   
    return doc;
  }
View Full Code Here


            count++;
            // The key that is returned by the EvaluatingIterator is not the same key that is in
            // the table. The value that is returned by the EvaluatingIterator is a kryo
            // serialized EventFields object.
            processResults.resume();
            Document d = this.createDocument(entry.getKey(), entry.getValue());
            results.getResults().add(d);
            processResults.suspend();
          }
          log.info(count + " matching entries found in optimized query.");
          optimizationSucceeded = true;
          processResults.stop();
        } catch (TableNotFoundException e) {
          log.error(this.getTableName() + "not found", e);
          throw new RuntimeException(this.getIndexTableName() + "not found", e);
        } finally {
          if (bs != null) {
            bs.close();
          }
        }
        optimizedEventQuery.stop();
      }
      optimizedQuery.stop();
    }
   
    // WE should look into finding a better way to handle whether we do an optimized query or not.
    // We are not setting up an else condition here because we may have aborted the logic early in the if statement.
    if (!optimizationSucceeded || ((null != orTerms && orTerms.size() > 0) && (indexedTerms.size() != fields.size()) && !orsAllIndexed)) {
      // if (!optimizationSucceeded || ((null != orTerms && orTerms.size() > 0) && (indexedTerms.size() != fields.size()))) {
      fullScanQuery.start();
      if (log.isDebugEnabled()) {
        log.debug(hash + " Performing full scan query");
      }
     
      // Set up a full scan using the date ranges from the query
      // Create BatchScanner, set the ranges, and setup the iterators.
      BatchScanner bs = null;
      try {
        // The ranges are the start and end dates
        Collection<Range> r = getFullScanRange(beginDate, endDate, terms);
        ranges.addAll(r);
       
        if (log.isDebugEnabled()) {
          log.debug(hash + " Ranges: count: " + ranges.size() + ", " + ranges.toString());
        }
       
        bs = connector.createBatchScanner(this.getTableName(), auths, queryThreads);
        bs.setRanges(ranges);
        IteratorSetting si = new IteratorSetting(22, "eval", EvaluatingIterator.class);
        // Create datatype regex if needed
        if (null != typeFilter) {
          StringBuilder buf = new StringBuilder();
          String s = "";
          for (String type : typeFilter) {
            buf.append(s).append(type).append(".*");
            s = "|";
          }
          if (log.isDebugEnabled())
            log.debug("Setting colf regex iterator to: " + buf.toString());
          IteratorSetting ri = new IteratorSetting(21, "typeFilter", RegExFilter.class);
          RegExFilter.setRegexs(ri, null, buf.toString(), null, null, false);
          bs.addScanIterator(ri);
        }
        if (log.isDebugEnabled()) {
          log.debug("Setting scan option: " + EvaluatingIterator.QUERY_OPTION + " to " + queryString);
        }
        si.addOption(EvaluatingIterator.QUERY_OPTION, queryString);
        if (null != unevaluatedExpressions) {
          StringBuilder unevaluatedExpressionList = new StringBuilder();
          String sep2 = "";
          for (String exp : unevaluatedExpressions) {
            unevaluatedExpressionList.append(sep2).append(exp);
            sep2 = ",";
          }
          if (log.isDebugEnabled())
            log.debug("Setting scan option: " + EvaluatingIterator.UNEVALUTED_EXPRESSIONS + " to " + unevaluatedExpressionList.toString());
          si.addOption(EvaluatingIterator.UNEVALUTED_EXPRESSIONS, unevaluatedExpressionList.toString());
        }
        bs.addScanIterator(si);
        long count = 0;
        processResults.start();
        processResults.suspend();
        for (Entry<Key,Value> entry : bs) {
          count++;
          // The key that is returned by the EvaluatingIterator is not the same key that is in
          // the partition table. The value that is returned by the EvaluatingIterator is a kryo
          // serialized EventFields object.
          processResults.resume();
          Document d = this.createDocument(entry.getKey(), entry.getValue());
          results.getResults().add(d);
          processResults.suspend();
        }
        processResults.stop();
        log.info(count + " matching entries found in full scan query.");
View Full Code Here

      try {
        Scanner scanner = connector.createScanner(this.getTableName(), auths);
        scanner.setRange(r);
        // This should in theory only match one thing.
        for (Entry<Key,Value> entry : scanner) {
          Document doc = new Document();
          doc.setId(id);
          Field val = new Field();
          val.setFieldName("DOCUMENT");
          val.setFieldValue(new String(Base64.decodeBase64(entry.getValue().toString())));
          doc.getFields().add(val);
          results.getResults().add(doc);
        }
      } catch (TableNotFoundException e) {
        throw new RuntimeException("Table not found: " + this.getTableName(), e);
      }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.examples.wikisearch.sample.Document

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.