本文整理汇总了Java中org.apache.lucene.queries.function.FunctionQuery类的典型用法代码示例。如果您正苦于以下问题:Java FunctionQuery类的具体用法?Java FunctionQuery怎么用?Java FunctionQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FunctionQuery类属于org.apache.lucene.queries.function包,在下文中一共展示了FunctionQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: makeQueryFromShape
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
protected Query makeQueryFromShape(Shape shape) {
SpatialArgs args = new SpatialArgs(operation, shape);
if (!Double.isNaN(distErrPct))
args.setDistErrPct(distErrPct);
if (score) {
ValueSource valueSource = strategy.makeDistanceValueSource(shape.getCenter());
return new CustomScoreQuery(strategy.makeQuery(args), new FunctionQuery(valueSource));
} else {
//strategy.makeQuery() could potentially score (isn't well defined) so instead we call
// makeFilter() and wrap
Filter filter = strategy.makeFilter(args);
if (filter instanceof QueryWrapperFilter) {
return ((QueryWrapperFilter)filter).getQuery();
} else {
return new ConstantScoreQuery(filter);
}
}
}
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:SpatialFileQueryMaker.java
示例2: doTestRank
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private void doTestRank (ValueSource valueSource) throws Exception {
FunctionQuery functionQuery = new FunctionQuery(valueSource);
IndexReader r = DirectoryReader.open(dir);
IndexSearcher s = newSearcher(r);
log("test: "+ functionQuery);
QueryUtils.check(random(), functionQuery,s);
ScoreDoc[] h = s.search(functionQuery, null, 1000).scoreDocs;
assertEquals("All docs should be matched!",N_DOCS,h.length);
String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
for (int i=0; i<h.length; i++) {
String resID = s.doc(h[i].doc).get(ID_FIELD);
log(i+". score="+h[i].score+" - "+resID);
log(s.explain(functionQuery,h[i].doc));
assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);
prevID = resID;
}
r.close();
}
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestFieldScoreQuery.java
示例3: doTestExactScore
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private void doTestExactScore (ValueSource valueSource) throws Exception {
FunctionQuery functionQuery = new FunctionQuery(valueSource);
IndexReader r = DirectoryReader.open(dir);
IndexSearcher s = newSearcher(r);
TopDocs td = s.search(functionQuery,null,1000);
assertEquals("All docs should be matched!",N_DOCS,td.totalHits);
ScoreDoc sd[] = td.scoreDocs;
for (ScoreDoc aSd : sd) {
float score = aSd.score;
log(s.explain(functionQuery, aSd.doc));
String id = s.getIndexReader().document(aSd.doc).get(ID_FIELD);
float expectedScore = expectedFieldScore(id); // "ID7" --> 7.0
assertEquals("score of " + id + " shuould be " + expectedScore + " != " + score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);
}
r.close();
}
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestFieldScoreQuery.java
示例4: checkValueSource
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
/** scores[] are in docId order */
protected void checkValueSource(ValueSource vs, float scores[], float delta) throws IOException {
FunctionQuery q = new FunctionQuery(vs);
// //TODO is there any point to this check?
// int expectedDocs[] = new int[scores.length];//fill with ascending 0....length-1
// for (int i = 0; i < expectedDocs.length; i++) {
// expectedDocs[i] = i;
// }
// CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);
//TopDocs is sorted but we actually don't care about the order
TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
for (int i = 0; i < docs.scoreDocs.length; i++) {
ScoreDoc gotSD = docs.scoreDocs[i];
float expectedScore = scores[gotSD.doc];
assertEquals("Not equal for doc "+gotSD.doc, expectedScore, gotSD.score, delta);
}
CheckHits.checkExplanations(q, "", indexSearcher);
}
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:StrategyTestCase.java
示例5: getQueryFromSpatialArgs
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
T strategy = getStrategy(field.getName());
SolrParams localParams = parser.getLocalParams();
String scoreParam = (localParams == null ? null : localParams.get(SCORE_PARAM));
//We get the valueSource for the score then the filter and combine them.
ValueSource valueSource = getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy);
if (valueSource == null) {
//FYI Solr FieldType doesn't have a getFilter(). We'll always grab
// getQuery() but it's possible a strategy has a more efficient getFilter
// that could be wrapped -- no way to know.
//See SOLR-2883 needScore
return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
}
FunctionQuery functionQuery = new FunctionQuery(valueSource);
if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
return functionQuery;
Filter filter = strategy.makeFilter(spatialArgs);
return new FilteredQuery(functionQuery, filter);
}
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:AbstractSpatialFieldType.java
示例6: doTestRank
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private void doTestRank (ValueSource valueSource) throws Exception {
FunctionQuery functionQuery = new FunctionQuery(valueSource);
IndexReader r = DirectoryReader.open(dir);
IndexSearcher s = new IndexSearcher(r);
log("test: "+ functionQuery);
QueryUtils.check(random(), functionQuery,s);
ScoreDoc[] h = s.search(functionQuery, null, 1000).scoreDocs;
assertEquals("All docs should be matched!",N_DOCS,h.length);
String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
for (int i=0; i<h.length; i++) {
String resID = s.doc(h[i].doc).get(ID_FIELD);
log(i+". score="+h[i].score+" - "+resID);
log(s.explain(functionQuery,h[i].doc));
assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);
prevID = resID;
}
r.close();
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:TestFieldScoreQuery.java
示例7: doTestExactScore
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private void doTestExactScore (ValueSource valueSource) throws Exception {
FunctionQuery functionQuery = new FunctionQuery(valueSource);
IndexReader r = DirectoryReader.open(dir);
IndexSearcher s = new IndexSearcher(r);
TopDocs td = s.search(functionQuery,null,1000);
assertEquals("All docs should be matched!",N_DOCS,td.totalHits);
ScoreDoc sd[] = td.scoreDocs;
for (ScoreDoc aSd : sd) {
float score = aSd.score;
log(s.explain(functionQuery, aSd.doc));
String id = s.getIndexReader().document(aSd.doc).get(ID_FIELD);
float expectedScore = expectedFieldScore(id); // "ID7" --> 7.0
assertEquals("score of " + id + " shuould be " + expectedScore + " != " + score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);
}
r.close();
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:TestFieldScoreQuery.java
示例8: checkValueSource
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
/** scores[] are in docId order */
protected void checkValueSource(ValueSource vs, float scores[], float delta) throws IOException {
FunctionQuery q = new FunctionQuery(vs);
// //TODO is there any point to this check?
// int expectedDocs[] = new int[scores.length];//fill with ascending 0....length-1
// for (int i = 0; i < expectedDocs.length; i++) {
// expectedDocs[i] = i;
// }
// CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);
TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
for (int i = 0; i < docs.scoreDocs.length; i++) {
ScoreDoc gotSD = docs.scoreDocs[i];
float expectedScore = scores[gotSD.doc];
assertEquals("Not equal for doc "+gotSD.doc, expectedScore, gotSD.score, delta);
}
CheckHits.checkExplanations(q, "", indexSearcher);
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:StrategyTestCase.java
示例9: CustomScoreQuery
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
/**
* Create a CustomScoreQuery over input subQuery and a {@link org.apache.lucene.queries.function.FunctionQuery}.
* @param subQuery the sub query whose score is being customized. Must not be null.
* @param scoringQueries value source queries whose scores are used in the custom score
* computation. This parameter is optional - it can be null or even an empty array.
*/
public CustomScoreQuery(Query subQuery, FunctionQuery... scoringQueries) {
this.subQuery = subQuery;
this.scoringQueries = scoringQueries !=null?
scoringQueries : new Query[0];
if (subQuery == null) throw new IllegalArgumentException("<subquery> must not be null!");
}
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:CustomScoreQuery.java
示例10: testTopLevelBoost
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public void testTopLevelBoost() throws Exception {
Query q = new TermQuery(new Term(FIELD, "w1"));
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
BooleanQuery bq = new BooleanQuery();
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bq.add(csq, BooleanClause.Occur.MUST);
bq.setBoost(6);
qtest(bq, new int[] { 0,1,2,3 });
}
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:TestCustomScoreExplanations.java
示例11: CollapsingFieldValueCollector
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public CollapsingFieldValueCollector(int maxDoc,
int segments,
SortedDocValues values,
int nullPolicy,
String field,
boolean max,
boolean needsScores,
FieldType fieldType,
IntIntOpenHashMap boostDocs,
FunctionQuery funcQuery, IndexSearcher searcher) throws IOException{
this.maxDoc = maxDoc;
this.contexts = new AtomicReaderContext[segments];
this.values = values;
int valueCount = values.getValueCount();
this.nullPolicy = nullPolicy;
this.needsScores = needsScores;
this.boostDocs = boostDocs;
if(funcQuery != null) {
this.fieldValueCollapse = new ValueSourceCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs, funcQuery, searcher, values);
} else {
if(fieldType instanceof TrieIntField) {
this.fieldValueCollapse = new IntValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs, values);
} else if(fieldType instanceof TrieLongField) {
this.fieldValueCollapse = new LongValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs, values);
} else if(fieldType instanceof TrieFloatField) {
this.fieldValueCollapse = new FloatValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs, values);
} else {
throw new IOException("min/max must be either TrieInt, TrieLong or TrieFloat.");
}
}
}
开发者ID:europeana,项目名称:search,代码行数:33,代码来源:CollapsingQParserPlugin.java
示例12: ValueSourceCollapse
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public ValueSourceCollapse(int maxDoc,
String funcStr,
int nullPolicy,
int[] ords,
boolean max,
boolean needsScores,
IntIntOpenHashMap boostDocs,
FunctionQuery funcQuery, IndexSearcher searcher, SortedDocValues values) throws IOException {
super(maxDoc, null, nullPolicy, max, needsScores, boostDocs, values);
this.valueSource = funcQuery.getValueSource();
this.rcontext = ValueSource.newContext(searcher);
this.ords = ords;
this.ordVals = new float[ords.length];
Arrays.fill(ords, -1);
if(max) {
comp = new MaxFloatComp();
Arrays.fill(ordVals, -Float.MAX_VALUE );
} else {
this.nullVal = Float.MAX_VALUE;
comp = new MinFloatComp();
Arrays.fill(ordVals, Float.MAX_VALUE);
}
if(funcStr.indexOf("cscore()") != -1) {
this.cscore = true;
this.rcontext.put("CSCORE",this.collapseScore);
}
if(this.needsScores) {
this.scores = new float[ords.length];
if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
nullScores = new FloatArrayList();
}
}
}
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:CollapsingQParserPlugin.java
示例13: NameOptScoreQuery
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
NameOptScoreQuery(Query query, FunctionQuery boostQuery) {
super(query, boostQuery);
this.query = query;
synoms.put("option", "opt");
synoms.put("permission", "perm");
synoms.put("crash", "fail");
ontologies.put("tcp", "network");
ontologies.put("encrypt", "ssl");
}
开发者ID:tianyin,项目名称:cox,代码行数:12,代码来源:NameOptScoreQuery.java
示例14: getQueryFromSpatialArgs
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
T strategy = getStrategy(field.getName());
SolrParams localParams = parser.getLocalParams();
String score = (localParams == null ? null : localParams.get(SCORE_PARAM));
if (score == null || "none".equals(score) || "".equals(score)) {
//FYI Solr FieldType doesn't have a getFilter(). We'll always grab
// getQuery() but it's possible a strategy has a more efficient getFilter
// that could be wrapped -- no way to know.
//See SOLR-2883 needScore
return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
}
//We get the valueSource for the score then the filter and combine them.
ValueSource valueSource;
if ("distance".equals(score))
valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter());
else if ("recipDistance".equals(score))
valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape());
else
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");
FunctionQuery functionQuery = new FunctionQuery(valueSource);
if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
return functionQuery;
Filter filter = strategy.makeFilter(spatialArgs);
return new FilteredQuery(functionQuery, filter);
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:AbstractSpatialFieldType.java
示例15: CollapsingFieldValueCollector
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public CollapsingFieldValueCollector(int maxDoc,
int segments,
SortedDocValues values,
int nullPolicy,
String field,
boolean max,
boolean needsScores,
FieldType fieldType,
IntOpenHashSet boostDocs,
FunctionQuery funcQuery, IndexSearcher searcher) throws IOException{
this.maxDoc = maxDoc;
this.contexts = new AtomicReaderContext[segments];
this.values = values;
int valueCount = values.getValueCount();
this.nullPolicy = nullPolicy;
this.needsScores = needsScores;
this.boostDocs = boostDocs;
if(funcQuery != null) {
this.fieldValueCollapse = new ValueSourceCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs, funcQuery, searcher);
} else {
if(fieldType instanceof TrieIntField) {
this.fieldValueCollapse = new IntValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs);
} else if(fieldType instanceof TrieLongField) {
this.fieldValueCollapse = new LongValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs);
} else if(fieldType instanceof TrieFloatField) {
this.fieldValueCollapse = new FloatValueCollapse(maxDoc, field, nullPolicy, new int[valueCount], max, this.needsScores, boostDocs);
} else {
throw new IOException("min/max must be either TrieInt, TrieLong or TrieFloat.");
}
}
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:33,代码来源:CollapsingQParserPlugin.java
示例16: ValueSourceCollapse
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public ValueSourceCollapse(int maxDoc,
String funcStr,
int nullPolicy,
int[] ords,
boolean max,
boolean needsScores,
IntOpenHashSet boostDocs,
FunctionQuery funcQuery, IndexSearcher searcher) throws IOException {
super(maxDoc, null, nullPolicy, max, needsScores, boostDocs);
this.valueSource = funcQuery.getValueSource();
this.rcontext = ValueSource.newContext(searcher);
this.ords = ords;
this.ordVals = new float[ords.length];
Arrays.fill(ords, -1);
if(max) {
comp = new MaxFloatComp();
Arrays.fill(ordVals, -Float.MAX_VALUE );
} else {
this.nullVal = Float.MAX_VALUE;
comp = new MinFloatComp();
Arrays.fill(ordVals, Float.MAX_VALUE);
}
if(funcStr.indexOf("cscore()") != -1) {
this.cscore = true;
this.rcontext.put("CSCORE",this.collapseScore);
}
if(this.needsScores) {
this.scores = new float[ords.length];
if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
nullScores = new FloatArrayList();
}
}
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:37,代码来源:CollapsingQParserPlugin.java
示例17: getQueryFromSpatialArgs
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
T strategy = getStrategy(field.getName());
SolrParams localParams = parser.getLocalParams();
String score = (localParams == null ? null : localParams.get(SCORE_PARAM));
if (score == null || "none".equals(score) || "".equals(score)) {
//FYI Solr FieldType doesn't have a getFilter(). We'll always grab
// getQuery() but it's possible a strategy has a more efficient getFilter
// that could be wrapped -- no way to know.
//See SOLR-2883 needScore
return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
}
//We get the valueSource for the score then the filter and combine them.
ValueSource valueSource;
if ("distance".equals(score)) {
double multiplier = 1.0;//TODO support units=kilometers
valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier);
} else if ("recipDistance".equals(score)) {
valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape());
} else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");
}
FunctionQuery functionQuery = new FunctionQuery(valueSource);
if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
return functionQuery;
Filter filter = strategy.makeFilter(spatialArgs);
return new FilteredQuery(functionQuery, filter);
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:32,代码来源:AbstractSpatialFieldType.java
示例18: main
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Directory dir = new RAMDirectory();
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_4, analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
IndexWriter writer = new IndexWriter(dir, iwc);
addDocument(writer, "doc1", 100);
addDocument(writer, "doc2", 200);
addDocument(writer, "doc3", 300);
addDocument(writer, "doc4", 400);
addDocument(writer, "doc5", 500);
addDocument(writer, "doc6", 600);
writer.close();
IndexReader reader = IndexReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);
Query q =
new FunctionQuery(
new DistanceDualFloatFunction(new IntFieldSource("weight"), new ConstValueSource(245)));
final ScoreDoc[] scoreDocs = searcher.search(q, 10).scoreDocs;
for (ScoreDoc doc : scoreDocs) {
System.out.println(reader.document(doc.doc).getField("title") + " " + doc.score);
}
}
开发者ID:MysterionRise,项目名称:information-retrieval-adventure,代码行数:30,代码来源:ClosestNumberScore.java
示例19: addScoreBoostToQuery
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
private Query addScoreBoostToQuery(Query query) {
return new CustomScoreQuery(query, new FunctionQuery(new LongFieldSource("score")));
}
开发者ID:askplatypus,项目名称:platypus-kb-lucene,代码行数:4,代码来源:LuceneLookup.java
示例20: testOneTerm
import org.apache.lucene.queries.function.FunctionQuery; //导入依赖的package包/类
public void testOneTerm() throws Exception {
Query q = new TermQuery(new Term(FIELD, "w1"));
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
qtest(csq, new int[] { 0,1,2,3 });
}
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:TestCustomScoreExplanations.java
注:本文中的org.apache.lucene.queries.function.FunctionQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论