Package org.apache.lucene.search

Examples of org.apache.lucene.search.Similarity


    if (args.length < 3) {
      System.err.println("Usage: FieldNormModifier <index> <package.SimilarityClassName | -n> <field1> [field2] ...");
      System.exit(1);
    }

    Similarity s = null;
    if (!args[1].equals("-n")) {
      try {
        s = Class.forName(args[1]).asSubclass(Similarity.class).newInstance();
      } catch (Exception e) {
        System.err.println("Couldn't instantiate similarity with empty constructor: " + args[1]);
View Full Code Here


  }

  @Test
  public void testSimilarityFactory() {
    SolrCore core = h.getCore();
    Similarity similarity = core.getSchema().getSimilarity();
    assertTrue("wrong class", similarity instanceof MockConfigurableSimilarity);
    assertEquals("is there an echo?", ((MockConfigurableSimilarity)similarity).getPassthrough());
  }
View Full Code Here

            );
  }

  public void testSimilarityFactory() {
    SolrCore core = h.getCore();
    Similarity similarity = core.getSchema().getSimilarity();
    assertTrue("wrong class", similarity instanceof MockConfigurableSimilarity);
    assertEquals("is there an echo?", ((MockConfigurableSimilarity)similarity).getPassthrough());
  }
View Full Code Here

    catch(Exception e){
      log.error(e.getMessage()+", defaulting to "+StandardAnalyzer.class,e);
      analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
    }
   
    Similarity similarity = null;
    try{
      similarity = core.getSchema().getSimilarity();
    }
    catch(Exception e){
      log.error(e.getMessage()+", defaulting to "+DefaultSimilarity.class,e);
View Full Code Here

  public void testAddDocument() throws Exception {
    Document testDoc = new Document();
    DocHelper.setupDoc(testDoc);
    Analyzer analyzer = new WhitespaceAnalyzer();
    Similarity similarity = Similarity.getDefault();
    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    String segName = "test";
    writer.addDocument(segName, testDoc);
    //After adding the document, we should be able to read it back in
    SegmentReader reader = SegmentReader.get(new SegmentInfo(segName, 1, dir));
View Full Code Here

      public int getPositionIncrementGap(String fieldName) {
        return 500;
      }
    };

    Similarity similarity = Similarity.getDefault();
    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    Document doc = new Document();
    doc.add(new Field("repeated", "repeated one", Field.Store.YES, Field.Index.TOKENIZED));
    doc.add(new Field("repeated", "repeated two", Field.Store.YES, Field.Index.TOKENIZED));
View Full Code Here

    if (args.length < 3) {
      System.err.println("Usage: FieldNormModifier <index> <package.SimilarityClassName | -n> <field1> [field2] ...");
      System.exit(1);
    }

    Similarity s = null;
    if (!args[1].equals("-n")) {
      try {
        Class simClass = Class.forName(args[1]);
        s = (Similarity)simClass.newInstance();
      } catch (Exception e) {
View Full Code Here

    } else {
      stream = new JsonStatusBlockReader(file);
    }

    Analyzer analyzer = ANALYZER;
    Similarity similarity = new ConstantNormSimilarity();
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31, analyzer);
    config.setSimilarity(similarity);
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // Overwrite existing.

    IndexWriter writer = new IndexWriter(FSDirectory.open(indexLocation), config);
View Full Code Here

    writer.setMergeFactor(indexConf.getMergeFactor());
    String similarityName = indexConf.getSimilarityName();
    if (similarityName != null) {
      try {
        Class similarityClass = Class.forName(similarityName);
        Similarity similarity = (Similarity) similarityClass.newInstance();
        writer.setSimilarity(similarity);
      } catch (Exception e) {
        throw new IOException("Error in creating a similarty object "
            + similarityName);
      }
View Full Code Here

    writer.setMergeFactor(indexConf.getMergeFactor());
    String similarityName = indexConf.getSimilarityName();
    if (similarityName != null) {
      try {
        Class<?> similarityClass = Class.forName(similarityName);
        Similarity similarity = (Similarity) similarityClass.newInstance();
        writer.setSimilarity(similarity);
      } catch (Exception e) {
        throw new IOException("Error in creating a similarty object "
            + similarityName);
      }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Similarity

Copyright © 2018 www.massapicom. 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.