home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (Scorer.java)

This example Lucene source code file (Scorer.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

io, ioexception, ioexception, scorer, scorer, tokenstream, tokenstream

The Lucene Scorer.java source code

package org.apache.lucene.search.highlight;

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

import java.io.IOException;

import org.apache.lucene.analysis.TokenStream;

 * A Scorer is responsible for scoring a stream of tokens. These token scores
 * can then be used to compute {@link TextFragment} scores.
public interface Scorer {

   * Called to init the Scorer with a {@link TokenStream}. You can grab references to
   * the attributes you are interested in here and access them from {@link #getTokenScore()}.
   * @param tokenStream the {@link TokenStream} that will be scored.
   * @return either a {@link TokenStream} that the Highlighter should continue using (eg
   *         if you read the tokenSream in this method) or null to continue
   *         using the same {@link TokenStream} that was passed in.
   * @throws IOException
  public TokenStream init(TokenStream tokenStream) throws IOException;

   * Called when a new fragment is started for consideration.
   * @param newFragment the fragment that will be scored next
  public void startFragment(TextFragment newFragment);

   * Called for each token in the current fragment. The {@link Highlighter} will
   * increment the {@link TokenStream} passed to init on every call.
   * @return a score which is passed to the {@link Highlighter} class to influence the
   *         mark-up of the text (this return value is NOT used to score the
   *         fragment)
  public float getTokenScore();

   * Called when the {@link Highlighter} has no more tokens for the current fragment -
   * the Scorer returns the weighting it has derived for the most recent
   * fragment, typically based on the results of {@link #getTokenScore()}.
  public float getFragmentScore();


Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene Scorer.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.