<commit_before>/*
 * Copyright 2011 Internet Archive
 *
 * Licensed 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,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.archive.jbs.lucene;

import java.io.*;
import java.net.*;
import java.util.*;

import org.apache.lucene.document.*;
import org.apache.lucene.index.*;

import org.archive.jbs.Document;

/**
 * Handler that computes a boost value based on any number of values
 * in the input Document, then applies that boost value to the Lucene
 * doc.  The boost value is also stored in the Lucene doc for future
 * reference, such as auditing/debugging/tracking.
 */
public class BoostHandler implements FieldHandler
{

  public void handle( org.apache.lucene.document.Document luceneDocument, Document document )
  {
    long numInlinks = getLong( document, "numInlinks", 0 );

    if ( numInlinks > 10 )
      {
        float boost = (float) Math.log10( numInlinks );
        
        // Store the boost value with the document.  This can be handy
        // for debugging/auditing, but it is not searched on, nor does
        // it actually have any operational effect.  It's just so that
        // we can know later what boost value we set on the document.
        // There's no other way to tell.
        luceneDocument.add( new Field( "boost", Float.toString(boost), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS ) );

        luceneDocument.setBoost( boost );
      }
  }

  public long getLong( Document document, String key, long defaultValue )
  {
    long value = defaultValue;
    try
      {
        value = Long.parseLong( document.get( key ) );
      }
    catch ( NumberFormatException nfe )
      {
        // Skip it
      }
    return value;<commit_msg>Fix parameter for Lucene index value to be "do not index".<commit_after>/*
 * Copyright 2011 Internet Archive
 *
 * Licensed 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,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.archive.jbs.lucene;

import java.io.*;
import java.net.*;
import java.util.*;

import org.apache.lucene.document.*;
import org.apache.lucene.index.*;

import org.archive.jbs.Document;

/**
 * Handler that computes a boost value based on any number of values
 * in the input Document, then applies that boost value to the Lucene
 * doc.  The boost value is also stored in the Lucene doc for future
 * reference, such as auditing/debugging/tracking.
 */
public class BoostHandler implements FieldHandler
{

  public void handle( org.apache.lucene.document.Document luceneDocument, Document document )
  {
    long numInlinks = getLong( document, "numInlinks", 0 );

    if ( numInlinks > 10 )
      {
        float boost = (float) Math.log10( numInlinks );
        
        // Store the boost value with the document.  This can be handy
        // for debugging/auditing, but it is not searched on, nor does
        // it actually have any operational effect.  It's just so that
        // we can know later what boost value we set on the document.
        // There's no other way to tell.
        luceneDocument.add( new Field( "boost", Float.toString(boost), Field.Store.YES, Field.Index.NO ) );

        luceneDocument.setBoost( boost );
      }
  }

  public long getLong( Document document, String key, long defaultValue )
  {
    long value = defaultValue;
    try
      {
        value = Long.parseLong( document.get( key ) );
      }
    catch ( NumberFormatException nfe )
      {
        // Skip it
      }
    return value;
{'fraction_non_alphanumeric': 0.08518855065879145, 'fraction_numerical': 0.005906406179009541, 'mean_word_length': 2.882716049382716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7551753', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1174, 'n_words': 501}