Examples of Highlighter


Examples of javax.swing.text.Highlighter

      int paramCount = pc.getParamCount();
      List paramLocs = null;
      if (paramCount>0) {
        paramLocs = new ArrayList(paramCount);
      }
      Highlighter h = tc.getHighlighter();

      try {

        // Get the range in which the caret can move before we hide
        // this tooltip.
        minPos = dot;
        maxPos = tc.getDocument().createPosition(dot-sb.length());
        int firstParamLen = 0;

        // Create the text to insert (keep it one completion for
        // performance and simplicity of undo/redo).
        int start = dot;
        for (int i=0; i<paramCount; i++) {
          FunctionCompletion.Parameter param = pc.getParam(i);
          String paramText = getParamText(param);
          if (i==0) {
            firstParamLen = paramText.length();
          }
          sb.append(paramText);
          int end = start + paramText.length();
          paramLocs.add(new Point(start, end));
          if (i<paramCount-1) {
            sb.append(pc.getProvider().getParameterListSeparator());
            start = end + 2;
          }
        }
        sb.append(pc.getProvider().getParameterListEnd());

        // Insert the parameter text and add highlights around the
        // parameters.
        tc.replaceSelection(sb.toString());
        for (int i=0; i<paramCount; i++) {
          Point pt = (Point)paramLocs.get(i);
           // "-1" is a workaround for Java Highlight issues.
          tags.add(h.addHighlight(pt.x-1, pt.y, p));
        }

        // Go back and start at the first parameter.
        tc.setCaretPosition(dot);
        if (pc.getParamCount()>0) {
View Full Code Here

Examples of javax.swing.text.Highlighter

        responsePanel.setTabFocus();
        responsePanel.requestFocus();
        break;
      }
       
        Highlighter hilite = txtArea.getHighlighter();
        HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
        try {
      hilite.removeAllHighlights();
      hilite.addHighlight(sm.getStart(), sm.getEnd(), painter);
      txtArea.setCaretPosition(sm.getStart());
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
View Full Code Here

Examples of name.pehl.karaka.client.model.Highlighter

    @Override
    public void onFindActivity(final Request request, final Callback callback)
    {
        final String query = request.getQuery();
        final Highlighter highlighter = new Highlighter(query);
        dispatcher.execute(new FindActivityAction(query), new KarakaCallback<FindActivityResult>(getEventBus())
        {
            @Override
            public void onSuccess(final FindActivityResult result)
            {
                List<Activity> activities = result.getActivities();
                if (!activities.isEmpty())
                {
                    List<NamedModelSuggestion<Activity>> suggestions = new ArrayList<NamedModelSuggestion<Activity>>();
                    for (Activity activity : activities)
                    {
                        StringBuilder displayString = new StringBuilder();
                        displayString.append(activity.getName());
                        if (activity.getDescription() != null)
                        {
                            displayString.append(": ").append(activity.getDescription());
                        }
                        if (activity.getProject() != null)
                        {
                            displayString.append(", (Project: ").append(activity.getProject().getName()).append(")");
                        }
                        NamedModelSuggestion<Activity> suggestion = new NamedModelSuggestion<Activity>(activity,
                                activity.getName(), highlighter.highlight(displayString.toString()));
                        suggestions.add(suggestion);
                    }
                    callback.onSuggestionsReady(request, new Response(suggestions));
                }
            }
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

        if (readerDir != null)
        {
          IndexReader     reader = IndexReader.open(readerDir);
          SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");

          mHighlighter = new Highlighter(formatter, new QueryScorer(query.rewrite(reader)));
        }
        else
        {
          throw new IOException("Couldn't find the correct index directory for this bot, channel, and server combination");
        }
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

        hits = searcher.search(query, new Sort(new SortField[] { dateSort, timeSort }));

        // only highlight in the message
        Query           keywordQuery = search_tool.getKeywordQuery();
        Highlighter       highlighter = null;
        if (keywordQuery != null)
        {
          Query         rewritten_query =  keywordQuery.rewrite(reader);
          SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");
         
          highlighter = new Highlighter(formatter, new QueryScorer(rewritten_query));
        }

        for (int i = offset; i < LIMIT + offset; i++)
        {
          if (i >= hits.length())
          {
            // handle partial full pages
            break;
          }

          Document doc = hits.doc(i);

          // pull in our values
          String   nickname = doc.getField("nickname").stringValue();
          String   message = doc.getField("message").stringValue();
          String   channelname = doc.getField("channel").stringValue();
          String   botname = doc.getField("botname").stringValue();
          String   servername = doc.getField("servername").stringValue();
          Date   moment = DateField.stringToDate(doc.getField("moment").stringValue());
          String   day = mOutputDateFormat.format(moment);
          String   time = mOutputTimeFormat.format(moment);
          String   outputday = mDateFormat.format(moment);

          // stolen directly from ChannelLog
          String nickcolor = (String)mNickColors.get(nickname);
          if (null == nickcolor)
          {
            nickcolor = ChannelLog.NICK_COLORS[mColorCounter++%ChannelLog.NICK_COLORS.length];
            mNickColors.put(nickname, nickcolor);
          }
          mTemplate.setValue("bgcolor", nickcolor);

          channelname = "#" + channelname;

          // output a header if we're no longer in our little
          // section of the world, i.e. date, server, channel, or
          // bot changed
          if (mCurrentDate == null || !mCurrentDate.equals(day) ||
            mCurrentServername == null || !mCurrentServername.equals(servername) ||
            mCurrentBotname == null || !mCurrentBotname.equals(botname) ||
            mCurrentChannelname == null || !mCurrentChannelname.equals(channelname))
          {
            mTemplate.setValue("day", day);
            mTemplate.setValue("botname", botname);
            mTemplate.setValue("servername", servername);
            mTemplate.setValue("channelname", channelname);

            try
            {
              SearchBean bean = new SearchBean();
              bean.setKeyword(submission.getKeyword());
              bean.setChannel(botname + " - " + channelname);
              bean.setDate(INPUT_DATE_FORMAT_SHORT.format(mDateFormat.parse(outputday)));

              setNamedOutputBean("SearchBean", bean);
            }
            catch (ParseException e)
            {
              Logger
                .getLogger("com.uwyn.drone.webui.elements.pub")
                .severe(ExceptionUtils.getExceptionStackTrace(e));
            }

            setOutput("day", outputday);
            setOutput("channelname", channelname);
            setOutput("botname", botname);
            setExitQuery(mTemplate, "show_channel_log", null, null);

            mTemplate.setBlock("day_header", "day_header");

            mCurrentDate = day;
            mCurrentServername = servername;
            mCurrentBotname = botname;
            mCurrentChannelname = channelname;
          }
          else
          {
            mTemplate.setValue("day_header", "");
          }

          // output the message
          mTemplate.setValue("time", time);

          // translate the \u0001ACTION command which corresponds to
          // /me so that the user's nickname is used instead
          StringBuffer message_buf = new StringBuffer();
          if (message.startsWith(ChannelLog.IRC_ACTION))
          {
            message_buf
              .append(nickname)
              .append(message.substring(ChannelLog.IRC_ACTION.length()));
          }
          else
          {
            message_buf.append(message);
          }

          String encoded_message = encodeHtml(message_buf.toString());

          if (highlighter != null)
          {
            TokenStream tokenStream = new StandardAnalyzer().tokenStream("message", new StringReader(encoded_message));
            String highlighted = highlighter.getBestFragments(tokenStream, encoded_message, 25, "...");

            if (!highlighted.equals(""))
            {
              encoded_message = highlighted;
            }
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

      // The highlighter needs a rewritten query to work with wildcard and fuzzy queries
      Query rewrittenQuery = manager.rewrite(mQuery);
      QueryScorer queryScorer = new QueryScorer(rewrittenQuery);
      // End added by Anders

      Highlighter highlighter = new Highlighter(
              new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>"), queryScorer);

      // Remark: the summary is at this point not a summary. It contains the
      // first n characters from the document. n is configurable (default: 250000)
      // We transform this summary into
      // a) a summary matching the search terms (highlighting)
      // b) and a shortend summary (200 characters)
//      int docId = hitScoreDocs[index].doc;

      Document document = getHitDocument(index);
      byte[] compressedFieldValue = document.getBinaryValue("summary");
      String text = null;
      if (compressedFieldValue != null) {
        text = CompressionTools.decompressString(compressedFieldValue);
      }

      if (text != null) {
        // Overwrite the content with a shortend summary
        String resSummary = RegainToolkit.createSummaryFromContent(text, 200);
        document.removeField("summary");
        if (resSummary != null) {
          //System.out.println("resSummary " + resSummary);
          document.add(new Field("summary", resSummary, Field.Store.NO, Field.Index.NOT_ANALYZED));
          document.add(new Field("summary", CompressionTools.compressString(resSummary), Field.Store.YES));

        }

        String resHighlSummary = null;
        // Remove 'html', this works the same way as PageResponse.printNoHTML()
        text = RegainToolkit.replace(text, "<", "&lt;");
        text = RegainToolkit.replace(text, ">", "&gt;");

        TokenStream tokenStream = mAnalyzer.tokenStream("content",
                new StringReader(text));
        // Get 3 best fragments and seperate with a " ... "
        resHighlSummary = highlighter.getBestFragments(tokenStream, text, 3, " ... ");

        if (resHighlSummary != null) {
          //System.out.println("Highlighted summary: " + resHighlSummary);
          // write the result back to the document in a new field
          document.add(new Field("highlightedSummary", resHighlSummary, Field.Store.NO, Field.Index.NOT_ANALYZED));
          document.add(new Field("highlightedSummary", CompressionTools.compressString(resHighlSummary), Field.Store.YES));
        }
      }
      // Highlight the title
      text = document.get("title");
      String resHighlTitle = null;
      if (text != null) {
        TokenStream tokenStream = mAnalyzer.tokenStream("content",
                new StringReader(text));
        // Get the best fragment
        resHighlTitle = highlighter.getBestFragment(tokenStream, text);
      }

      if (resHighlTitle != null) {
        // write the result back to the document in a new field
        //System.out.println("Highlighted title: " + resHighlTitle);
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

     */
    protected String escapeBestFragments(Query query, Fragmenter fragmenter,
                                         String indexedText, int numOfFragments, int alternativeLength) {

        // The HTML escaping forces us to first fragment with internal placeholders...
        Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(INTERNAL_BEGIN_HIT, INTERNAL_END_HIT), new QueryScorer(query));
        highlighter.setTextFragmenter(fragmenter);
        try {
            // Use the same analyzer as the indexer!
            TokenStream tokenStream = new StandardAnalyzer().tokenStream(null, new StringReader(indexedText));

            String unescapedFragements =
                    highlighter.getBestFragments(tokenStream, indexedText, numOfFragments, getFragmentSeparator());

            String escapedFragments = WikiUtil.escapeHtml(WikiUtil.removeMacros(unescapedFragements), false, false);

            // .. and then replace the internal placeholders with real tags after HTML has been escaped
            escapedFragments = escapedFragments.replaceAll(INTERNAL_BEGIN_HIT, getBeginHitTag());
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

   * @param doc
   * @param resultDocument
   * @throws IOException
   */
  private void doHighlight(Query query, Analyzer analyzer, Document doc, ResultDocument resultDocument) throws IOException {
    Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(HIGHLIGHT_PRE_TAG,HIGHLIGHT_POST_TAG) , new QueryScorer(query));
    // Get 3 best fragments of content and seperate with a "..."
    String content = doc.get(OlatDocument.CONTENT_FIELD_NAME);
    String title = doc.get(OlatDocument.TITLE_FIELD_NAME);
   
    Set terms = new HashSet();
    query.extractTerms(terms);
   
    try {
      //highlight content
      TokenStream tokenStream = analyzer.tokenStream(OlatDocument.CONTENT_FIELD_NAME, new StringReader(content));               
      String highlightResult = highlighter.getBestFragments(tokenStream, content, 3, HIGHLIGHT_SEPARATOR);
      // if no highlightResult is in content => look in description
      if (highlightResult.length() == 0) {
        String description = doc.get(OlatDocument.DESCRIPTION_FIELD_NAME);    
        tokenStream = analyzer.tokenStream(OlatDocument.DESCRIPTION_FIELD_NAME, new StringReader(description));               
        highlightResult = highlighter.getBestFragments(tokenStream, description, 3, HIGHLIGHT_SEPARATOR);
        resultDocument.setHighlightingDescription(true);
     
      resultDocument.setHighlightResult(highlightResult);
     
      //highlight title
      tokenStream = analyzer.tokenStream(OlatDocument.CONTENT_FIELD_NAME, new StringReader(title));               
      String highlightTitle = highlighter.getBestFragments(tokenStream, title, 3, " ")
      resultDocument.setHighlightTitle(highlightTitle);
    } catch (InvalidTokenOffsetsException e) {
      log.warn("", e);
    }
  } 
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

      System.out.println(query);
      System.out.println("Searching for: " + query.toString(FIELD_NAME));
      Hits hits = searcher.search(query);
     
      BoldFormatter formatter = new BoldFormatter();
      Highlighter highlighter =new Highlighter(formatter,new QueryScorer(query));
      highlighter.setTextFragmenter(new SimpleFragmenter(50));
      for (int i = 0; i < hits.length(); i++)
      {
        String text = hits.doc(i).get(FIELD_NAME);
        int maxNumFragmentsRequired = 5;
        String fragmentSeparator = "...";
        TermPositionVector tpv = (TermPositionVector)reader.getTermFreqVector(hits.id(i),FIELD_NAME);
        TokenStream tokenStream=TokenSources.getTokenStream(tpv);
        /*
        TokenStream tokenStream2=
          (new StandardAnalyzer())
          //XFactory.getWriterAnalyzer()
            .tokenStream(FIELD_NAME,new StringReader(text));
       
        do {
          Token t = tokenStream2.next();
          if(t==null)break;
          System.out.println("\t" + t.startOffset() + "," + t.endOffset() + "\t" + t.termText());
        }while(true);
        */
        String result =
          highlighter.getBestFragments(
            tokenStream, text, maxNumFragmentsRequired, fragmentSeparator);
        System.out.println("\n" + result);
      }
      reader.close();
    }catch(Exception e) {
View Full Code Here

Examples of org.apache.lucene.search.highlight.Highlighter

    query = query.rewrite(reader);
    System.out.println("Searching for: " + query.toString(FIELD_NAME));
    TopDocs hits = searcher.search(query, 10);

    BoldFormatter formatter = new BoldFormatter();
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
        query));
    highlighter.setTextFragmenter(new SimpleFragmenter(50));
    for (int i = 0; i < hits.scoreDocs.length; i++) {
      int docId = hits.scoreDocs[i].doc;
      Document hit = searcher.doc(docId);
      String text = hit.get(FIELD_NAME);
      int maxNumFragmentsRequired = 5;
      String fragmentSeparator = "...";
      TermPositionVector tpv = (TermPositionVector) reader
          .getTermFreqVector(docId, FIELD_NAME);
      TokenStream tokenStream = TokenSources.getTokenStream(tpv);
      String result = highlighter.getBestFragments(tokenStream, text,
          maxNumFragmentsRequired, fragmentSeparator);
      System.out.println("\n" + result);
    }
    reader.close();
  }
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.