Java 类org.apache.lucene.search.similarities.PerFieldSimilarityWrapper 实例源码

项目:search    文件:TestTaxonomyFacetCounts.java   
public void testReallyNoNormsForDrillDown() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
  iwc.setSimilarity(new PerFieldSimilarityWrapper() {
      final Similarity sim = new DefaultSimilarity();

      @Override
      public Similarity get(String name) {
        assertEquals("field", name);
        return sim;
      }
    });
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
  FacetsConfig config = new FacetsConfig();

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  doc.add(new FacetField("a", "path"));
  writer.addDocument(config.build(taxoWriter, doc));
  IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
项目:search    文件:TestSimilarityProvider.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  directory = newDirectory();
  PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
  IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())).setSimilarity(sim);
  RandomIndexWriter iw = new RandomIndexWriter(random(), directory, iwc);
  Document doc = new Document();
  Field field = newTextField("foo", "", Field.Store.NO);
  doc.add(field);
  Field field2 = newTextField("bar", "", Field.Store.NO);
  doc.add(field2);

  field.setStringValue("quick brown fox");
  field2.setStringValue("quick brown fox");
  iw.addDocument(doc);
  field.setStringValue("jumps over lazy brown dog");
  field2.setStringValue("jumps over lazy brown dog");
  iw.addDocument(doc);
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
  searcher.setSimilarity(sim);
}
项目:NYBC    文件:TestDemoFacets.java   
public void testReallyNoNormsForDrillDown() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  iwc.setSimilarity(new PerFieldSimilarityWrapper() {
      final Similarity sim = new DefaultSimilarity();

      @Override
      public Similarity get(String name) {
        assertEquals("field", name);
        return sim;
      }
    });
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  FacetFields facetFields = new FacetFields(taxoWriter);      

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
  writer.addDocument(doc);
  writer.close();
  taxoWriter.close();
  dir.close();
  taxoDir.close();
}
项目:NYBC    文件:TestSimilarityProvider.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  directory = newDirectory();
  PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
  IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, 
      new MockAnalyzer(random())).setSimilarity(sim);
  RandomIndexWriter iw = new RandomIndexWriter(random(), directory, iwc);
  Document doc = new Document();
  Field field = newTextField("foo", "", Field.Store.NO);
  doc.add(field);
  Field field2 = newTextField("bar", "", Field.Store.NO);
  doc.add(field2);

  field.setStringValue("quick brown fox");
  field2.setStringValue("quick brown fox");
  iw.addDocument(doc);
  field.setStringValue("jumps over lazy brown dog");
  field2.setStringValue("jumps over lazy brown dog");
  iw.addDocument(doc);
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
  searcher.setSimilarity(sim);
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestDemoFacets.java   
public void testReallyNoNormsForDrillDown() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  iwc.setSimilarity(new PerFieldSimilarityWrapper() {
      final Similarity sim = new DefaultSimilarity();

      @Override
      public Similarity get(String name) {
        assertEquals("field", name);
        return sim;
      }
    });
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  FacetFields facetFields = new FacetFields(taxoWriter);      

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
  writer.addDocument(doc);
  writer.close();
  taxoWriter.close();
  dir.close();
  taxoDir.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSimilarityProvider.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  directory = newDirectory();
  PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
  IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, 
      new MockAnalyzer(random())).setSimilarity(sim);
  RandomIndexWriter iw = new RandomIndexWriter(random(), directory, iwc);
  Document doc = new Document();
  Field field = newTextField("foo", "", Field.Store.NO);
  doc.add(field);
  Field field2 = newTextField("bar", "", Field.Store.NO);
  doc.add(field2);

  field.setStringValue("quick brown fox");
  field2.setStringValue("quick brown fox");
  iw.addDocument(doc);
  field.setStringValue("jumps over lazy brown dog");
  field2.setStringValue("jumps over lazy brown dog");
  iw.addDocument(doc);
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
  searcher.setSimilarity(sim);
}
项目:elasticsearch_my    文件:HasChildQueryBuilderTests.java   
public void testNonDefaultSimilarity() throws Exception {
    QueryShardContext shardContext = createShardContext();
    HasChildQueryBuilder hasChildQueryBuilder = QueryBuilders.hasChildQuery(CHILD_TYPE, new TermQueryBuilder("custom_string", "value"), ScoreMode.None);
    HasChildQueryBuilder.LateParsingQuery query = (HasChildQueryBuilder.LateParsingQuery) hasChildQueryBuilder.toQuery(shardContext);
    Similarity expected = SimilarityService.BUILT_IN.get(similarity)
        .apply(similarity, Settings.EMPTY, Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build())
        .get();
    assertThat(((PerFieldSimilarityWrapper) query.getSimilarity()).get("custom_string"), instanceOf(expected.getClass()));
}
项目:search    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}
项目:search    文件:BaseSimilarityTestCase.java   
/** returns the similarity in use for the field */
protected Similarity getSimilarity(String field) {
  SolrCore core = h.getCore();
  RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
  Similarity sim = searcher.get().getSimilarity();
  searcher.decref();
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  return sim;
}
项目:NYBC    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}
项目:NYBC    文件:BaseSimilarityTestCase.java   
/** returns the similarity in use for the field */
protected Similarity getSimilarity(String field) {
  SolrCore core = h.getCore();
  RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
  Similarity sim = searcher.get().getSimilarity();
  searcher.decref();
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  return sim;
}
项目:lumongo    文件:LumongoSegment.java   
private PerFieldSimilarityWrapper getSimilarity(final QueryWithFilters queryWithFilters) {
    return new PerFieldSimilarityWrapper() {
        @Override
        public Similarity get(String name) {

            AnalyzerSettings analyzerSettings = indexConfig.getAnalyzerSettingsForIndexField(name);
            AnalyzerSettings.Similarity similarity = AnalyzerSettings.Similarity.BM25;
            if (analyzerSettings != null) {
                similarity = analyzerSettings.getSimilarity();
            }

            AnalyzerSettings.Similarity fieldSimilarityOverride = queryWithFilters.getFieldSimilarityOverride(name);
            if (fieldSimilarityOverride != null) {
                similarity = fieldSimilarityOverride;
            }

            if (AnalyzerSettings.Similarity.TFIDF.equals(similarity)) {
                return new ClassicSimilarity();
            }
            else if (AnalyzerSettings.Similarity.BM25.equals(similarity)) {
                return new BM25Similarity();
            }
            else if (AnalyzerSettings.Similarity.CONSTANT.equals(similarity)) {
                return new ConstantSimilarity();
            }
            else if (AnalyzerSettings.Similarity.TF.equals(similarity)) {
                return new TFSimilarity();
            }
            else {
                throw new RuntimeException("Unknown similarity type <" + similarity + ">");
            }
        }
    };
}
项目:search-core    文件:BaseSimilarityTestCase.java   
/** returns the similarity in use for the field */
protected Similarity getSimilarity(String field) {
  SolrCore core = h.getCore();
  RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
  Similarity sim = searcher.get().getSimilarity();
  searcher.decref();
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  return sim;
}
项目:read-open-source-code    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}
项目:read-open-source-code    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}
项目:read-open-source-code    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:IDFValueSource.java   
static TFIDFSimilarity asTFIDF(Similarity sim, String field) {
  while (sim instanceof PerFieldSimilarityWrapper) {
    sim = ((PerFieldSimilarityWrapper)sim).get(field);
  }
  if (sim instanceof TFIDFSimilarity) {
    return (TFIDFSimilarity)sim;
  } else {
    return null;
  }
}