Package com.gentics.cr.monitoring

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


    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

   * @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

   * @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

   * @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

  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

   * @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

   * @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

   * @param fieldName fieldname.
   * @return string.
   */
  public final String highlight(final Query parsedQuery, final IndexReader reader, final int docId,
      final String fieldName) {
    UseCase uc = MonitorFactory.startUseCase("Highlight.WhitespaceVectorBolder.highlight()");
    StringBuilder result = new StringBuilder();
    if (fieldName != null && parsedQuery != null) {
      FastVectorHighlighter highlighter = new FastVectorHighlighter(true, true, new SimpleFragListBuilder(),
          new WhitespaceFragmentsBuilder(new String[] { getHighlightPrefix() },
              new String[] { getHighlightPostfix() }));
      FieldQuery fieldQuery = highlighter.getFieldQuery(parsedQuery);
      //highlighter.setTextFragmenter(new WordCountFragmenter(fragmentSize));

      //TokenStream tokenStream = analyzer.tokenStream(
      //    this.getHighlightAttribute(), new StringReader(attribute));
      try {
        UseCase ucFragments = MonitorFactory
            .startUseCase("Highlight.WhitespaceVectorBolder.highlight()#getFragments");
        //TextFragment[] frags = highlighter.getBestTextFragments(tokenStream,
        //    attribute, true, numMaxFragments);
        String[] frags = highlighter.getBestFragments(
          fieldQuery,
          reader,
          docId,
          fieldName,
          getFragmentSize(),
          getMaxFragments());
        ucFragments.stop();
        boolean first = true;
        if (frags != null) {
          for (String frag : frags) {
            frag = frag.replaceAll(REMOVE_TEXT_FROM_FRAGMENT_REGEX, "");
            if (!first) {
View Full Code Here

   * @return highlighted text.
   *
   */
  public final String highlight(final Query parsedQuery, final IndexReader reader, final int docId,
      final String fieldName) {
    UseCase uc = MonitorFactory.startUseCase("Highlight.VectorBolder.highlight()");
    String result = "";
    if (fieldName != null && parsedQuery != null) {
      FastVectorHighlighter highlighter = new FastVectorHighlighter(true, true, new SimpleFragListBuilder(),
          new ScoreOrderFragmentsBuilder(new String[] { getHighlightPrefix() },
              new String[] { getHighlightPostfix() }));
      FieldQuery fieldQuery = highlighter.getFieldQuery(parsedQuery);
      //highlighter.setTextFragmenter(new WordCountFragmenter(fragmentSize));

      //TokenStream tokenStream = analyzer.tokenStream(
      //    this.getHighlightAttribute(), new StringReader(attribute));
      try {
        UseCase ucFragments = MonitorFactory.startUseCase("Highlight.VectorBolder.highlight()#getFragments");
        //TextFragment[] frags = highlighter.getBestTextFragments(tokenStream,
        //    attribute, true, numMaxFragments);
        String[] frags = highlighter.getBestFragments(
          fieldQuery,
          reader,
          docId,
          fieldName,
          fragmentSize,
          numMaxFragments);
        ucFragments.stop();
        boolean first = true;
        if (frags != null) {
          for (String frag : frags) {
            frag = frag.replaceAll(REMOVE_TEXT_FROM_FRAGMENT_REGEX, "");
            if (!first) {
View Full Code Here

TOP

Related Classes of com.gentics.cr.monitoring.UseCase

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.