本文整理汇总了Java中org.apache.lucene.search.suggest.Lookup.LookupResult方法的典型用法代码示例。如果您正苦于以下问题:Java Lookup.LookupResult方法的具体用法?Java Lookup.LookupResult怎么用?Java Lookup.LookupResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.suggest.Lookup
的用法示例。
在下文中一共展示了Lookup.LookupResult方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookup
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
private static void lookup(AnalyzingInfixSuggester suggester, String keyword,
String region) throws IOException {
HashSet<BytesRef> contexts = new HashSet<BytesRef>();
contexts.add(new BytesRef(region.getBytes("UTF8")));
//先以contexts为过滤条件进行过滤,再以keyword为关键字进行筛选,根据weight值排序返回前2条
//第3个布尔值即是否每个Term都要匹配,第4个参数表示是否需要关键字高亮
List<Lookup.LookupResult> results = suggester.lookup(keyword, 2, true, false);
System.out.println("-- \"" + keyword + "\" (" + region + "):");
for (Lookup.LookupResult result : results) {
System.out.println(result.key);
//从payload中反序列化出Product对象
BytesRef bytesRef = result.payload;
InputStream is = Tools.bytes2InputStream(bytesRef.bytes);
Product product = (Product) Tools.deSerialize(is);
System.out.println("product-Name:" + product.getName());
System.out.println("product-regions:" + product.getRegions());
System.out.println("product-image:" + product.getImage());
System.out.println("product-numberSold:" + product.getNumberSold());
}
System.out.println();
}
示例2: suggest
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
/**
* Provide highlighted suggestion for titles.
*
* @param query The current user input.
* @return A list of highlighted (with HTML mark-ups) titles.
* @throws IOException
*/
public List<String> suggest(String query) throws IOException {
List<Lookup.LookupResult> results = suggester.lookup(query, suggestionCount, false, true);
List<String> suggestions = new ArrayList<String>();
for (Lookup.LookupResult result : results) {
if (result.highlightKey instanceof String) {
suggestions.add((String) result.highlightKey);
} else {
suggestions.add(result.key.toString());
}
}
return suggestions;
}
示例3: suggest
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@NotNull
public List<Lookup.LookupResult> suggest(String qText, int count) throws IOException {
Lookup s = suggester();
if (s == null)
return Collections.EMPTY_LIST;
else
return s.lookup(qText, false, count);
}
示例4: boundedTreeAdd
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
/**
* Add an element to the tree respecting a size limit
*
* @param results the tree to add in
* @param result the result we try to add
* @param num size limit
*/
private static void boundedTreeAdd(TreeSet<Lookup.LookupResult> results, Lookup.LookupResult result, int num) {
if (results.size() >= num) {
if (results.first().value < result.value) {
results.pollFirst();
} else {
return;
}
}
results.add(result);
}
示例5: compare
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@Override
public int compare(Lookup.LookupResult o1, Lookup.LookupResult o2) {
// order on weight
if (o1.value > o2.value) {
return 1;
} else if (o1.value < o2.value) {
return -1;
}
// otherwise on alphabetic order
return CHARSEQUENCE_COMPARATOR.compare(o1.key, o2.key);
}
示例6: BytesRef
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
public void /*testT*/rying() throws IOException {
BytesRef lake = new BytesRef("lake");
BytesRef star = new BytesRef("star");
BytesRef ret = new BytesRef("ret");
Input keys[] = new Input[]{
new Input("top of the lake", 15, lake),
new Input("star wars: episode v - the empire strikes back", 12, star),
new Input("the returned", 10, ret),
};
File tempDir = createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
// if factor is small, we don't get the expected element
BlendedInfixSuggester suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, newFSDirectory(tempDir), a, a,
AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS, BlendedInfixSuggester.BlenderType.POSITION_RECIPROCAL,
BlendedInfixSuggester.DEFAULT_NUM_FACTOR);
suggester.build(new InputArrayIterator(keys));
List<Lookup.LookupResult> responses = suggester.lookup("the", null, 4, true, false);
for (Lookup.LookupResult response : responses) {
System.out.println(response);
}
suggester.close();
}
示例7: getInResults
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
private static long getInResults(BlendedInfixSuggester suggester, String prefix, BytesRef payload, int num) throws IOException {
List<Lookup.LookupResult> responses = suggester.lookup(prefix, null, num, true, false);
for (Lookup.LookupResult response : responses) {
if (response.payload.equals(payload)) {
return response.value;
}
}
return -1;
}
示例8: lookup
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@Override
public List<Lookup.LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num) throws IOException {
// here we multiply the number of searched element by the defined factor
return super.lookup(key, contexts, onlyMorePopular, num * numFactor);
}
示例9: createResults
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@Override
protected List<Lookup.LookupResult> createResults(IndexSearcher searcher, TopFieldDocs hits, int num, CharSequence key,
boolean doHighlight, Set<String> matchedTokens, String prefixToken)
throws IOException {
BinaryDocValues textDV = MultiDocValues.getBinaryValues(searcher.getIndexReader(), TEXT_FIELD_NAME);
assert textDV != null;
// This will just be null if app didn't pass payloads to build():
// TODO: maybe just stored fields? they compress...
BinaryDocValues payloadsDV = MultiDocValues.getBinaryValues(searcher.getIndexReader(), "payloads");
TreeSet<Lookup.LookupResult> results = new TreeSet<>(LOOKUP_COMP);
// we reduce the num to the one initially requested
int actualNum = num / numFactor;
for (int i = 0; i < hits.scoreDocs.length; i++) {
FieldDoc fd = (FieldDoc) hits.scoreDocs[i];
final String text = textDV.get(fd.doc).utf8ToString();
long weight = (Long) fd.fields[0];
BytesRef payload;
if (payloadsDV != null) {
payload = BytesRef.deepCopyOf(payloadsDV.get(fd.doc));
} else {
payload = null;
}
double coefficient;
if (text.startsWith(key.toString())) {
// if hit starts with the key, we don't change the score
coefficient = 1;
} else {
coefficient = createCoefficient(searcher, fd.doc, matchedTokens, prefixToken);
}
long score = (long) (weight * coefficient);
LookupResult result;
if (doHighlight) {
result = new LookupResult(text, highlight(text, matchedTokens, prefixToken), score, payload);
} else {
result = new LookupResult(text, score, payload);
}
boundedTreeAdd(results, result, actualNum);
}
return new ArrayList<>(results.descendingSet());
}
示例10: lookup
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@Override
public List<Lookup.LookupResult> lookup(CharSequence key, boolean onlyMorePopular, int num) {
// here we multiply the number of searched element by the defined factor
return super.lookup(key, onlyMorePopular, num * numFactor);
}
示例11: createResults
import org.apache.lucene.search.suggest.Lookup; //导入方法依赖的package包/类
@Override
protected List<Lookup.LookupResult> createResults(TopDocs hits, int num, CharSequence key,
boolean doHighlight, Set<String> matchedTokens, String prefixToken)
throws IOException {
TreeSet<Lookup.LookupResult> results = new TreeSet<Lookup.LookupResult>(LOOKUP_COMP);
// we reduce the num to the one initially requested
int actualNum = num / numFactor;
BytesRef scratch = new BytesRef();
for (int i = 0; i < hits.scoreDocs.length; i++) {
ScoreDoc sd = hits.scoreDocs[i];
textDV.get(sd.doc, scratch);
String text = scratch.utf8ToString();
long weight = weightsDV.get(sd.doc);
BytesRef payload;
if (payloadsDV != null) {
payload = new BytesRef();
payloadsDV.get(sd.doc, payload);
} else {
payload = null;
}
double coefficient;
if (text.startsWith(key.toString())) {
// if hit starts with the key, we don't change the score
coefficient = 1;
} else {
coefficient = createCoefficient(sd.doc, matchedTokens, prefixToken);
}
long score = (long) (weight * coefficient);
LookupResult result;
if (doHighlight) {
Object highlightKey = highlight(text, matchedTokens, prefixToken);
result = new LookupResult(highlightKey.toString(), highlightKey, score, payload);
} else {
result = new LookupResult(text, score, payload);
}
boundedTreeAdd(results, result, actualNum);
}
return new ArrayList<Lookup.LookupResult>(results.descendingSet());
}