本文整理汇总了Java中org.apache.lucene.search.payloads.PayloadTermQuery类的典型用法代码示例。如果您正苦于以下问题:Java PayloadTermQuery类的具体用法?Java PayloadTermQuery怎么用?Java PayloadTermQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PayloadTermQuery类属于org.apache.lucene.search.payloads包,在下文中一共展示了PayloadTermQuery类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
public void search(String queryString) {
try {
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File("D:/data/indices/sandbox")));
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(new MyPayloadSimilarity());
PayloadTermQuery query = new PayloadTermQuery(new Term("concept", queryString),
new AveragePayloadFunction());
System.out.println("Query: " + query.toString());
TopDocs topDocs = searcher.search(query, 999);
ScoreDoc[] hits = topDocs.scoreDocs;
System.out.println("Number of results:" + hits.length);
// output
for (int i = 0; i < hits.length; i++) {
Document doc = searcher.doc(hits[i].doc);
System.out.println("-> docid: " + doc.get("path") + " score: " + hits[i].score);
}
reader.close();
} catch (Exception e) {
System.out.println("Exception while searching: " + e.getMessage());
}
}
示例2: getSpanQuery
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
PayloadTermQuery btq = new PayloadTermQuery(new Term(fieldName, value), new AveragePayloadFunction());
btq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
return btq;
}
示例3: getMathQueries
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
private List<Query> getMathQueries(Map<String, Float> queryForms, MathTokenizer.MathMLType type) {
String field = (type == MathTokenizer.MathMLType.PRESENTATION ? "p" : "c") + "math";
List<Query> result = new ArrayList<>();
Iterator<Map.Entry<String, Float>> it = queryForms.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Float> entry = it.next();
Float boost = entry.getValue();
PayloadTermQuery ptq = new PayloadTermQuery(new Term(field, entry.getKey()), new AveragePayloadFunction());
ptq.setBoost(boost);
result.add(ptq);
}
return result;
}
示例4: addMoves
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
private void addMoves(BooleanQuery query, List<String> moves) {
// Create the moves list, and calculate the actual depth
StringBuilder builder = new StringBuilder().append(MoveTextTokenizer.MOVE_ZERO);
int actualDepth = 0;
for (String move : moves) {
String value = "";
if (move != null) {
value = move.trim();
}
if (value.isEmpty()) {
break;
}
builder.append(MoveText.SEPARATOR);
value = MoveTextTokenizer.filter(value);
value = queryEscape(value);
builder.append(value);
actualDepth++;
}
// Create the query
String result = builder.toString();
Term moveText = new Term(FieldMapper.MOVE_TEXT.toString(), result);
if (actualDepth < analysisDepth) {
query.add(new PayloadTermQuery(moveText, new GameListQueryPayloadFunction()), BooleanClause.Occur.MUST);
} else {
query.add(new PrefixQuery(moveText), BooleanClause.Occur.MUST);
}
}
示例5: matchSequence
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
private void matchSequence(IndexReader reader, String sequence, int docs, int continuations) throws IOException {
ContinuationCollector collector = new ContinuationCollector();
ContinuationSimilarity similarity = new ContinuationSimilarity(collector);
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(similarity);
Query query = new PayloadTermQuery(new Term(FIELD_NAME, sequence), new AveragePayloadFunction());
searcher.search(query, collector);
TopDocs results = collector.getTopDocs();
assertEquals(docs, results.scoreDocs.length);
assertEquals(continuations, collector.getContinuationsCount());
}
示例6: testPayloadTermQuery
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
public void testPayloadTermQuery() throws Throwable {
addDoc("Hurricane warning",
"Bulletin: A hurricane warning was issued at " +
"6 AM for the outer great banks");
addDoc("Warning label maker",
"The warning label maker is a delightful toy for " +
"your precocious seven year old's warning needs");
addDoc("Tornado warning",
"Bulletin: There is a tornado warning for " +
"Worcester county until 6 PM today");
IndexReader r = writer.getReader();
writer.close();
IndexSearcher searcher = new IndexSearcher(r);
searcher.setSimilarity(new BoostingSimilarity());
Term warning = new Term("contents", "warning");
Query query1 = new TermQuery(warning);
LOGGER.info("\nTermQuery results:");
TopDocs hits = searcher.search(query1, 10);
TestUtil.dumpHits(searcher, hits);
assertEquals("Warning label maker", // #B
searcher.doc(hits.scoreDocs[0].doc).get("title")); // #B
Query query2 = new PayloadTermQuery(warning,
new AveragePayloadFunction());
LOGGER.info("\nPayloadTermQuery results:");
hits = searcher.search(query2, 10);
TestUtil.dumpHits(searcher, hits);
assertEquals("Warning label maker", // #C
searcher.doc(hits.scoreDocs[2].doc).get("title")); // #C
r.close();
searcher.close();
}
示例7: search
import org.apache.lucene.search.payloads.PayloadTermQuery; //导入依赖的package包/类
/**
* Searches for documents based on a text query.
* @param queryString The query that is used to search
*/
public List<Result> search(String queryString) {
// for results
List<Result> results = new ArrayList<>();
String conceptIndexfolder = configManager.getProperty("conceptindexer.indexfolder");
try {
// access the index and create a searcher
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(conceptIndexfolder)));
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(new PayloadSimilarity());
// create query
PayloadTermQuery query = new PayloadTermQuery(new Term("concept", queryString),
new AveragePayloadFunction());
logger.info("Query: " + query.toString());
// searching...
TopDocs topDocs = searcher.search(query,999);
ScoreDoc[] hits = topDocs.scoreDocs;
// transform into Results objects
for (int i = 0; i < hits.length; i++) {
// get document from index
Document doc = searcher.doc(hits[i].doc);
// store docIDs (filename) and score
Result result = new Result(doc.get("path"), doc.get("path"), hits[i].score, "NO_USER");
results.add(result);
}
reader.close();
} catch (Exception e) {
logger.error("Exception while searching for '" + queryString + "': " + e.getMessage());
e.printStackTrace();
}
return results;
}