本文整理汇总了Java中org.apache.lucene.search.similarities.PerFieldSimilarityWrapper类的典型用法代码示例。如果您正苦于以下问题:Java PerFieldSimilarityWrapper类的具体用法?Java PerFieldSimilarityWrapper怎么用?Java PerFieldSimilarityWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PerFieldSimilarityWrapper类属于org.apache.lucene.search.similarities包,在下文中一共展示了PerFieldSimilarityWrapper类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testReallyNoNormsForDrillDown
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
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);
}
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestTaxonomyFacetCounts.java
示例2: setUp
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
@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);
}
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestSimilarityProvider.java
示例3: testReallyNoNormsForDrillDown
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
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();
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:TestDemoFacets.java
示例4: setUp
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
@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);
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:TestSimilarityProvider.java
示例5: testNonDefaultSimilarity
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
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()));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:HasChildQueryBuilderTests.java
示例6: asTFIDF
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
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;
}
}
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:IDFValueSource.java
示例7: getSimilarity
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
/** 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;
}
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:BaseSimilarityTestCase.java
示例8: getSimilarity
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; //导入依赖的package包/类
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 + ">");
}
}
};
}
开发者ID:lumongo,项目名称:lumongo,代码行数:35,代码来源:LumongoSegment.java
注:本文中的org.apache.lucene.search.similarities.PerFieldSimilarityWrapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论