当前位置: 首页>>代码示例>>Java>>正文


Java SolrIndexSearcher.getSchema方法代码示例

本文整理汇总了Java中org.apache.solr.search.SolrIndexSearcher.getSchema方法的典型用法代码示例。如果您正苦于以下问题:Java SolrIndexSearcher.getSchema方法的具体用法?Java SolrIndexSearcher.getSchema怎么用?Java SolrIndexSearcher.getSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.search.SolrIndexSearcher的用法示例。


在下文中一共展示了SolrIndexSearcher.getSchema方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:19,代码来源:QueryAutoFilteringComponent.java

示例2: 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;
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:25,代码来源:QueryAutoFilteringComponent.java

示例3: process

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
@Override
public void process(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  if (!params.getBool(COMPONENT_NAME, false)) return;
  
  SolrIndexSearcher searcher = rb.req.getSearcher();
  IndexSchema schema = searcher.getSchema();
  if (schema.getUniqueKeyField() == null) return;

  ResultContext rc = (ResultContext) rb.rsp.getValues().get("response");
  
  if (rc.docs.hasScores()) {
    processScores(rb, rc.docs, schema, searcher);
  } else {
    processIds(rb, rc.docs, schema, searcher);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ResponseLogComponent.java

示例4: 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];
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:PostingsSolrHighlighter.java

示例5: doStandardResultsDebug

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public static void doStandardResultsDebug(
        SolrQueryRequest req,
        Query query,
        DocList results,
        boolean dbgResults,
        NamedList dbg) throws IOException
{
  if (dbgResults) {
    SolrIndexSearcher searcher = req.getSearcher();
    IndexSchema schema = searcher.getSchema();
    boolean explainStruct = req.getParams().getBool(CommonParams.EXPLAIN_STRUCT, false);

    if (results != null) {
      NamedList<Explanation> explain = getExplanations(query, results, searcher, schema);
      dbg.add("explain", explainStruct
          ? explanationsToNamedLists(explain)
          : explanationsToStrings(explain));
    }

    String otherQueryS = req.getParams().get(CommonParams.EXPLAIN_OTHER);
    if (otherQueryS != null && otherQueryS.length() > 0) {
      DocList otherResults = doSimpleQuery(otherQueryS, req, 0, 10);
      dbg.add("otherQuery", otherQueryS);
      NamedList<Explanation> explainO = getExplanations(query, otherResults, searcher, schema);
      dbg.add("explainOther", explainStruct
              ? explanationsToNamedLists(explainO)
              : explanationsToStrings(explainO));
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:SolrPluginUtils.java

示例6: getFilterQuery

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
private String getFilterQuery( ResponseBuilder rb, String fieldName, ArrayList<String> valList,
                               int[] termPosRange, ArrayList<char[]> queryTokens, String suffix) {
  if (fieldName.indexOf( fieldDelim ) > 0) {
    return getFilterQuery( rb, fieldName.split( fieldSplitExpr ), valList, termPosRange, queryTokens, suffix );
  }
  if (valList.size() == 1) {
    // check if valList[0] is multi-term - if so, check if there is a single term equivalent
    // if this returns non-null, create an OR query with single term version
    // example "white linen perfume" vs "white linen shirt"  where "White Linen" is a brand
    String term = valList.get( 0 );
      
    if (term.indexOf( " " ) > 0) {
      String singleTermQuery = getSingleTermQuery( term );
      if (singleTermQuery != null) {
        StringBuilder strb = new StringBuilder( );
        // EH: possible meta-escaping problem if value includes {!field f=<fieldName>}value
        strb.append( "(" ).append( fieldName ).append( ":" )
            .append( term ).append( " OR (" ).append( singleTermQuery ).append( "))" ).append( suffix );
        Log.debug( "returning composite query: " + strb.toString( ) );
        return strb.toString( );
      }
    }
      
    String query = fieldName + ":" + term + suffix;
    Log.debug( "returning single query: " + query );
    return query;
  }
  else {
    SolrIndexSearcher searcher = rb.req.getSearcher();
    IndexSchema schema = searcher.getSchema();
    SchemaField field = schema.getField(fieldName);
    boolean useAnd = field.multiValued() && useAndForMultiValuedFields;
    // if query has 'or' in it and or is at a position 'within' the values for this field ...
    if (useAnd) {
      for (int i = termPosRange[0] + 1; i < termPosRange[1]; i++ ) {
        char[] qToken = queryTokens.get( i );
        // is the token 'or'?
        if (qToken.length == 2 && qToken[0] == 'o' && qToken[1] == 'r' ) {
          useAnd = false;
          break;
        }
      }
    }
      
    StringBuilder orQ = new StringBuilder( );
    for (String val : valList ) {
      if (orQ.length() > 0) orQ.append( (useAnd ? " AND " : " OR ") );
      orQ.append( val );
    }
    return fieldName + ":(" + orQ.toString() + ")" + suffix;
  }
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:53,代码来源:QueryAutoFilteringComponent.java

示例7: getFilterQuery

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
private String getFilterQuery( ResponseBuilder rb, String fieldName, ArrayList<String> valList,
                               int[] termPosRange, ArrayList<char[]> queryTokens, String suffix) {
    
  if (fieldName.indexOf( fieldDelim ) > 0) {
    return getFilterQuery( rb, fieldName.split( fieldSplitExpr ), valList, termPosRange, queryTokens, suffix );
  }
  if (valList.size() == 1) {
    // check if valList[0] is multi-term - if so, check if there is a single term equivalent
    // if this returns non-null, create an OR query with single term version
    // example "white linen perfume" vs "white linen shirt"  where "White Linen" is a brand
    String term = valList.get( 0 );

    if (term.indexOf( " " ) > 0) {
      String singleTermQuery = getSingleTermQuery( term );
      if (singleTermQuery != null) {
        StringBuilder strb = new StringBuilder( );
        strb.append( "(" ).append( fieldName ).append( ":" )
            .append( term ).append( " OR (" ).append( singleTermQuery ).append( "))" ).append( suffix );
        Log.debug( "returning composite query: " + strb.toString( ) );
        return strb.toString( );
      }
    }

    String query = fieldName + ":" + term + suffix;
    Log.debug( "returning single query: " + query );
    return query;
  }
  else {
    // Check if it is a MultiValued Field - if so, use AND internally
    SolrIndexSearcher searcher = rb.req.getSearcher();
    IndexSchema schema = searcher.getSchema();
    SchemaField field = schema.getField(fieldName);
      
    boolean useAnd = field.multiValued() && useAndForMultiValuedFields;
    // if query has 'or' in it and or is at a position 'within' the values for this field ...
    if (useAnd) {
      for (int i = termPosRange[0] + 1; i < termPosRange[1]; i++ ) {
        char[] qToken = queryTokens.get( i );
        if (qToken.length == 2 && qToken[0] == 'o' && qToken[1] == 'r' ) {
          useAnd = false;
          break;
        }
      }
    }
      
    StringBuilder orQ = new StringBuilder( );
    for (String val : valList ) {
      if (orQ.length() > 0) orQ.append( (useAnd ? " AND " : " OR ") );
      orQ.append( val );
    }
      
    String fq = fieldName + ":(" + orQ.toString() + ")" + suffix;
    Log.debug( "fq = " + fq );
    return fq;
  }
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:57,代码来源:QueryAutoFilteringComponent.java

示例8: getFieldWriters

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
protected FieldWriter[] getFieldWriters(String[] fields, SolrIndexSearcher searcher) throws IOException {
  IndexSchema schema = searcher.getSchema();
  FieldWriter[] writers = new FieldWriter[fields.length];
  for(int i=0; i<fields.length; i++) {
    String field = fields[i];
    SchemaField schemaField = schema.getField(field);

    if(!schemaField.hasDocValues()) {
      throw new IOException(field+" must have DocValues to use this feature.");
    }

    boolean multiValued = schemaField.multiValued();
    FieldType fieldType = schemaField.getType();
    if(fieldType instanceof TrieIntField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new IntFieldWriter(field);
      }
    } else if (fieldType instanceof TrieLongField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new LongFieldWriter(field);
      }
    } else if (fieldType instanceof TrieFloatField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new FloatFieldWriter(field);
      }
    } else if(fieldType instanceof TrieDoubleField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new DoubleFieldWriter(field);
      }
    } else if(fieldType instanceof StrField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, false);
      } else {
        writers[i] = new StringFieldWriter(field, fieldType);
      }
    } else {
      throw new IOException("Export fields must either be one of the following types: int,float,long,double,string");
    }
  }
  return writers;
}
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:SortingResponseWriter.java

