本文整理汇总了Java中org.apache.lucene.search.similarities.TFIDFSimilarity类的典型用法代码示例。如果您正苦于以下问题:Java TFIDFSimilarity类的具体用法?Java TFIDFSimilarity怎么用?Java TFIDFSimilarity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TFIDFSimilarity类属于org.apache.lucene.search.similarities包,在下文中一共展示了TFIDFSimilarity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertScoresMatch
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
private void assertScoresMatch(List<PrebuiltFeature> features, float[] scores,
RankerQuery ltrQuery, ScoreDoc scoreDoc) throws IOException {
Document d = searcherUnderTest.doc(scoreDoc.doc);
String idVal = d.get("id");
int docId = Integer.decode(idVal);
float modelScore = scores[docId];
float queryScore = scoreDoc.score;
assertEquals("Scores match with similarity " + similarity.getClass(), modelScore,
queryScore, SCORE_NB_ULP_PREC *Math.ulp(modelScore));
if (!(similarity instanceof TFIDFSimilarity)) {
// There are precision issues with these similarities when using explain
// It produces 0.56103003 for feat:0 in doc1 using score() but 0.5610301 using explain
Explanation expl = searcherUnderTest.explain(ltrQuery, docId);
assertEquals("Explain scores match with similarity " + similarity.getClass(), expl.getValue(),
queryScore, 5 * Math.ulp(modelScore));
checkFeatureNames(expl, features);
}
}
示例2: getValues
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
IndexSearcher searcher = (IndexSearcher)context.get("searcher");
final TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(), field);
if (similarity == null) {
throw new UnsupportedOperationException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
}
final NumericDocValues norms = readerContext.reader().getNormValues(field);
if (norms == null) {
return new ConstDoubleDocValues(0.0, this);
}
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return similarity.decodeNormValue(norms.get(doc));
}
};
}
示例3: testHyperbolicSweetSpot
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void testHyperbolicSweetSpot() {
SweetSpotSimilarity ss = new SweetSpotSimilarity() {
@Override
public float tf(float freq) {
return hyperbolicTf(freq);
}
};
ss.setHyperbolicTfFactors(3.3f, 7.7f, Math.E, 5.0f);
TFIDFSimilarity s = ss;
for (int i = 1; i <=1000; i++) {
assertTrue("MIN tf: i="+i+" : s="+s.tf(i),
3.3f <= s.tf(i));
assertTrue("MAX tf: i="+i+" : s="+s.tf(i),
s.tf(i) <= 7.7f);
}
assertEquals("MID tf", 3.3f+(7.7f - 3.3f)/2.0f, s.tf(5), 0.00001f);
// stupidity
assertEquals("tf zero", 0.0f, s.tf(0), 0.0f);
}
示例4: getValues
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
IndexSearcher searcher = (IndexSearcher)context.get("searcher");
final TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(), field);
if (similarity == null) {
throw new UnsupportedOperationException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
}
final NumericDocValues norms = readerContext.reader().getNormValues(field);
if (norms == null) {
return new ConstDoubleDocValues(0.0, this);
}
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return similarity.decodeNormValue((byte)norms.get(doc));
}
};
}
示例5: testHyperbolicSweetSpot
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void testHyperbolicSweetSpot() {
SweetSpotSimilarity ss = new SweetSpotSimilarity() {
@Override
public float tf(int freq) {
return hyperbolicTf(freq);
}
};
ss.setHyperbolicTfFactors(3.3f, 7.7f, Math.E, 5.0f);
TFIDFSimilarity s = ss;
for (int i = 1; i <=1000; i++) {
assertTrue("MIN tf: i="+i+" : s="+s.tf(i),
3.3f <= s.tf(i));
assertTrue("MAX tf: i="+i+" : s="+s.tf(i),
s.tf(i) <= 7.7f);
}
assertEquals("MID tf", 3.3f+(7.7f - 3.3f)/2.0f, s.tf(5), 0.00001f);
// stupidity
assertEquals("tf zero", 0.0f, s.tf(0), 0.0f);
}
示例6: getValues
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
IndexSearcher searcher = (IndexSearcher)context.get("searcher");
TFIDFSimilarity sim = asTFIDF(searcher.getSimilarity(), field);
if (sim == null) {
throw new UnsupportedOperationException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
}
int docfreq = searcher.getIndexReader().docFreq(new Term(indexedField, indexedBytes));
float idf = sim.idf(docfreq, searcher.getIndexReader().maxDoc());
return new ConstDoubleDocValues(idf, this);
}
示例7: asTFIDF
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的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;
}
}
示例8: testSimple2
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void testSimple2() throws Exception {
assumeTrue("Broken scoring: LUCENE-3723",
searcher.getSimilarity() instanceof TFIDFSimilarity);
SpanQuery q1 = new SpanTermQuery(new Term("gender", "female"));
SpanQuery q2 = new SpanTermQuery(new Term("last", "smith"));
SpanQuery q = new SpanNearQuery(new SpanQuery[]
{ q1, new FieldMaskingSpanQuery(q2, "gender")}, -1, false );
check(q, new int[] { 2, 4 });
q = new SpanNearQuery(new SpanQuery[]
{ new FieldMaskingSpanQuery(q1, "id"),
new FieldMaskingSpanQuery(q2, "id") }, -1, false );
check(q, new int[] { 2, 4 });
}
示例9: testSpans2
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void testSpans2() throws Exception {
assumeTrue("Broken scoring: LUCENE-3723",
searcher.getSimilarity() instanceof TFIDFSimilarity);
SpanQuery qA1 = new SpanTermQuery(new Term("gender", "female"));
SpanQuery qA2 = new SpanTermQuery(new Term("first", "james"));
SpanQuery qA = new SpanOrQuery(qA1, new FieldMaskingSpanQuery(qA2, "gender"));
SpanQuery qB = new SpanTermQuery(new Term("last", "jones"));
SpanQuery q = new SpanNearQuery(new SpanQuery[]
{ new FieldMaskingSpanQuery(qA, "id"),
new FieldMaskingSpanQuery(qB, "id") }, -1, false );
check(q, new int[] { 0, 1, 2, 3 });
Spans span = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
assertEquals(true, span.next());
assertEquals(s(0,0,1), s(span));
assertEquals(true, span.next());
assertEquals(s(1,1,2), s(span));
assertEquals(true, span.next());
assertEquals(s(2,0,1), s(span));
assertEquals(true, span.next());
assertEquals(s(2,2,3), s(span));
assertEquals(true, span.next());
assertEquals(s(3,0,1), s(span));
assertEquals(false, span.next());
}
示例10: AbstractAuthorityQueryWeight
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public AbstractAuthorityQueryWeight(SolrIndexSearcher searcher, Query query, String authTermName, String authTermText) throws IOException
{
this.searcher = searcher;
this.query = query;
this.similarity = (TFIDFSimilarity) searcher.getSimilarity();
CollectionStatistics collectionStats = searcher.collectionStatistics(authTermName);
final IndexReaderContext context = searcher.getTopReaderContext();
final Term term = new Term(authTermName, authTermText);
final TermContext termContext = TermContext.build(context, term);
TermStatistics termStats = searcher.termStatistics(term, termContext);
idfExp = similarity.idfExplain(collectionStats, termStats);
idf = idfExp.getValue();
}
示例11: setSimilarity
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void setSimilarity(Similarity similarity) {
if (similarity == null || similarity instanceof TFIDFSimilarity) {
//LUCENE 4 UPGRADE we need TFIDF similarity here so I only set it if it is an instance of it
this.similarity = (TFIDFSimilarity) similarity;
}
}
示例12: XMoreLikeThis
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public XMoreLikeThis(IndexReader ir, TFIDFSimilarity sim) {
this.ir = ir;
this.similarity = sim;
}
示例13: getSimilarity
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public TFIDFSimilarity getSimilarity() {
return similarity;
}
示例14: setSimilarity
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public void setSimilarity(TFIDFSimilarity similarity) {
this.similarity = similarity;
}
示例15: RelevancyFeedback
import org.apache.lucene.search.similarities.TFIDFSimilarity; //导入依赖的package包/类
public RelevancyFeedback(IndexReader ir, TFIDFSimilarity sim) {
this.ir = ir;
this.similarity = sim;
}