本文整理汇总了Java中org.apache.solr.search.SolrIndexSearcher类的典型用法代码示例。如果您正苦于以下问题:Java SolrIndexSearcher类的具体用法?Java SolrIndexSearcher怎么用?Java SolrIndexSearcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SolrIndexSearcher类属于org.apache.solr.search包,在下文中一共展示了SolrIndexSearcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newFrom
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/**
* Creates a new {@link SolrQueryRequest} from a given prototype and injects there a set of params.
*
* @param request the prototype {@link SolrQueryRequest}.
* @param params the parameters that will be injected.
* @return a {@link SolrQueryRequest} clone.
*/
public SolrQueryRequest newFrom(final SolrQueryRequest request, final SolrParams params) {
return new SolrQueryRequestBase(
request.getCore(),
new ModifiableSolrParams(params),
new RTimerTree()) {
@Override
public Map<Object, Object> getContext() {
return request.getContext();
}
@Override
public SolrIndexSearcher getSearcher() {
return request.getSearcher();
}
};
}
开发者ID:spaziocodice,项目名称:invisible-queries-request-handler,代码行数:24,代码来源:InvisibleQueriesRequestHandler.java
示例2: LocalEnv
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
public LocalEnv(int offset, int limit, int startTermIndex, int adjust, int targetIdx, int nTerms, Predicate<BytesRef> termFilter,
int mincount, int[] counts, CharsRefBuilder charsRef, boolean extend, SortedSetDocValues si,
SolrIndexSearcher searcher, List<Entry<LeafReader, Bits>> leaves, String fieldName, T ft, NamedList res) {
super(offset, limit, targetIdx, mincount, fieldName, ft, res);
if (startTermIndex == -1) {
// weird case where missing is counted at counts[0].
this.startTermOrd = 0;
this.endTermOrd = nTerms - 1;
} else if (startTermIndex >= 0) {
this.startTermOrd = startTermIndex;
this.endTermOrd = startTermIndex + nTerms;
} else {
throw new IllegalStateException();
}
this.startTermIndex = startTermIndex;
this.adjust = adjust;
this.nTerms = nTerms;
this.termFilter = termFilter;
this.counts = counts;
this.charsRef = charsRef;
this.extend = extend;
this.si = si;
this.searcher = searcher;
this.leaves = leaves;
}
示例3: addToStatistics
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
public static void addToStatistics(SolrIndexSearcher searcher, String field) throws IOException {
// check if this field is already in the stats.
// synchronized (instance) {
if (termstats.get(field)!=null) return;
// }
// else add it to the stats.
Terms terms = searcher.getSlowAtomicReader().terms(field);
HashMap<String, Integer> term2docFreq = new HashMap<String, Integer>(1000);
termstats.put(field, term2docFreq);
if (terms!=null) {
TermsEnum termsEnum = terms.iterator();
BytesRef term;
while ((term = termsEnum.next()) != null) {
term2docFreq.put(term.utf8ToString(), termsEnum.docFreq());
}
}
}
示例4: getStringFields
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
private ArrayList<String> getStringFields( SolrIndexSearcher searcher ) {
IndexSchema schema = searcher.getSchema();
ArrayList<String> strFields = new ArrayList<String>( );
Collection<String> fieldNames = searcher.getFieldNames();
Iterator<String> fnIt = fieldNames.iterator();
while ( fnIt.hasNext() ) {
String fieldName = fnIt.next( );
if (excludeFields == null || !excludeFields.contains( fieldName )) {
SchemaField field = schema.getField(fieldName);
if (field.stored() && field.getType() instanceof StrField ) {
strFields.add( fieldName );
}
}
}
return strFields;
}
示例5: getStringFields
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
private ArrayList<String> getStringFields( SolrIndexSearcher searcher ) {
IndexSchema schema = searcher.getSchema();
ArrayList<String> strFields = new ArrayList<String>( );
Collection<String> fieldNames = searcher.getFieldNames();
Iterator<String> fnIt = fieldNames.iterator();
while ( fnIt.hasNext() ) {
String fieldName = fnIt.next( );
if (excludeFields == null || !excludeFields.contains( fieldName )) {
try {
SchemaField field = schema.getField(fieldName);
if (field.stored() && field.getType() instanceof StrField ) {
strFields.add( fieldName );
}
}
catch (Throwable e )
{
}
}
}
return strFields;
}
示例6: calcLastModified
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/**
* Calculate the appropriate last-modified time for Solr relative the current request.
*
* @return the timestamp to use as a last modified time.
*/
public static long calcLastModified(final SolrQueryRequest solrReq) {
final SolrCore core = solrReq.getCore();
final SolrIndexSearcher searcher = solrReq.getSearcher();
final LastModFrom lastModFrom
= core.getSolrConfig().getHttpCachingConfig().getLastModFrom();
long lastMod;
try {
// assume default, change if needed (getOpenTime() should be fast)
lastMod =
LastModFrom.DIRLASTMOD == lastModFrom
? IndexDeletionPolicyWrapper.getCommitTimestamp(searcher.getIndexReader().getIndexCommit())
: searcher.getOpenTime();
} catch (IOException e) {
// we're pretty freaking screwed if this happens
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
// Get the time where the searcher has been opened
// We get rid of the milliseconds because the HTTP header has only
// second granularity
return lastMod - (lastMod % 1000L);
}
示例7: deleteAll
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/** currently for testing only */
public void deleteAll() {
synchronized (this) {
try {
RefCounted<SolrIndexSearcher> holder = uhandler.core.openNewSearcher(true, true);
holder.decref();
} catch (Exception e) {
SolrException.log(log, "Error opening realtime searcher for deleteByQuery", e);
}
if (map != null) map.clear();
if (prevMap != null) prevMap.clear();
if (prevMap2 != null) prevMap2.clear();
oldDeletes.clear();
deleteByQueries.clear();
}
}
示例8: getVersionFromIndex
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
public Long getVersionFromIndex(BytesRef idBytes) {
// TODO: we could cache much of this and invalidate during a commit.
// TODO: most DocValues classes are threadsafe - expose which.
RefCounted<SolrIndexSearcher> newestSearcher = ulog.uhandler.core.getRealtimeSearcher();
try {
SolrIndexSearcher searcher = newestSearcher.get();
long lookup = searcher.lookupId(idBytes);
if (lookup < 0) return null;
ValueSource vs = versionField.getType().getValueSource(versionField, null);
Map context = ValueSource.newContext(searcher);
vs.createWeight(context, searcher);
FunctionValues fv = vs.getValues(context, searcher.getTopReaderContext().leaves().get((int)(lookup>>32)));
long ver = fv.longVal((int)lookup);
return ver;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading version from index", e);
} finally {
if (newestSearcher != null) {
newestSearcher.decref();
}
}
}
示例9: process
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
ShardResponse srsp = shardRequest.responses.get(0);
SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response");
String uniqueIdFieldName = rb.req.getSchema().getUniqueKeyField().getName();
for (SolrDocument doc : docs) {
Object id = doc.getFieldValue(uniqueIdFieldName).toString();
ShardDoc shardDoc = rb.resultIds.get(id);
FieldDoc fieldDoc = (FieldDoc) shardDoc;
if (shardDoc != null) {
if (returnScores && !Float.isNaN(fieldDoc.score)) {
doc.setField("score", fieldDoc.score);
}
rb.retrievedDocuments.put(id, doc);
}
}
}
示例10: for
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/**
* Generates an NamedList of Explanations for each item in a list of docs.
*
* @param query The Query you want explanations in the context of
* @param docs The Documents you want explained relative that query
*/
public static NamedList<Explanation> getExplanations
(Query query,
DocList docs,
SolrIndexSearcher searcher,
IndexSchema schema) throws IOException {
NamedList<Explanation> explainList = new SimpleOrderedMap<>();
DocIterator iterator = docs.iterator();
for (int i=0; i<docs.size(); i++) {
int id = iterator.nextDoc();
Document doc = searcher.doc(id);
String strid = schema.printableUniqueKey(doc);
explainList.add(strid, searcher.explain(query, id) );
}
return explainList;
}
示例11: create
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String) params.get(FIELD);
String weightField = (String) params.get(WEIGHT_FIELD);
String payloadField = (String) params.get(PAYLOAD_FIELD);
if (field == null) {
throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
}
if (weightField == null) {
throw new IllegalArgumentException(WEIGHT_FIELD + " is a mandatory parameter");
}
return new DocumentDictionary(searcher.getIndexReader(), field, weightField, payloadField);
}
示例12: create
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String)params.get(SolrSpellChecker.FIELD);
if (field == null) {
throw new IllegalArgumentException(SolrSpellChecker.FIELD + " is a mandatory parameter");
}
float threshold = params.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f
: (Float)params.get(THRESHOLD_TOKEN_FREQUENCY);
return new HighFrequencyDictionary(searcher.getIndexReader(), field, threshold);
}
示例13: reload
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
@Override
public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {
LOG.info("reload()");
if (dictionary == null && storeDir != null) {
// this may be a firstSearcher event, try loading it
FileInputStream is = new FileInputStream(new File(storeDir, factory.storeFileName()));
try {
if (lookup.load(is)) {
return; // loaded ok
}
} finally {
IOUtils.closeWhileHandlingException(is);
}
LOG.debug("load failed, need to build Lookup again");
}
// loading was unsuccessful - build it again
build(core, searcher);
}
示例14: getUniqueKeys
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
/** Retrieves the unique keys for the topdocs to key the results */
protected String[] getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs) throws IOException {
IndexSchema schema = searcher.getSchema();
SchemaField keyField = schema.getUniqueKeyField();
if (keyField != null) {
Set<String> selector = Collections.singleton(keyField.getName());
String uniqueKeys[] = new String[docIDs.length];
for (int i = 0; i < docIDs.length; i++) {
int docid = docIDs[i];
Document doc = searcher.doc(docid, selector);
String id = schema.printableUniqueKey(doc);
uniqueKeys[i] = id;
}
return uniqueKeys;
} else {
return new String[docIDs.length];
}
}
示例15: newHolder
import org.apache.solr.search.SolrIndexSearcher; //导入依赖的package包/类
private RefCounted<SolrIndexSearcher> newHolder(SolrIndexSearcher newSearcher, final List<RefCounted<SolrIndexSearcher>> searcherList) {
RefCounted<SolrIndexSearcher> holder = new RefCounted<SolrIndexSearcher>(newSearcher) {
@Override
public void close() {
try {
synchronized(searcherLock) {
// it's possible for someone to get a reference via the _searchers queue
// and increment the refcount while RefCounted.close() is being called.
// we check the refcount again to see if this has happened and abort the close.
// This relies on the RefCounted class allowing close() to be called every
// time the counter hits zero.
if (refcount.get() > 0) return;
searcherList.remove(this);
}
resource.close();
} catch (Exception e) {
// do not allow decref() operations to fail since they are typically called in finally blocks
// and throwing another exception would be very unexpected.
SolrException.log(log, "Error closing searcher:" + this, e);
}
}
};
holder.incref(); // set ref count to 1 to account for this._searcher
return holder;
}