Guest User

Untitled

a guest
May 16th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package com.umamao.solr;
  2. import java.io.*;
  3. import org.apache.lucene.search.*;
  4.  
  5. /**
  6. * Licensed to the Apache Software Foundation (ASF) under one or more
  7. * contributor license agreements. See the NOTICE file distributed with
  8. * this work for additional information regarding copyright ownership.
  9. * The ASF licenses this file to You under the Apache License, Version 2.0
  10. * (the "License"); you may not use this file except in compliance with
  11. * the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21.  
  22. /** Expert: Default scoring implementation. */
  23. public class ShortFieldNormSimilarity extends DefaultSimilarity {
  24. private static float ARR[] = { 0.0f, 1.5f, 1.25f, 1.0f, 0.875f, 0.75f, 0.625f, 0.5f, 0.4375f, 0.375f, 0.3125f};
  25.  
  26. public ShortFieldNormSimilarity(){
  27. try{
  28. BufferedWriter out = new BufferedWriter(new FileWriter("/tmp/log", true));
  29. out.write("create class\n");
  30. out.close();
  31. }catch(Exception e){
  32. e.printStackTrace();
  33. }
  34. }
  35. /**
  36. * Implemented as a lookup for the first 10 counts, then
  37. * <code>1/sqrt(numTerms)</code>. This is to avoid term counts below
  38. * 11 from having the same lengthNorm after being stored encoded as
  39. * a single byte.
  40. */
  41. public float lengthNorm(String fieldName, int numTerms) {
  42. try{
  43. BufferedWriter out = new BufferedWriter(new FileWriter("/tmp/log", true));
  44. out.write("teste\n");
  45. out.close();
  46. }catch(Exception e){
  47. e.printStackTrace();
  48. }
  49.  
  50. System.out.println("using my similarity");
  51. if( numTerms <= 10 ) {
  52. // this shouldn't be possible, but be safe.
  53. if( numTerms < 0 ) { numTerms = 0; }
  54.  
  55. return ARR[numTerms];
  56. }
  57. //else
  58. return (float)(1.0 / Math.sqrt(numTerms));
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment