Examples of UseCase


Examples of com.gentics.cr.monitoring.UseCase

      final Collection<CRResolvableBean> slice, final Map<String, Boolean> attributes, final RequestProcessor rp,
      final boolean create, final CRConfigUtil config, final List<ContentTransformer> transformerlist,
      final List<String> reverseattributes, final TaxonomyWriter taxonomyWriter, final TaxonomyAccessor taxonomyAccessor)
      throws CRException, IOException {
    // prefill all needed attributes
    UseCase uc = MonitorFactory.startUseCase("indexSlice(" + crid + ")");
    try {
      CRRequest req = new CRRequest();
      String[] prefillAttributes = attributes.keySet().toArray(new String[0]);
      req.setAttributeArray(prefillAttributes);
      UseCase prefillCase = MonitorFactory.startUseCase("indexSlice(" + crid + ").prefillAttributes");
      rp.fillAttributes(slice, req, idAttribute);
      prefillCase.stop();
      for (Resolvable objectToIndex : slice) {
        CRResolvableBean bean = new CRResolvableBean(objectToIndex, prefillAttributes);
        UseCase bcase = MonitorFactory.startUseCase("indexSlice(" + crid + ").indexBean");
        try {
          //CALL PRE INDEX PROCESSORS/TRANSFORMERS
          //TODO This could be optimized for multicore servers with
          //a map/reduce algorithm
          if (transformerlist != null) {
            for (ContentTransformer transformer : transformerlist) {
              try {

                if (transformer.match(bean)) {
                  String msg = "TRANSFORMER: " + transformer.getTransformerKey() + "; BEAN: " + bean.get(idAttribute);
                  status.setCurrentStatusString(msg);
                  ContentTransformer.getLogger().debug(msg);
                  if (transformer instanceof AbstractLuceneMonitoringTransformer) {
                    ((AbstractLuceneMonitoringTransformer) transformer).processBeanWithMonitoring(bean, indexWriter);
                  } else {
                    transformer.processBeanWithMonitoring(bean);
                  }
                }
              } catch (Exception e) {
                //TODO Remember broken files
                log.error("Error while Transforming Contentbean" + "with id: " + bean.get(idAttribute) + " Transformer: "
                    + transformer.getTransformerKey() + " " + transformer.getClass().getName(), e);
              }
            }
          }
          Term idTerm = new Term(idAttribute, bean.getString(idAttribute));
          Document docToUpdate = getUniqueDocument(indexReader, idTerm, crid);

          // get the category paths for the facets
          CategoryDocumentBuilder categoryDocBuilder = null;
          if (useFacets && taxonomyAccessor != null && taxonomyWriter != null) {
            List<CategoryPath> categories = getCategoryAttributeMapping(bean, taxonomyAccessor.getTaxonomyMappings());
            if (categories.size() > 0) {
              categoryDocBuilder = new CategoryDocumentBuilder(taxonomyWriter).setCategoryPaths(categories);
            }
          }
          if (!create && docToUpdate != null) {
            Document doc = getDocument(docToUpdate, bean, attributes, config, reverseattributes);
            // add facets to document
            if (categoryDocBuilder != null) {
              categoryDocBuilder.build(doc);
            }
            indexWriter.updateDocument(idTerm, doc);
          } else {
            Document doc = getDocument(null, bean, attributes, config, reverseattributes);
            // add facets to document
            if (categoryDocBuilder != null) {
              categoryDocBuilder.build(doc);
            }
            indexWriter.addDocument(doc);
          }
        } finally {
          bcase.stop();
        }
        //Stop Indexing when thread has been interrupted
        if (Thread.currentThread().isInterrupted()) {
          break;
        }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

  @Override
  public void deleteStaleObjects() {
    log.debug(checkedDocuments.size() + " objects checked, " + docs.size() + " objects already in the index.");
    IndexReader writeReader = null;
    boolean readerNeedsWrite = true;
    UseCase deleteStale = MonitorFactory.startUseCase("LuceneIndexUpdateChecker.deleteStaleObjects(" + indexLocation.getName() + ")");
    try {
      boolean objectsDeleted = false;
      for (String contentId : docs.keySet()) {
        if (!checkedDocuments.contains(contentId)) {
          log.debug("Object " + contentId + " wasn't checked in the last run. So i will delete it.");
          if (writeReader == null) {
            writeReader = indexAccessor.getReader(readerNeedsWrite);
          }
          writeReader.deleteDocument(docs.get(contentId));
          objectsDeleted = true;
        }
      }
      if (objectsDeleted) {
        indexLocation.createReopenFile();
      }
    } catch (IOException e) {
      log.error("Cannot delete objects from index.", e);
    } finally {
      //always release writeReader it blocks other threads if you don't
      if (writeReader != null) {
        indexAccessor.release(writeReader, readerNeedsWrite);
      }
      log.debug("Finished cleaning stale documents");
      deleteStale.stop();
    }
    checkedDocuments.clear();
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

    }

  }

  private synchronized void reIndex() throws IOException {
    UseCase ucReIndex = MonitorFactory.startUseCase("reIndex()");
    // build a dictionary (from the spell package)
    log.debug("Starting to reindex didyoumean index.");
    IndexAccessor sourceAccessor = didyoumean.getSourceLocation().getAccessor();
    IndexReader sourceReader = sourceAccessor.getReader(false);
    CustomSpellChecker spellchecker = didyoumean.getSpellchecker();
    Collection<String> fields = null;

    if (didyoumean.isAll()) {
      fields = sourceReader.getFieldNames(IndexReader.FieldOption.ALL);
    } else {
      fields = didyoumean.getDym_fields();
    }
    try {
      for (String fieldname : fields) {
        LuceneDictionary dict = new LuceneDictionary(sourceReader, fieldname);
        spellchecker.indexDictionary(dict);
      }
    } finally {
      if (sourceAccessor != null && sourceReader != null) {
        sourceAccessor.release(sourceReader, false);
      }
    }
    log.debug("Finished reindexing didyoumean index.");
    ucReIndex.stop();
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

    return result;
  }

  @Deprecated
  private synchronized void reIndex() throws IOException {
    UseCase ucReIndex = MonitorFactory.startUseCase("reIndex()");
    // build a dictionary (from the spell package)
    log.debug("Starting to reindex didyoumean index.");
    IndexReader sourceReader = IndexReader.open(source);
    Collection<String> fields = null;
    if (all) {
      fields = sourceReader.getFieldNames(IndexReader.FieldOption.ALL);
    } else {
      fields = dym_fields;
    }
    try {
      for (String fieldname : fields) {
        LuceneDictionary dict = new LuceneDictionary(sourceReader, fieldname);
        spellchecker.indexDictionary(dict);
      }
    } finally {
      sourceReader.close();
    }
    log.debug("Finished reindexing didyoumean index.");
    ucReIndex.stop();
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

   * @throws CRException
   */
  @Override
  public final Collection<CRResolvableBean> getObjects(final CRRequest request, final boolean doNavigation)
      throws CRException {
    UseCase ucGetObjects = startUseCase("LuceneRequestProcessor." + "getObjects(" + name + ")");

    /**
     * search preparations (instantiate/validate all needed variables)
     */
    UseCase ucPrepareSearch = startUseCase("LuceneRequestProcessor.getObjects(" + name + ")#prepareSearch");
    ArrayList<CRResolvableBean> result = new ArrayList<CRResolvableBean>();
    int count = getCount(request);
    int start = getStart(request);
    ucPrepareSearch.stop();
    /** * search preparations */

    /**
     * Get results
     */
    long indexSearchStartTime = System.currentTimeMillis();
    UseCase ucSearch = startUseCase("LuceneRequestProcessor." + "getObjects(" + name + ")#search");
    HashMap<String, Object> searchResult = null;
    try {
      searchResult = searcher.search(
        request.getRequestFilter(),
        getSearchedAttributes(),
        count,
        start,
        doNavigation,
        request.getSortArray(),
        request);
    } catch (IOException ex) {
      LOGGER.error("Error while getting search results from index.");
      throw new CRException(ex);
    }
    ucSearch.stop();
    LOGGER.debug("Search in Index took " + (System.currentTimeMillis() - indexSearchStartTime) + "ms");
    /**
     * process search
     */
    UseCase ucProcessSearch = startUseCase("LuceneRequestProcessor." + "getObjects(" + name + ")#processSearch");
    if (searchResult != null) {
      Query parsedQuery = (Query) searchResult.get(CRSearcher.RESULT_QUERY_KEY);

      result = processMetaData(result, searchResult, parsedQuery, request, start, count);
      result = processSearchResolvables(result, searchResult, parsedQuery, request);
    } else {
      // searchresult is null - we don't want to proceed - we want to throw an error
      result = null;
    }
    ucProcessSearch.stop();
    /** * process search */

    ucGetObjects.stop();
    return result;
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

   * @return list of results with added metadata bean
   */
  private ArrayList<CRResolvableBean> processMetaData(final ArrayList<CRResolvableBean> result,
    final HashMap<String, Object> searchResult, final Query parsedQuery, final CRRequest request,
    final int start, final int count) {
    UseCase ucProcessSearchMeta = startUseCase("LuceneRequestProcessor.getObjects(" + name
      + ")#processSearch.Metaresolvables");

    Object metaKey = request.get(META_RESOLVABLE_KEY);
    if (metaKey != null && (Boolean) metaKey) {
      final CRResolvableBean metaBean;
      if (showParsedQuery) {
        metaBean = new CRMetaResolvableBean(searchResult, request, parsedQuery, start, count);
      } else {
        metaBean = new CRMetaResolvableBean(searchResult, request, start, count);
      }
      result.add(metaBean);
    }

    ucProcessSearchMeta.stop();
    return result;
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

   * @param request needed for highlighting the query
   * @return list of results containing all documents
   */
  private ArrayList<CRResolvableBean> processSearchResolvables(final ArrayList<CRResolvableBean> result,
    final HashMap<String, Object> searchResult, Query parsedQuery, final CRRequest request) {
    UseCase ucProcessSearchResolvables = startUseCase("LuceneRequestProcessor.getObjects(" + name
      + ")#processSearch.Resolvables");

    LinkedHashMap<Document, Float> docs = objectToLinkedHashMapDocuments(searchResult
      .get(CRSearcher.RESULT_RESULT_KEY));

    LuceneIndexLocation idsLocation = LuceneIndexLocation.getIndexLocation(config);
    IndexAccessor indexAccessor = idsLocation.getAccessor();
    IndexReader reader = null;
    try {
      reader = indexAccessor.getReader(false);

      parsedQuery = parseHighlightQuery(request, reader, parsedQuery);

      processDocuments(docs, result, reader, parsedQuery);

    } catch (IOException e) {
      LOGGER.error("Cannot get Index reader for highlighting", e);
    } finally {
      indexAccessor.release(reader, false);
    }

    ucProcessSearchResolvables.stop();
    return result;
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

  private void doHighlighting(final CRResolvableBean crBean, final Document doc, final Query parsedQuery,
      final IndexReader reader) {

    //IF HIGHLIGHTERS ARE CONFIGURED => DO HIGHLIGHTNING
    if (highlighters != null) {
      UseCase ucProcessSearchHighlight = MonitorFactory.startUseCase("LuceneRequestProcessor." + "getObjects("
          + name + ")#processSearch.Highlight");
      long s2 = System.currentTimeMillis();
      for (Entry<String, ContentHighlighter> contentHighlighter : highlighters.entrySet()) {
        ContentHighlighter highligther = contentHighlighter.getValue();
        String att = contentHighlighter.getKey();
        //IF crBean matches the highlighters rule => highlight
        if (highligther.match(crBean)) {
          String ret = null;
          if (highligther instanceof AdvancedContentHighlighter) {
            AdvancedContentHighlighter advancedHighlighter = (AdvancedContentHighlighter) highligther;
            int documentId = Integer.parseInt(doc.get("id"));

            ret = advancedHighlighter.highlight(parsedQuery, reader, documentId, att);

          } else {
            ret = highligther.highlight((String) crBean.get(att), parsedQuery);
          }
          if (ret != null && !"".equals(ret)) {
            crBean.set(att, ret);
          }
        }
      }
      LOGGER.debug("Highlighters took " + (System.currentTimeMillis() - s2) + "ms");
      ucProcessSearchHighlight.stop();
    }
  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

   * @param originalTermText
   * @param tokenGroup
   * @return highlightedterm
   */
  public final String highlightTerm(final String originalTermText, final TokenGroup tokenGroup) {
    UseCase uc = MonitorFactory.startUseCase("Highlight.PhraseBolder.highlightTerm()");
    if (tokenGroup.getTotalScore() <= 0) {
      uc.stop();
      return originalTermText;
    }
    uc.stop();
    return getHighlightPrefix() + originalTermText + getHighlightPostfix();

  }
View Full Code Here

Examples of com.gentics.cr.monitoring.UseCase

   * @param parsedQuery
   * @return highlighted text
   *
   */
  public final String highlight(final String attribute, final Query parsedQuery) {
    UseCase uc = MonitorFactory.startUseCase("Highlight.PhraseBolder.highlight()");
    String result = "";
    if (attribute != null && parsedQuery != null) {
      Highlighter highlighter = new Highlighter(this, new QueryScorer(parsedQuery));
      highlighter.setTextFragmenter(new WordCountFragmenter(getFragmentSize()));

      TokenStream tokenStream = analyzer.tokenStream(this.getHighlightAttribute(), new StringReader(attribute));
      try {
        UseCase ucFragments = MonitorFactory.startUseCase("Highlight.PhraseBolder.highlight()#getFragments");
        TextFragment[] frags = highlighter
            .getBestTextFragments(tokenStream, attribute, true, getMaxFragments());
        ucFragments.stop();
        boolean first = true;
        int startPosition = -1;
        int endPosition = -1;
        for (TextFragment frag : frags) {
          String fragment = frag.toString();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.