Return-Path: Delivered-To: apmail-lucene-java-commits-archive@www.apache.org Received: (qmail 25390 invoked from network); 12 Sep 2006 01:05:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Sep 2006 01:05:31 -0000 Received: (qmail 7794 invoked by uid 500); 12 Sep 2006 01:05:31 -0000 Delivered-To: apmail-lucene-java-commits-archive@lucene.apache.org Received: (qmail 7775 invoked by uid 500); 12 Sep 2006 01:05:31 -0000 Mailing-List: contact java-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-commits@lucene.apache.org Received: (qmail 7764 invoked by uid 99); 12 Sep 2006 01:05:31 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Sep 2006 18:05:31 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=gsingers@apache.org; spf=permerror X-ASF-Spam-Status: No, hits=-9.8 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received-SPF: error (idunn.apache.osuosl.org: domain apache.org from 140.211.166.113 cause and error) Received: from ([140.211.166.113:49242] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1 r(10620)) with ESMTP id A4/61-28385-0E706054 for ; Mon, 11 Sep 2006 18:05:37 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3998B1A981A; Mon, 11 Sep 2006 18:05:23 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r442406 - in /lucene/java/trunk: docs/ docs/lucene-sandbox/ src/java/org/apache/lucene/search/ xdocs/ xdocs/stylesheets/ Date: Tue, 12 Sep 2006 01:05:22 -0000 To: java-commits@lucene.apache.org From: gsingers@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060912010523.3998B1A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: gsingers Date: Mon Sep 11 18:05:20 2006 New Revision: 442406 URL: http://svn.apache.org/viewvc?view=rev&rev=442406 Log: Updated scoring.xml per suggestions by Doug and Chris on issue 664. Moved the Query information and Similarity info to the o.a.l.s package.html in the Javadocs and provided links to the javadocs from the scoring file. Added scoring.html into the project.xml so that it will now be live on the Lucene java site. Modified: lucene/java/trunk/docs/benchmarks.html lucene/java/trunk/docs/contributions.html lucene/java/trunk/docs/demo.html lucene/java/trunk/docs/demo2.html lucene/java/trunk/docs/demo3.html lucene/java/trunk/docs/demo4.html lucene/java/trunk/docs/features.html lucene/java/trunk/docs/fileformats.html lucene/java/trunk/docs/gettingstarted.html lucene/java/trunk/docs/index.html lucene/java/trunk/docs/lucene-sandbox/index.html lucene/java/trunk/docs/mailinglists.html lucene/java/trunk/docs/queryparsersyntax.html lucene/java/trunk/docs/resources.html lucene/java/trunk/docs/scoring.html lucene/java/trunk/docs/systemproperties.html lucene/java/trunk/docs/whoweare.html lucene/java/trunk/src/java/org/apache/lucene/search/package.html lucene/java/trunk/xdocs/scoring.xml lucene/java/trunk/xdocs/stylesheets/project.xml Modified: lucene/java/trunk/docs/benchmarks.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/benchmarks.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/benchmarks.html (original) +++ lucene/java/trunk/docs/benchmarks.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/contributions.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/contributions.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/contributions.html (original) +++ lucene/java/trunk/docs/contributions.html Mon Sep 11 18:05:20 2006 @@ -90,6 +90,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/demo.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/demo.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/demo.html (original) +++ lucene/java/trunk/docs/demo.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/demo2.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/demo2.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/demo2.html (original) +++ lucene/java/trunk/docs/demo2.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/demo3.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/demo3.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/demo3.html (original) +++ lucene/java/trunk/docs/demo3.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/demo4.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/demo4.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/demo4.html (original) +++ lucene/java/trunk/docs/demo4.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/features.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/features.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/features.html (original) +++ lucene/java/trunk/docs/features.html Mon Sep 11 18:05:20 2006 @@ -84,6 +84,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/fileformats.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/fileformats.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/fileformats.html (original) +++ lucene/java/trunk/docs/fileformats.html Mon Sep 11 18:05:20 2006 @@ -84,6 +84,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/gettingstarted.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/gettingstarted.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/gettingstarted.html (original) +++ lucene/java/trunk/docs/gettingstarted.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/index.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/index.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/index.html (original) +++ lucene/java/trunk/docs/index.html Mon Sep 11 18:05:20 2006 @@ -92,6 +92,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/lucene-sandbox/index.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/lucene-sandbox/index.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/lucene-sandbox/index.html (original) +++ lucene/java/trunk/docs/lucene-sandbox/index.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/mailinglists.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/mailinglists.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/mailinglists.html (original) +++ lucene/java/trunk/docs/mailinglists.html Mon Sep 11 18:05:20 2006 @@ -84,6 +84,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/queryparsersyntax.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/queryparsersyntax.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/queryparsersyntax.html (original) +++ lucene/java/trunk/docs/queryparsersyntax.html Mon Sep 11 18:05:20 2006 @@ -88,6 +88,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/resources.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/resources.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/resources.html (original) +++ lucene/java/trunk/docs/resources.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/scoring.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/scoring.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/scoring.html (original) +++ lucene/java/trunk/docs/scoring.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions @@ -336,126 +338,8 @@
    -

    - TermQuery -

    -

    Of the various implementations of - Query, the - TermQuery - is the easiest to understand and the most often used in applications. A TermQuery matches all the documents that contain the specified - Term, - which is a word that occurs in a certain - Field. - Thus, a TermQuery identifies and scores all - Documents that have a Field with the specified string in it. - Constructing a TermQuery - is as simple as: -

    -      TermQuery tq = new TermQuery(new Term("fieldName", "term");
    -		    
    In this example, the Query identifies all Documents that have the Field named "fieldName" and - contain the word "term". -

    -

    - BooleanQuery -

    -

    Things start to get interesting when one combines multiple - TermQuery instances into a BooleanQuery. - A BooleanQuery contains multiple - BooleanClauses, - where each clause contains a sub-query (Query - instance) and an operator (from BooleanClause.Occur) - describing how that sub-query is combined with the other clauses: -

      - -
    1. SHOULD -- Use this operator when a clause can occur in the result set, but is not required. - If a query is made up of all SHOULD clauses, then every document in the result - set matches at least one of these clauses.

    2. - -
    3. MUST -- Use this operator when a clause is required to occur in the result set. Every - document in the result set will match - all such clauses.

    4. - -
    5. MUST NOT -- Use this operator when a - clause must not occur in the result set. No - document in the result set will match - any such clauses.

    6. -
    - Boolean queries are constructed by adding two or more - BooleanClause - instances. If too many clauses are added, a TooManyClauses - exception will be thrown during searching. This most often occurs - when a Query - is rewritten into a BooleanQuery with many - TermQuery clauses, - for example by WildcardQuery. - The default setting for the maximum number - of clauses 1024, but this can be changed via the - static method setMaxClauseCount - in BooleanQuery. -

    -

    Phrases

    -

    Another common search is to find documents containing certain phrases. This - is handled in two different ways. -

      -
    1. -

      PhraseQuery - -- Matches a sequence of - Terms. - PhraseQuery uses a slop factor to determine - how many positions may occur between any two terms in the phrase and still be considered a match.

      -
    2. -
    3. -

      SpanNearQuery - -- Matches a sequence of other - SpanQuery - instances. SpanNearQuery allows for much more - complicated phrase queries since it is constructed from other to SpanQuery - instances, instead of only TermQuery instances.

      -
    4. -
    -

    -

    - RangeQuery -

    -

    The - RangeQuery - matches all documents that occur in the - exclusive range of a lower - Term - and an upper - Term. - For example, one could find all documents - that have terms beginning with the letters a through c. This type of Query is frequently used to - find - documents that occur in a specific date range. -

    -

    - PrefixQuery, - WildcardQuery -

    -

    While the - PrefixQuery - has a different implementation, it is essentially a special case of the - WildcardQuery. - The PrefixQuery allows an application - to identify all documents with terms that begin with a certain string. The WildcardQuery generalizes this by allowing - for the use of * (matches 0 or more characters) and ? (matches exactly one character) wildcards. Note that the WildcardQuery can be quite slow. Also note that - WildcardQuery should - not start with * and ?, as these are extremely slow. For tricks on how to search using a wildcard at - the beginning of a term, see - - Starts With x and Ends With x Queries - from the Lucene users's mailing list. -

    -

    - FuzzyQuery -

    -

    A - FuzzyQuery - matches documents that contain terms similar to the specified term. Similarity is - determined using - Levenshtein (edit) distance. - This type of query can be useful when accounting for spelling variations in the collection. +

    For information on the Query Classes, refer to the + search package javadocs

    @@ -469,36 +353,9 @@
    -

    Chances are DefaultSimilarity is sufficient for all your searching needs. - However, in some applications it may be necessary to customize your Similarity implementation. For instance, some applications do not need to - distinguish between shorter and longer documents (see a "fair" similarity).

    -

    To change Similarity, one must do so for both indexing and searching, and the changes must happen before - either of these actions take place. Although in theory there is nothing stopping you from changing mid-stream, it just isn't well-defined what is going to happen. -

    -

    To make this change, implement your own Similarity (likely you'll want to simply subclass - DefaultSimilarity) and then use the new - class by calling - IndexWriter.setSimilarity before indexing and - Searcher.setSimilarity before searching. -

    -

    - If you are interested in use cases for changing your similarity, see the Lucene users's mailing list at Overriding Similarity. - In summary, here are a few use cases: -

      -
    1. SweetSpotSimilarity -- SweetSpotSimilarity gives small increases as the frequency increases a small amount - and then greater increases when you hit the "sweet spot", i.e. where you think the frequency of terms is more significant.

    2. -
    3. Overriding tf -- In some applications, it doesn't matter what the score of a document is as long as a matching term occurs. In these - cases people have overridden Similarity to return 1 from the tf() method.

    4. -
    5. Changing Length Normalization -- By overriding lengthNorm, it is possible to discount how the length of a field contributes - to a score. In DefaultSimilarity, lengthNorm = 1 / (numTerms in field)^0.5, but if one changes this to be - 1 / (numTerms in field), all fields will be treated - "fairly".

    6. -
    - In general, Chris Hostetter sums it up best in saying (from the Lucene users's mailing list): -
    [One would override the Similarity in] ... any situation where you know more about your data then just that - it's "text" is a situation where it *might* make sense to to override your - Similarity method.
    -

    +

    One of the ways of changing the scoring characteristics of Lucene is to change the similarity factors. For information on + how to do this, see the + search package javadocs


    @@ -516,169 +373,10 @@
    -

    Changing scoring is an expert level task, so tread carefully and be prepared to share your code if - you want help. -

    -

    With the warning out of the way, it is possible to change a lot more than just the Similarity - when it comes to scoring in Lucene. Lucene's scoring is a complex mechanism that is grounded by - three main classes: -

      -
    1. - Query -- The abstract object representation of the user's information need.
    2. -
    3. - Weight -- The internal interface representation of the user's Query, so that Query objects may be reused.
    4. -
    5. - Scorer -- An abstract class containing common functionality for scoring. Provides both scoring and explanation capabilities.
    6. -
    - Details on each of these classes, and their children can be found in the subsections below. +

    At a much deeper level, one can affect scoring by implementing their own Query classes (and related scoring classes.) To learn more + about how to do this, refer to the + search package javadocs

    - - - - -
    - - The Query Class - -
    -
    -

    In some sense, the - Query - class is where it all begins. Without a Query, there would be - nothing to score. Furthermore, the Query class is the catalyst for the other scoring classes as it - is often responsible - for creating them or coordinating the functionality between them. The - Query class has several methods that are important for - derived classes: -

      -
    1. createWeight(Searcher searcher) -- A - Weight is the internal representation of the Query, so each Query implementation must - provide an implementation of Weight. See the subsection on The Weight Interface below for details on implementing the Weight interface.
    2. -
    3. rewrite(IndexReader reader) -- Rewrites queries into primitive queries. Primitive queries are: - TermQuery, - BooleanQuery, OTHERS????
    4. -
    -

    -
    -

    - - - - -
    - - The Weight Interface - -
    -
    -

    The - Weight - interface provides an internal representation of the Query so that it can be reused. Any - Searcher - dependent state should be stored in the Weight implementation, - not in the Query class. The interface defines 6 methods that must be implemented: -

      -
    1. - Weight#getQuery() -- Pointer to the Query that this Weight represents.
    2. -
    3. - Weight#getValue() -- The weight for this Query. For example, the TermQuery.TermWeight value is - equal to the idf^2 * boost * queryNorm
    4. -
    5. - - Weight#sumOfSquaredWeights() -- The sum of squared weights. Tor TermQuery, this is (idf * - boost)^2
    6. -
    7. - - Weight#normalize(float) -- Determine the query normalization factor. The query normalization may - allow for comparing scores between queries.
    8. -
    9. - - Weight#scorer(IndexReader) -- Construct a new - Scorer - for this Weight. See - The Scorer Class - below for help defining a Scorer. As the name implies, the - Scorer is responsible for doing the actual scoring of documents given the Query. -
    10. -
    11. - - Weight#explain(IndexReader, int) -- Provide a means for explaining why a given document was scored - the way it was.
    12. -
    -

    -
    -

    - - - - -
    - - The Scorer Class - -
    -
    -

    The - Scorer - abstract class provides common scoring functionality for all Scorer implementations and - is the heart of the Lucene scoring process. The Scorer defines the following abstract methods which - must be implemented: -

      -
    1. - Scorer#next() -- Advances to the next document that matches this Query, returning true if and only - if there is another document that matches.
    2. -
    3. - Scorer#doc() -- Returns the id of the - Document - that contains the match. Is not valid until next() has been called at least once. -
    4. -
    5. - Scorer#score() -- Return the score of the current document. This value can be determined in any - appropriate way for an application. For instance, the - TermScorer - returns the tf * Weight.getValue() * fieldNorm. -
    6. -
    7. - Scorer#skipTo(int) -- Skip ahead in the document matches to the document whose id is greater than - or equal to the passed in value. In many instances, skipTo can be - implemented more efficiently than simply looping through all the matching documents until - the target document is identified.
    8. -
    9. - Scorer#explain(int) -- Provides details on why the score came about.
    10. -
    -

    -
    -

    - - - - -
    - - Why would I want to add my own Query? - -
    -
    -

    In a nutshell, you want to add your own custom Query implementation when you think that Lucene's - aren't appropriate for the - task that you want to do. You might be doing some cutting edge research or you need more information - back - out of Lucene (similar to Doug adding SpanQuery functionality).

    -
    -

    - - - - -
    - - Examples - -
    -
    -

    FILL IN HERE

    -
    -

    Modified: lucene/java/trunk/docs/systemproperties.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/systemproperties.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/systemproperties.html (original) +++ lucene/java/trunk/docs/systemproperties.html Mon Sep 11 18:05:20 2006 @@ -86,6 +86,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/docs/whoweare.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/docs/whoweare.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/docs/whoweare.html (original) +++ lucene/java/trunk/docs/whoweare.html Mon Sep 11 18:05:20 2006 @@ -88,6 +88,8 @@
  • File Formats
  • +
  • Scoring +
  • Javadoc
  • Contributions Modified: lucene/java/trunk/src/java/org/apache/lucene/search/package.html URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/package.html?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/package.html (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/package.html Mon Sep 11 18:05:20 2006 @@ -3,13 +3,356 @@ + +

    Table Of Contents

    +

    +

      +
    1. Search Basics
    2. +
    3. The Query Classes
    4. +
    5. Changing the Scoring
    6. +
    +

    + +

    Search

    +

    Search over indices. Applications usually call {@link org.apache.lucene.search.Searcher#search(Query)} or {@link org.apache.lucene.search.Searcher#search(Query,Filter)}. + + +

    + +

    Query Classes

    +

    + TermQuery +

    + +

    Of the various implementations of + Query, the + TermQuery + is the easiest to understand and the most often used in applications. A TermQuery matches all the documents that contain the + specified + Term, + which is a word that occurs in a certain + Field. + Thus, a TermQuery identifies and scores all + Documents that have a Field with the specified string in it. + Constructing a TermQuery + is as simple as: +

    +        TermQuery tq = new TermQuery(new Term("fieldName", "term");
    +    
    In this example, the Query identifies all Documents that have the Field named "fieldName" and + contain the word "term". +

    +

    + BooleanQuery +

    + +

    Things start to get interesting when one combines multiple + TermQuery instances into a BooleanQuery. + A BooleanQuery contains multiple + BooleanClauses, + where each clause contains a sub-query (Query + instance) and an operator (from BooleanClause.Occur) + describing how that sub-query is combined with the other clauses: +

      + +
    1. SHOULD -- Use this operator when a clause can occur in the result set, but is not required. + If a query is made up of all SHOULD clauses, then every document in the result + set matches at least one of these clauses.

    2. + +
    3. MUST -- Use this operator when a clause is required to occur in the result set. Every + document in the result set will match + all such clauses.

    4. + +
    5. MUST NOT -- Use this operator when a + clause must not occur in the result set. No + document in the result set will match + any such clauses.

    6. +
    + Boolean queries are constructed by adding two or more + BooleanClause + instances. If too many clauses are added, a TooManyClauses + exception will be thrown during searching. This most often occurs + when a Query + is rewritten into a BooleanQuery with many + TermQuery clauses, + for example by WildcardQuery. + The default setting for the maximum number + of clauses 1024, but this can be changed via the + static method setMaxClauseCount + in BooleanQuery. +

    + +

    Phrases

    + +

    Another common search is to find documents containing certain phrases. This + is handled in two different ways. +

      +
    1. +

      PhraseQuery + -- Matches a sequence of + Terms. + PhraseQuery uses a slop factor to determine + how many positions may occur between any two terms in the phrase and still be considered a match.

      +
    2. +
    3. +

      SpanNearQuery + -- Matches a sequence of other + SpanQuery + instances. SpanNearQuery allows for + much more + complicated phrase queries since it is constructed from other to SpanQuery + instances, instead of only TermQuery + instances.

      +
    4. +
    +

    +

    + RangeQuery +

    + +

    The + RangeQuery + matches all documents that occur in the + exclusive range of a lower + Term + and an upper + Term. + For example, one could find all documents + that have terms beginning with the letters a through c. This type of Query is frequently used to + find + documents that occur in a specific date range. +

    +

    + PrefixQuery, + WildcardQuery +

    + +

    While the + PrefixQuery + has a different implementation, it is essentially a special case of the + WildcardQuery. + The PrefixQuery allows an application + to identify all documents with terms that begin with a certain string. The WildcardQuery generalizes this by allowing + for the use of * (matches 0 or more characters) and ? (matches exactly one character) wildcards. + Note that the WildcardQuery can be quite slow. Also + note that + WildcardQuery should + not start with * and ?, as these are extremely slow. For tricks on how to search using a wildcard + at + the beginning of a term, see + + Starts With x and Ends With x Queries + from the Lucene users's mailing list. +

    +

    + FuzzyQuery +

    + +

    A + FuzzyQuery + matches documents that contain terms similar to the specified term. Similarity is + determined using + Levenshtein (edit) distance. + This type of query can be useful when accounting for spelling variations in the collection. +

    + +

    Changing Similarity

    + +

    Chances are DefaultSimilarity is sufficient for all + your searching needs. + However, in some applications it may be necessary to customize your Similarity implementation. For instance, some + applications do not need to + distinguish between shorter and longer documents (see a "fair" similarity).

    + +

    To change Similarity, one must do so for both indexing and + searching, and the changes must happen before + either of these actions take place. Although in theory there is nothing stopping you from changing mid-stream, it + just isn't well-defined what is going to happen. +

    + +

    To make this change, implement your own Similarity (likely + you'll want to simply subclass + DefaultSimilarity) and then use the new + class by calling + IndexWriter.setSimilarity + before indexing and + Searcher.setSimilarity + before searching. +

    + +

    + If you are interested in use cases for changing your similarity, see the Lucene users's mailing list at Overriding Similarity. + In summary, here are a few use cases: +

      +
    1. SweetSpotSimilarity -- SweetSpotSimilarity gives small increases + as the frequency increases a small amount + and then greater increases when you hit the "sweet spot", i.e. where you think the frequency of terms is + more significant.

    2. +
    3. Overriding tf -- In some applications, it doesn't matter what the score of a document is as long as a + matching term occurs. In these + cases people have overridden Similarity to return 1 from the tf() method.

    4. +
    5. Changing Length Normalization -- By overriding lengthNorm, + it is possible to discount how the length of a field contributes + to a score. In DefaultSimilarity, + lengthNorm = 1 / (numTerms in field)^0.5, but if one changes this to be + 1 / (numTerms in field), all fields will be treated + "fairly".

    6. +
    + In general, Chris Hostetter sums it up best in saying (from the Lucene users's mailing list): +
    [One would override the Similarity in] ... any situation where you know more about your data then just + that + it's "text" is a situation where it *might* make sense to to override your + Similarity method.
    +

    + +

    Changing Scoring -- Expert Level

    + +

    Changing scoring is an expert level task, so tread carefully and be prepared to share your code if + you want help. +

    + +

    With the warning out of the way, it is possible to change a lot more than just the Similarity + when it comes to scoring in Lucene. Lucene's scoring is a complex mechanism that is grounded by + three main classes: +

      +
    1. + Query -- The abstract object representation of the + user's information need.
    2. +
    3. + Weight -- The internal interface representation of + the user's Query, so that Query objects may be reused.
    4. +
    5. + Scorer -- An abstract class containing common + functionality for scoring. Provides both scoring and explanation capabilities.
    6. +
    + Details on each of these classes, and their children can be found in the subsections below. +

    +

    The Query Class

    +

    In some sense, the + Query + class is where it all begins. Without a Query, there would be + nothing to score. Furthermore, the Query class is the catalyst for the other scoring classes as it + is often responsible + for creating them or coordinating the functionality between them. The + Query class has several methods that are important for + derived classes: +

      +
    1. createWeight(Searcher searcher) -- A + Weight is the internal representation of the + Query, so each Query implementation must + provide an implementation of Weight. See the subsection on The Weight Interface below for details on implementing the Weight + interface.
    2. +
    3. rewrite(IndexReader reader) -- Rewrites queries into primitive queries. Primitive queries are: + TermQuery, + BooleanQuery, OTHERS????
    4. +
    +

    +

    The Weight Interface

    +

    The + Weight + interface provides an internal representation of the Query so that it can be reused. Any + Searcher + dependent state should be stored in the Weight implementation, + not in the Query class. The interface defines 6 methods that must be implemented: +

      +
    1. + Weight#getQuery() -- Pointer to the + Query that this Weight represents.
    2. +
    3. + Weight#getValue() -- The weight for + this Query. For example, the TermQuery.TermWeight value is + equal to the idf^2 * boost * queryNorm
    4. +
    5. + + Weight#sumOfSquaredWeights() -- The sum of squared weights. Tor TermQuery, this is (idf * + boost)^2
    6. +
    7. + + Weight#normalize(float) -- Determine the query normalization factor. The query normalization may + allow for comparing scores between queries.
    8. +
    9. + + Weight#scorer(IndexReader) -- Construct a new + Scorer + for this Weight. See + The Scorer Class + below for help defining a Scorer. As the name implies, the + Scorer is responsible for doing the actual scoring of documents given the Query. +
    10. +
    11. + + Weight#explain(IndexReader, int) -- Provide a means for explaining why a given document was + scored + the way it was.
    12. +
    +

    +

    The Scorer Class

    +

    The + Scorer + abstract class provides common scoring functionality for all Scorer implementations and + is the heart of the Lucene scoring process. The Scorer defines the following abstract methods which + must be implemented: +

      +
    1. + Scorer#next() -- Advances to the next + document that matches this Query, returning true if and only + if there is another document that matches.
    2. +
    3. + Scorer#doc() -- Returns the id of the + Document + that contains the match. Is not valid until next() has been called at least once. +
    4. +
    5. + Scorer#score() -- Return the score of the + current document. This value can be determined in any + appropriate way for an application. For instance, the + TermScorer + returns the tf * Weight.getValue() * fieldNorm. +
    6. +
    7. + Scorer#skipTo(int) -- Skip ahead in + the document matches to the document whose id is greater than + or equal to the passed in value. In many instances, skipTo can be + implemented more efficiently than simply looping through all the matching documents until + the target document is identified.
    8. +
    9. + Scorer#explain(int) -- Provides + details on why the score came about.
    10. +
    +

    +

    Why would I want to add my own Query?

    + +

    In a nutshell, you want to add your own custom Query implementation when you think that Lucene's + aren't appropriate for the + task that you want to do. You might be doing some cutting edge research or you need more information + back + out of Lucene (similar to Doug adding SpanQuery functionality).

    +

    Examples

    +

    FILL IN HERE

    Modified: lucene/java/trunk/xdocs/scoring.xml URL: http://svn.apache.org/viewvc/lucene/java/trunk/xdocs/scoring.xml?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/xdocs/scoring.xml (original) +++ lucene/java/trunk/xdocs/scoring.xml Mon Sep 11 18:05:20 2006 @@ -184,281 +184,22 @@

    -

    - TermQuery -

    -

    Of the various implementations of - Query, the - TermQuery - is the easiest to understand and the most often used in applications. A TermQuery matches all the documents that contain the specified - Term, - which is a word that occurs in a certain - Field. - Thus, a TermQuery identifies and scores all - Documents that have a Field with the specified string in it. - Constructing a TermQuery - is as simple as: -

    -      TermQuery tq = new TermQuery(new Term("fieldName", "term");
    -		    
    In this example, the Query identifies all Documents that have the Field named "fieldName" and - contain the word "term". -

    -

    - BooleanQuery -

    -

    Things start to get interesting when one combines multiple - TermQuery instances into a BooleanQuery. - A BooleanQuery contains multiple - BooleanClauses, - where each clause contains a sub-query (Query - instance) and an operator (from BooleanClause.Occur) - describing how that sub-query is combined with the other clauses: -

      - -
    1. SHOULD -- Use this operator when a clause can occur in the result set, but is not required. - If a query is made up of all SHOULD clauses, then every document in the result - set matches at least one of these clauses.

    2. - -
    3. MUST -- Use this operator when a clause is required to occur in the result set. Every - document in the result set will match - all such clauses.

    4. - -
    5. MUST NOT -- Use this operator when a - clause must not occur in the result set. No - document in the result set will match - any such clauses.

    6. -
    - Boolean queries are constructed by adding two or more - BooleanClause - instances. If too many clauses are added, a TooManyClauses - exception will be thrown during searching. This most often occurs - when a Query - is rewritten into a BooleanQuery with many - TermQuery clauses, - for example by WildcardQuery. - The default setting for the maximum number - of clauses 1024, but this can be changed via the - static method setMaxClauseCount - in BooleanQuery. -

    - -

    Phrases

    -

    Another common search is to find documents containing certain phrases. This - is handled in two different ways. -

      -
    1. -

      PhraseQuery - -- Matches a sequence of - Terms. - PhraseQuery uses a slop factor to determine - how many positions may occur between any two terms in the phrase and still be considered a match.

      -
    2. -
    3. -

      SpanNearQuery - -- Matches a sequence of other - SpanQuery - instances. SpanNearQuery allows for much more - complicated phrase queries since it is constructed from other to SpanQuery - instances, instead of only TermQuery instances.

      -
    4. -
    -

    -

    - RangeQuery -

    -

    The - RangeQuery - matches all documents that occur in the - exclusive range of a lower - Term - and an upper - Term. - For example, one could find all documents - that have terms beginning with the letters a through c. This type of Query is frequently used to - find - documents that occur in a specific date range. -

    -

    - PrefixQuery, - WildcardQuery -

    -

    While the - PrefixQuery - has a different implementation, it is essentially a special case of the - WildcardQuery. - The PrefixQuery allows an application - to identify all documents with terms that begin with a certain string. The WildcardQuery generalizes this by allowing - for the use of * (matches 0 or more characters) and ? (matches exactly one character) wildcards. Note that the WildcardQuery can be quite slow. Also note that - WildcardQuery should - not start with * and ?, as these are extremely slow. For tricks on how to search using a wildcard at - the beginning of a term, see - - Starts With x and Ends With x Queries - from the Lucene users's mailing list. -

    -

    - FuzzyQuery -

    -

    A - FuzzyQuery - matches documents that contain terms similar to the specified term. Similarity is - determined using - Levenshtein (edit) distance. - This type of query can be useful when accounting for spelling variations in the collection. +

    For information on the Query Classes, refer to the + search package javadocs

    -

    Chances are DefaultSimilarity is sufficient for all your searching needs. - However, in some applications it may be necessary to customize your Similarity implementation. For instance, some applications do not need to - distinguish between shorter and longer documents (see a "fair" similarity).

    - -

    To change Similarity, one must do so for both indexing and searching, and the changes must happen before - either of these actions take place. Although in theory there is nothing stopping you from changing mid-stream, it just isn't well-defined what is going to happen. -

    - -

    To make this change, implement your own Similarity (likely you'll want to simply subclass - DefaultSimilarity) and then use the new - class by calling - IndexWriter.setSimilarity before indexing and - Searcher.setSimilarity before searching. -

    -

    - If you are interested in use cases for changing your similarity, see the Lucene users's mailing list at Overriding Similarity. - In summary, here are a few use cases: -

      -
    1. SweetSpotSimilarity -- SweetSpotSimilarity gives small increases as the frequency increases a small amount - and then greater increases when you hit the "sweet spot", i.e. where you think the frequency of terms is more significant.

    2. -
    3. Overriding tf -- In some applications, it doesn't matter what the score of a document is as long as a matching term occurs. In these - cases people have overridden Similarity to return 1 from the tf() method.

    4. -
    5. Changing Length Normalization -- By overriding lengthNorm, it is possible to discount how the length of a field contributes - to a score. In DefaultSimilarity, lengthNorm = 1 / (numTerms in field)^0.5, but if one changes this to be - 1 / (numTerms in field), all fields will be treated - "fairly".

    6. -
    - In general, Chris Hostetter sums it up best in saying (from the Lucene users's mailing list): -
    [One would override the Similarity in] ... any situation where you know more about your data then just that - it's "text" is a situation where it *might* make sense to to override your - Similarity method.
    -

    +

    One of the ways of changing the scoring characteristics of Lucene is to change the similarity factors. For information on + how to do this, see the + search package javadocs

    -

    Changing scoring is an expert level task, so tread carefully and be prepared to share your code if - you want help. -

    -

    With the warning out of the way, it is possible to change a lot more than just the Similarity - when it comes to scoring in Lucene. Lucene's scoring is a complex mechanism that is grounded by - three main classes: -

      -
    1. - Query -- The abstract object representation of the user's information need.
    2. -
    3. - Weight -- The internal interface representation of the user's Query, so that Query objects may be reused.
    4. -
    5. - Scorer -- An abstract class containing common functionality for scoring. Provides both scoring and explanation capabilities.
    6. -
    - Details on each of these classes, and their children can be found in the subsections below. +

    At a much deeper level, one can affect scoring by implementing their own Query classes (and related scoring classes.) To learn more + about how to do this, refer to the + search package javadocs

    - -

    In some sense, the - Query - class is where it all begins. Without a Query, there would be - nothing to score. Furthermore, the Query class is the catalyst for the other scoring classes as it - is often responsible - for creating them or coordinating the functionality between them. The - Query class has several methods that are important for - derived classes: -

      -
    1. createWeight(Searcher searcher) -- A - Weight is the internal representation of the Query, so each Query implementation must - provide an implementation of Weight. See the subsection on The Weight Interface below for details on implementing the Weight interface.
    2. -
    3. rewrite(IndexReader reader) -- Rewrites queries into primitive queries. Primitive queries are: - TermQuery, - BooleanQuery, OTHERS????
    4. -
    -

    -
    - -

    The - Weight - interface provides an internal representation of the Query so that it can be reused. Any - Searcher - dependent state should be stored in the Weight implementation, - not in the Query class. The interface defines 6 methods that must be implemented: -

      -
    1. - Weight#getQuery() -- Pointer to the Query that this Weight represents.
    2. -
    3. - Weight#getValue() -- The weight for this Query. For example, the TermQuery.TermWeight value is - equal to the idf^2 * boost * queryNorm
    4. -
    5. - - Weight#sumOfSquaredWeights() -- The sum of squared weights. Tor TermQuery, this is (idf * - boost)^2
    6. -
    7. - - Weight#normalize(float) -- Determine the query normalization factor. The query normalization may - allow for comparing scores between queries.
    8. -
    9. - - Weight#scorer(IndexReader) -- Construct a new - Scorer - for this Weight. See - The Scorer Class - below for help defining a Scorer. As the name implies, the - Scorer is responsible for doing the actual scoring of documents given the Query. -
    10. -
    11. - - Weight#explain(IndexReader, int) -- Provide a means for explaining why a given document was scored - the way it was.
    12. -
    -

    -
    - -

    The - Scorer - abstract class provides common scoring functionality for all Scorer implementations and - is the heart of the Lucene scoring process. The Scorer defines the following abstract methods which - must be implemented: -

      -
    1. - Scorer#next() -- Advances to the next document that matches this Query, returning true if and only - if there is another document that matches.
    2. -
    3. - Scorer#doc() -- Returns the id of the - Document - that contains the match. Is not valid until next() has been called at least once. -
    4. -
    5. - Scorer#score() -- Return the score of the current document. This value can be determined in any - appropriate way for an application. For instance, the - TermScorer - returns the tf * Weight.getValue() * fieldNorm. -
    6. -
    7. - Scorer#skipTo(int) -- Skip ahead in the document matches to the document whose id is greater than - or equal to the passed in value. In many instances, skipTo can be - implemented more efficiently than simply looping through all the matching documents until - the target document is identified.
    8. -
    9. - Scorer#explain(int) -- Provides details on why the score came about.
    10. -
    -

    -
    - -

    In a nutshell, you want to add your own custom Query implementation when you think that Lucene's - aren't appropriate for the - task that you want to do. You might be doing some cutting edge research or you need more information - back - out of Lucene (similar to Doug adding SpanQuery functionality).

    -
    - -

    FILL IN HERE

    -
    Modified: lucene/java/trunk/xdocs/stylesheets/project.xml URL: http://svn.apache.org/viewvc/lucene/java/trunk/xdocs/stylesheets/project.xml?view=diff&rev=442406&r1=442405&r2=442406 ============================================================================== --- lucene/java/trunk/xdocs/stylesheets/project.xml (original) +++ lucene/java/trunk/xdocs/stylesheets/project.xml Mon Sep 11 18:05:20 2006 @@ -19,6 +19,7 @@ +