示例9: getSortDoc

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
private SortDoc getSortDoc(SolrIndexSearcher searcher, SortField[] sortFields) throws IOException {
  SortValue[] sortValues = new SortValue[sortFields.length];
  IndexSchema schema = searcher.getSchema();
  for(int i=0; i<sortFields.length; ++i) {
    SortField sf = sortFields[i];
    String field = sf.getField();
    boolean reverse = sf.getReverse();
    SchemaField schemaField = schema.getField(field);
    FieldType ft = schemaField.getType();

    if(!schemaField.hasDocValues()) {
      throw new IOException(field+" must have DocValues to use this feature.");
    }

    if(ft instanceof TrieIntField) {
      if(reverse) {
        sortValues[i] = new IntValue(field, new IntDesc());
      } else {
        sortValues[i] = new IntValue(field, new IntAsc());
      }
    } else if(ft instanceof TrieFloatField) {
      if(reverse) {
        sortValues[i] = new FloatValue(field, new FloatDesc());
      } else {
        sortValues[i] = new FloatValue(field, new FloatAsc());
      }
    } else if(ft instanceof TrieDoubleField) {
      if(reverse) {
        sortValues[i] = new DoubleValue(field, new DoubleDesc());
      } else {
        sortValues[i] = new DoubleValue(field, new DoubleAsc());
      }
    } else if(ft instanceof TrieLongField) {
      if(reverse) {
        sortValues[i] = new LongValue(field, new LongDesc());
      } else {
        sortValues[i] = new LongValue(field, new LongAsc());
      }
    } else if(ft instanceof StrField) {
      AtomicReader reader = searcher.getAtomicReader();
      SortedDocValues vals =  reader.getSortedDocValues(field);
      if(reverse) {
        sortValues[i] = new StringValue(vals, field, new IntDesc());
      } else {
        sortValues[i] = new StringValue(vals, field, new IntAsc());
      }
    } else {
      throw new IOException("Sort fields must be one of the following types: int,float,long,double,string");
    }
  }

  if(sortValues.length == 1) {
    return new SingleValueSortDoc(sortValues[0]);
  } else if(sortValues.length == 2) {
    return new DoubleValueSortDoc(sortValues[0], sortValues[1]);
  } else if(sortValues.length == 3) {
    return new TripleValueSortDoc(sortValues[0], sortValues[1], sortValues[2]);
  } else if(sortValues.length == 4) {
    return new QuadValueSortDoc(sortValues[0], sortValues[1], sortValues[2], sortValues[3]);
  } else {
    throw new IOException("A max of 4 sorts can be specified");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:SortingResponseWriter.java

示例10: getIndexedFieldsInfo

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
private static SimpleOrderedMap<Object> getIndexedFieldsInfo(SolrQueryRequest req)
    throws Exception {

  SolrIndexSearcher searcher = req.getSearcher();
  SolrParams params = req.getParams();

  Set<String> fields = null;
  String fl = params.get(CommonParams.FL);
  if (fl != null) {
    fields = new TreeSet<>(Arrays.asList(fl.split( "[,\\s]+" )));
  }

  AtomicReader reader = searcher.getAtomicReader();
  IndexSchema schema = searcher.getSchema();

  // Don't be tempted to put this in the loop below, the whole point here is to alphabetize the fields!
  Set<String> fieldNames = new TreeSet<>();
  for(FieldInfo fieldInfo : reader.getFieldInfos()) {
    fieldNames.add(fieldInfo.name);
  }

  // Walk the term enum and keep a priority queue for each map in our set
  SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();

  for (String fieldName : fieldNames) {
    if (fields != null && ! fields.contains(fieldName) && ! fields.contains("*")) {
      continue; //we're not interested in this field Still an issue here
    }

    SimpleOrderedMap<Object> fieldMap = new SimpleOrderedMap<>();

    SchemaField sfield = schema.getFieldOrNull( fieldName );
    FieldType ftype = (sfield==null)?null:sfield.getType();

    fieldMap.add( "type", (ftype==null)?null:ftype.getTypeName() );
    fieldMap.add("schema", getFieldFlags(sfield));
    if (sfield != null && schema.isDynamicField(sfield.getName()) && schema.getDynamicPattern(sfield.getName()) != null) {
      fieldMap.add("dynamicBase", schema.getDynamicPattern(sfield.getName()));
    }
    Terms terms = reader.fields().terms(fieldName);
    if (terms == null) { // Not indexed, so we need to report what we can (it made it through the fl param if specified)
      finfo.add( fieldName, fieldMap );
      continue;
    }

    if(sfield != null && sfield.indexed() ) {
      // In the pre-4.0 days, this did a veeeery expensive range query. But we can be much faster now,
      // so just do this all the time.
      Document doc = getFirstLiveDoc(terms, reader);


      if( doc != null ) {
        // Found a document with this field
        try {
          IndexableField fld = doc.getField( fieldName );
          if( fld != null ) {
            fieldMap.add("index", getFieldFlags(fld));
          }
          else {
            // it is a non-stored field...
            fieldMap.add("index", "(unstored field)");
          }
        }
        catch( Exception ex ) {
          log.warn( "error reading field: "+fieldName );
        }
      }
      fieldMap.add("docs", terms.getDocCount());

    }
    if (fields != null && (fields.contains(fieldName) || fields.contains("*"))) {
      getDetailedFieldInfo(req, fieldName, fieldMap);
    }
    // Add the field
    finfo.add( fieldName, fieldMap );
  }
  return finfo;
}
 
开发者ID:europeana,项目名称:search,代码行数:79,代码来源:LukeRequestHandler.java

示例11: getMoreLikeThese

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
NamedList<DocList> getMoreLikeThese(ResponseBuilder rb,
    SolrIndexSearcher searcher, DocList docs, int flags) throws IOException {
  SolrParams p = rb.req.getParams();
  IndexSchema schema = searcher.getSchema();
  MoreLikeThisHandler.MoreLikeThisHelper mltHelper = new MoreLikeThisHandler.MoreLikeThisHelper(
      p, searcher);
  NamedList<DocList> mlt = new SimpleOrderedMap<>();
  DocIterator iterator = docs.iterator();
  
  SimpleOrderedMap<Object> dbg = null;
  if (rb.isDebug()) {
    dbg = new SimpleOrderedMap<>();
  }
  
  while (iterator.hasNext()) {
    int id = iterator.nextDoc();
    int rows = p.getInt(MoreLikeThisParams.DOC_COUNT, 5);
    DocListAndSet sim = mltHelper.getMoreLikeThis(id, 0, rows, null, null,
        flags);
    String name = schema.printableUniqueKey(searcher.doc(id));
    mlt.add(name, sim.docList);
    
    if (dbg != null) {
      SimpleOrderedMap<Object> docDbg = new SimpleOrderedMap<>();
      docDbg.add("rawMLTQuery", mltHelper.getRawMLTQuery().toString());
      docDbg
          .add("boostedMLTQuery", mltHelper.getBoostedMLTQuery().toString());
      docDbg.add("realMLTQuery", mltHelper.getRealMLTQuery().toString());
      SimpleOrderedMap<Object> explains = new SimpleOrderedMap<>();
      DocIterator mltIte = sim.docList.iterator();
      while (mltIte.hasNext()) {
        int mltid = mltIte.nextDoc();
        String key = schema.printableUniqueKey(searcher.doc(mltid));
        explains.add(key,
            searcher.explain(mltHelper.getRealMLTQuery(), mltid));
      }
      docDbg.add("explain", explains);
      dbg.add(name, docDbg);
    }
  }
  
  // add debug information
  if (dbg != null) {
    rb.addDebugInfo("moreLikeThis", dbg);
  }
  return mlt;
}
 
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:MoreLikeThisComponent.java

示例12: doHighlighting

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
/**
 * Generates a list of Highlighted query fragments for each item in a list
 * of documents, or returns null if highlighting is disabled.
 *
 * @param docs query results
 * @param query the query
 * @param req the current request
 * @param defaultFields default list of fields to summarize
 *
 * @return NamedList containing a NamedList for each document, which in 
 * turns contains sets (field, summary) pairs.
 */
@Override
@SuppressWarnings("unchecked")
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
  SolrParams params = req.getParams(); 
  if (!isHighlightingEnabled(params))
      return null;
   
  SolrIndexSearcher searcher = req.getSearcher();
  IndexSchema schema = searcher.getSchema();
  NamedList fragments = new SimpleOrderedMap();
  String[] fieldNames = getHighlightFields(query, req, defaultFields);
  Set<String> fset = new HashSet<>();
   
  {
    // pre-fetch documents using the Searcher's doc cache
    for(String f : fieldNames) { fset.add(f); }
    // fetch unique key if one exists.
    SchemaField keyField = schema.getUniqueKeyField();
    if(null != keyField)
      fset.add(keyField.getName());  
  }

  // get FastVectorHighlighter instance out of the processing loop
  FastVectorHighlighter fvh = new FastVectorHighlighter(
      // FVH cannot process hl.usePhraseHighlighter parameter per-field basis
      params.getBool( HighlightParams.USE_PHRASE_HIGHLIGHTER, true ),
      // FVH cannot process hl.requireFieldMatch parameter per-field basis
      params.getBool( HighlightParams.FIELD_MATCH, false ) );
  fvh.setPhraseLimit(params.getInt(HighlightParams.PHRASE_LIMIT, SolrHighlighter.DEFAULT_PHRASE_LIMIT));
  FieldQuery fieldQuery = fvh.getFieldQuery( query, searcher.getIndexReader() );

  // Highlight each document
  DocIterator iterator = docs.iterator();
  for (int i = 0; i < docs.size(); i++) {
    int docId = iterator.nextDoc();
    Document doc = searcher.doc(docId, fset);
    NamedList docSummaries = new SimpleOrderedMap();
    for (String fieldName : fieldNames) {
      fieldName = fieldName.trim();
      if( useFastVectorHighlighter( params, schema, fieldName ) )
        doHighlightingByFastVectorHighlighter( fvh, fieldQuery, req, docSummaries, docId, doc, fieldName );
      else
        doHighlightingByHighlighter( query, req, docSummaries, docId, doc, fieldName );
    }
    String printId = schema.printableUniqueKey(doc);
    fragments.add(printId == null ? null : printId, docSummaries);
  }
  return fragments;
}
 
开发者ID:europeana,项目名称:search,代码行数:62,代码来源:DefaultSolrHighlighter.java


注:本文中的org.apache.solr.search.SolrIndexSearcher.getSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。