org.apache.lucene.search.DocValuesFieldExistsQuery#org.apache.solr.schema.IndexSchema源码实例Demo

下面列出了org.apache.lucene.search.DocValuesFieldExistsQuery#org.apache.solr.schema.IndexSchema 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jate   文件: TermRecognitionRequestHandler.java
private void iterateAddDomainTermFields(boolean isBoosted, String domainTermsFieldName,
                                        IndexSchema indexSchema, Document doc,
                                        List<Pair<String, Double>> filteredCandidateTerms) {
    // remove previous fields if exists
    doc.removeFields(domainTermsFieldName);

    for (Pair<String, Double> filteredTerm : filteredCandidateTerms) {
        if (filteredTerm == null) {
            continue;
        }

        if (isBoosted) {
            doc.add(indexSchema.getField(domainTermsFieldName).createField(filteredTerm.first()
                    ));
        } else {
            doc.add(indexSchema.getField(domainTermsFieldName).createField(filteredTerm.first()
                    ));
        }
    }
}
 
public void testFailedParseMixedLong() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNull(schema.getFieldOrNull("not_in_schema"));
  Map<Object,Object> mixed = new HashMap<>();
  Float floatVal = 294423.0f;
  mixed.put(85L, "85");
  mixed.put(floatVal, floatVal); // Float-typed field value
  mixed.put(-2894518L, "-2,894,518");
  mixed.put(1879472193L, "1,879,472,193");
  SolrInputDocument d = processAdd("parse-long-no-run-processor",
                                   doc(f("id", "7204"), f("not_in_schema", mixed.values())));
  assertNotNull(d);
  boolean foundFloat = false;
  for (Object o : d.getFieldValues("not_in_schema")) {
    if (floatVal == o) {
      foundFloat = true;
    } else {
      assertThat(o, IS_STRING);
    }
    mixed.values().remove(o);
  }
  assertTrue(foundFloat);
  assertTrue(mixed.isEmpty());
}
 
源代码3 项目: lucene-solr   文件: CursorMarkTest.java
public void testNextCursorMark() throws IOException {
  final Collection<String> allFieldNames = getAllFieldNames();
  final SolrQueryRequest req = req();
  final IndexSchema schema = req.getSchema();

  final String randomSortString = CursorPagingTest.buildRandomSort(allFieldNames);
  final SortSpec ss = SortSpecParsing.parseSortSpec(randomSortString, req);

  final CursorMark previous = new CursorMark(schema, ss);
  previous.parseSerializedTotem(CURSOR_MARK_START);

  List<Object> nextValues = Arrays.<Object>asList(buildRandomSortObjects(ss));
  final CursorMark next = previous.createNext(nextValues);
  assertEquals("next values not correct", nextValues, next.getSortValues());
  assertEquals("next SortSpec not correct", ss, next.getSortSpec());

  try {
    // append to our random sort string so we know it has wrong num clauses
    final SortSpec otherSort = SortSpecParsing.parseSortSpec(randomSortString+",id asc", req);
    CursorMark trash = previous.createNext(Arrays.<Object>asList
                                           (buildRandomSortObjects(otherSort)));
    fail("didn't fail on next with incorrect num of sortvalues");
  } catch (AssertionError e) {
    // NOOP: we're happy
  }
}
 
public void testParseFloatNonRootLocale() throws Exception {
  final DecimalFormatSymbols fr_FR = DecimalFormatSymbols.getInstance(new Locale("fr","FR"));
  final char groupChar = fr_FR.getGroupingSeparator();
  final char decimalChar = fr_FR.getDecimalSeparator();

  float value = 10898.83491F;
  String floatString1 = "10898"+decimalChar+"83491";
  String floatString2 = "10"+groupChar+"898"+decimalChar+"83491";
  
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("float_f")); // should match dynamic field "*_f"
  assertNull(schema.getFieldOrNull("not_in_schema"));
  SolrInputDocument d = processAdd("parse-float-french-no-run-processor",
      doc(f("id", "140"), f("float_f", floatString1),
          f("not_in_schema", floatString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("float_f"), IS_FLOAT);
  assertEquals(value, (Float)d.getFieldValue("float_f"), EPSILON);
  assertThat(d.getFieldValue("not_in_schema"), IS_FLOAT);
  assertEquals(value, (Float)d.getFieldValue("not_in_schema"), EPSILON);
}
 
public void testCanCreateTombstonesRequiredFieldInTombstoneConfig() {
  DocBasedVersionConstraintsProcessorFactory factory = new DocBasedVersionConstraintsProcessorFactory();
  NamedList<Object> config = new NamedList<>();
  config.add("versionField", "_version_");
  NamedList<Object> tombstoneConfig = new NamedList<>();
  config.add("tombstoneConfig", tombstoneConfig);
  tombstoneConfig.add("sku1", "foo");
  factory.init(config);
  IndexSchema schema = h.getCore().getLatestSchema();
  SchemaField sf = schema.getField("sku1");
  assertThat(sf, is(not(nullValue())));
  assertThat(schema.getRequiredFields(), not(hasItem(sf)));
  try {
    schema.getRequiredFields().add(sf);
    assertThat(factory.canCreateTombstoneDocument(schema), is(true));
  } finally {
    schema.getRequiredFields().remove(sf);
  }
}
 
源代码6 项目: lucene-solr   文件: HashQParserPlugin.java
public DelegatingCollector getFilterCollector(IndexSearcher indexSearcher) {
  HashKey[] hashKeys = new HashKey[keys.length];
  SolrIndexSearcher searcher = (SolrIndexSearcher)indexSearcher;
  IndexSchema schema = searcher.getSchema();
  for(int i=0; i<keys.length; i++) {
    String key = keys[i];
    FieldType ft = schema.getField(key).getType();
    HashKey h = null;
    if(ft instanceof StrField) {
      h = new BytesHash(key, ft);
    } else {
      h = new NumericHash(key);
    }
    hashKeys[i] = h;
  }
  HashKey k = (hashKeys.length > 1) ? new CompositeHash(hashKeys) : hashKeys[0];
  return new HashCollector(k, workers, worker);
}
 
源代码7 项目: lucene-solr   文件: SolrCore.java
private void checkVersionFieldExistsInSchema(IndexSchema schema, CoreDescriptor coreDescriptor) {
  if (null != coreDescriptor.getCloudDescriptor()) {
    // we are evidently running in cloud mode.  
    //
    // In cloud mode, version field is required for correct consistency
    // ideally this check would be more fine grained, and individual features
    // would assert it when they initialize, but DistributedUpdateProcessor
    // is currently a big ball of wax that does more then just distributing
    // updates (ie: partial document updates), so it needs to work in no cloud
    // mode as well, and can't assert version field support on init.

    try {
      VersionInfo.getAndCheckVersionField(schema);
    } catch (SolrException e) {
      throw new SolrException(ErrorCode.SERVER_ERROR,
          "Schema will not work with SolrCloud mode: " +
              e.getMessage(), e);
    }
  }
}
 
public void testMixedFloats() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("float_tf")); // should match dynamic field "*_tf"
  Map<Float,Object> mixedFloats = new HashMap<>();
  mixedFloats.put(85.0f, "85");
  mixedFloats.put(2894518.0f, "2,894,518");
  mixedFloats.put(2.94423E-9f, 2.94423E-9f); // Float-typed field value
  mixedFloats.put(48794721.937f, "48,794,721.937");
  SolrInputDocument d = processAdd("parse-float-no-run-processor", 
                                   doc(f("id", "342"), f("float_tf", mixedFloats.values())));
  assertNotNull(d);
  for (Object o : d.getFieldValues("float_tf")) {
    assertThat(o, IS_FLOAT);
    mixedFloats.remove(o);
  }
  assertTrue(mixedFloats.isEmpty());
}
 
public void testParseLongNonRootLocale() throws Exception {
  final DecimalFormatSymbols ru_RU = DecimalFormatSymbols.getInstance(new Locale("ru","RU"));
  final char groupChar = ru_RU.getGroupingSeparator();
  
  long value = 1089883491L;
  String longString1 = "1089883491";
  String longString2 = "1"+groupChar+"089"+groupChar+"883"+groupChar+"491";
  
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("long_l")); // should match dynamic field "*_l"
  assertNull(schema.getFieldOrNull("not_in_schema"));
  SolrInputDocument d = processAdd("parse-long-russian-no-run-processor",
                                   doc(f("id", "113"), f("long_l", longString1), f("not_in_schema", longString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("long_l"), IS_LONG);
  assertEquals(value, ((Long)d.getFieldValue("long_l")).longValue());
  assertThat(d.getFieldValue("not_in_schema"), IS_LONG);
  assertEquals(value, ((Long)d.getFieldValue("not_in_schema")).longValue());
}
 
public void testParseBooleanRoundTrip() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("boolean1_b")); // should match dynamic field "*_b"
  assertNotNull(schema.getFieldOrNull("boolean2_b")); // should match dynamic field "*_b"
  boolean value1 = true;
  boolean value2 = false;
  SolrInputDocument d = processAdd("parse-boolean",
      doc(f("id", "141"), f("boolean1_b", value1), f("boolean2_b", value2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("boolean1_b"), IS_BOOLEAN);
  assertEquals(value1, d.getFieldValue("boolean1_b"));
  assertThat(d.getFieldValue("boolean2_b"), IS_BOOLEAN);
  assertEquals(value2, d.getFieldValue("boolean2_b"));

  assertU(commit());
  assertQ(req("id:141")
      ,"//bool[@name='boolean1_b'][.='" + value1 + "']"
      ,"//bool[@name='boolean2_b'][.='" + value2 + "']");
}
 
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;
}
 
源代码12 项目: lucene-solr   文件: PeerSyncTest.java
public PeerSyncTest() {
  stress = 0;

  // TODO: a better way to do this?
  configString = "solrconfig-tlog.xml";
  schemaString = "schema.xml";

  // validate that the schema was not changed to an unexpected state
  try {
    initCore(configString, schemaString);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  IndexSchema schema = h.getCore().getLatestSchema();
  assertTrue(schema.getFieldOrNull("_version_").hasDocValues() && !schema.getFieldOrNull("_version_").indexed()
      && !schema.getFieldOrNull("_version_").stored());
  assertTrue(!schema.getFieldOrNull("val_i_dvo").indexed() && !schema.getFieldOrNull("val_i_dvo").stored() &&
      schema.getFieldOrNull("val_i_dvo").hasDocValues());
}
 
源代码13 项目: lucene-solr   文件: SolrPluginUtils.java
/**
 * 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;
}
 
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;
}
 
源代码15 项目: lucene-solr   文件: RealTimeGetComponent.java
private static SolrInputDocument toSolrInputDocument(Document doc, IndexSchema schema) {
  SolrInputDocument out = new SolrInputDocument();
  for( IndexableField f : doc.getFields() ) {
    String fname = f.name();
    SchemaField sf = schema.getFieldOrNull(f.name());
    Object val = null;
    if (sf != null) {
      if ((!sf.hasDocValues() && !sf.stored()) || schema.isCopyFieldTarget(sf)) continue;
      val = sf.getType().toObject(f);   // object or external string?
    } else {
      val = f.stringValue();
      if (val == null) val = f.numericValue();
      if (val == null) val = f.binaryValue();
      if (val == null) val = f;
    }

    // todo: how to handle targets of copy fields (including polyfield sub-fields)?
    out.addField(fname, val);
  }
  return out;
}
 
源代码16 项目: lucene-solr   文件: LukeRequestHandler.java
/**
 * This is a destructive call... the queue is empty at the end
 */
public NamedList<Integer> toNamedList( IndexSchema schema )
{
  // reverse the list..
  List<TermInfo> aslist = new LinkedList<>();
  while( size() > 0 ) {
    aslist.add( 0, (TermInfo)pop() );
  }

  NamedList<Integer> list = new NamedList<>();
  for (TermInfo i : aslist) {
    String txt = i.term.text();
    SchemaField ft = schema.getFieldOrNull( i.term.field() );
    if( ft != null ) {
      txt = ft.getType().indexedToReadable( txt );
    }
    list.add( txt, i.docFreq );
  }
  return list;
}
 
源代码17 项目: mtas   文件: MtasSolrComponentFacet.java
/**
 * Gets the field type.
 *
 * @param schema the schema
 * @param field the field
 * @return the field type
 * @throws IOException Signals that an I/O exception has occurred.
 */
private String getFieldType(IndexSchema schema, String field)
    throws IOException {
  SchemaField sf = schema.getField(field);
  FieldType ft = sf.getType();
  if (ft != null) {
    if (ft.isPointField() && !sf.hasDocValues()) {
      return ComponentFacet.TYPE_POINTFIELD_WITHOUT_DOCVALUES;
    }
    NumberType nt = ft.getNumberType();
    if (nt != null) {
      return nt.name();
    } else {
      return ComponentFacet.TYPE_STRING;
    }
  } else {
    // best guess
    return ComponentFacet.TYPE_STRING;
  }
}
 
public void testStringWithCopyFieldAndMaxChars() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  final String fieldName = "stringField";
  final String strFieldName = fieldName+"_str";
  assertNull(schema.getFieldOrNull(fieldName));
  String content = "This is a text that should be copied to a string field and cutoff at 10 characters";
  SolrInputDocument d = processAdd("add-fields-maxchars", doc(f("id", "1"), f(fieldName, content)));
  assertNotNull(d);
  System.out.println("Document is "+d);
  schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull(fieldName));
  assertNotNull(schema.getFieldOrNull(strFieldName));
  assertEquals("text", schema.getFieldType(fieldName).getTypeName());
  // We have three copyFields, one with maxChars 10 and two with maxChars 20
  assertEquals(3, schema.getCopyFieldProperties(true, Collections.singleton(fieldName), null).size());
  assertEquals("The configured maxChars cutoff does not exist on the copyField", 10, 
      schema.getCopyFieldProperties(true, Collections.singleton(fieldName), Collections.singleton(strFieldName))
          .get(0).get("maxChars"));
  assertEquals("The configured maxChars cutoff does not exist on the copyField", 20, 
      schema.getCopyFieldProperties(true, Collections.singleton(fieldName), Collections.singleton(fieldName+"_t"))
          .get(0).get("maxChars"));
  assertEquals("The configured maxChars cutoff does not exist on the copyField", 20, 
      schema.getCopyFieldProperties(true, Collections.singleton(fieldName), Collections.singleton(fieldName+"2_t"))
          .get(0).get("maxChars"));
}
 
源代码19 项目: lucene-solr   文件: TestRetrieveFieldsOptimizer.java
IndexSchema addFields(IndexSchema schema) {

    List<SchemaField> fieldsToAdd = new ArrayList<>();

    for (RetrieveField field : fields.values()) {
      allFields.add(field);
      SchemaField schemaField = field.schemaField;
      fieldsToAdd.add(schemaField);
      if (schemaField.multiValued()) {
        multiValuedFields.add(field);
      }
      if (schemaField.hasDocValues() && schemaField.stored() == false) {
        dvNotStoredFields.add(field);
      }
      if (schemaField.hasDocValues() == false && schemaField.stored()) {
        storedNotDvFields.add(field);
      }
      if (schemaField.hasDocValues() && schemaField.stored()) {
        storedAndDvFields.add(field);
      }
      if (schemaField.stored() && schemaField.multiValued()) {
        storedMvFields.add(field);
      }
    }
    return schema.addFields(fieldsToAdd, Collections.emptyMap(), false);
  }
 
public void testParseTrieDoubleRoundTrip() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("double1_td")); // should match dynamic field "*_td"
  assertNotNull(schema.getFieldOrNull("double2_td")); // should match dynamic field "*_td"
  double value = 10898.83491;
  String doubleString1 = "10898.83491";
  String doubleString2 = "10,898.83491";
  SolrInputDocument d = processAdd("parse-double",
      doc(f("id", "728"), f("double1_td", doubleString1), f("double2_td", doubleString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("double1_td"), IS_DOUBLE);
  assertEquals(value, (Double)d.getFieldValue("double1_td"), EPSILON);
  assertThat(d.getFieldValue("double2_td"), IS_DOUBLE);
  assertEquals(value, (Double)d.getFieldValue("double2_td"), EPSILON);

  assertU(commit());
  assertQ(req("id:728")
      ,"//double[@name='double1_td'][.='" + value + "']"
      ,"//double[@name='double2_td'][.='" + value + "']");
}
 
/**
 * Relod method of spellcheck listner
 * @param newSearcher
 * @param checker
 * @throws IOException
 * @throws SpellCheckException
 */
public void reload(SolrIndexSearcher newSearcher, SpellChecker checker)
    throws IOException, SpellCheckException {

  DirectoryReader productsIndexReader = newSearcher.getIndexReader();
  Fields fields = MultiFields.getFields(productsIndexReader);
  IndexSchema schema = newSearcher.getCore().getLatestSchema();
  long time = System.currentTimeMillis();
  for (String field : fields) {
    if (!fieldArr.contains(field)) {
      continue;
    }
    FieldType type = schema.getField(field).getType();
    int insertionsCount = 0;
    for (TermsEnum iterator = fields.terms(field).iterator(); iterator.next() != null; ) {
      BytesRef term = iterator.term();
      CharsRefBuilder charsRefBuilder = new CharsRefBuilder();
      type.indexedToReadable(term, charsRefBuilder);
      insertionsCount++;
      checker.getDataHolder().addItem(
          new DictionaryItem(charsRefBuilder.toString().trim(), (double) iterator.totalTermFreq(),
              0.0));
    }
    log.info("Spellcheck Dictionary populated for Field Name {}, Count {}", field,
        insertionsCount);
  }
  log.info("Data for SpellChecker  was populated. Time={} ms",
      (System.currentTimeMillis() - time));
}
 
源代码22 项目: SearchServices   文件: MLAnalayser.java
public MLAnalayser(MLAnalysisMode mlAnalaysisMode, IndexSchema schema, Mode mode)
{
    super(Analyzer.PER_FIELD_REUSE_STRATEGY);
    this.mlAnalaysisMode = mlAnalaysisMode;
    this.schema = schema;
    this.mode = mode;
}
 
public void testIntOverflow() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNull(schema.getFieldOrNull("not_in_schema1"));
  assertNull(schema.getFieldOrNull("not_in_schema2"));
  long longValue1 = (long)Integer.MAX_VALUE + 100L;
  long longValue2 = (long)Integer.MIN_VALUE - 100L;
  String longString1 = Long.toString(longValue1);
  String longString2 = Long.toString(longValue2);
  SolrInputDocument d = processAdd("parse-int-no-run-processor",
      doc(f("id", "282"), f("not_in_schema1", longString1), f("not_in_schema2", longString2)));
  assertNotNull(d);
  assertThat(d.getFieldValue("not_in_schema1"), IS_STRING);
  assertThat(d.getFieldValue("not_in_schema2"), IS_STRING);
}
 
源代码24 项目: SearchServices   文件: AlfrescoFieldType.java
@Override
protected void init(IndexSchema schema, Map<String, String> args)
{
    this.schema = schema;
    properties |= TOKENIZED;
    properties &= ~OMIT_TF_POSITIONS;
    super.init(schema, args);
    
    // TODO: Wire up localised analysis driven from the schema
    // for now we do something basic
    setIndexAnalyzer(new AlfrescoAnalyzerWrapper(schema, AlfrescoAnalyzerWrapper.Mode.INDEX));
    setQueryAnalyzer(new AlfrescoAnalyzerWrapper(schema, AlfrescoAnalyzerWrapper.Mode.QUERY));
}
 
public void testParseTrieDateRoundTrip() throws Exception {
  IndexSchema schema = h.getCore().getLatestSchema();
  assertNotNull(schema.getFieldOrNull("date_tdt")); // should match "*_tdt" dynamic field
  String dateString = "2010-11-12T13:14:15.168Z";
  SolrInputDocument d = processAdd("parse-date", doc(f("id", "39"), f("date_tdt", dateString)));
  assertNotNull(d);
  assertThat(d.getFieldValue("date_tdt"), IS_DATE);
  assertEquals(Instant.parse(dateString), ((Date) d.getFieldValue("date_tdt")).toInstant());
  assertU(commit());
  assertQ(req("id:39"), "//date[@name='date_tdt'][.='" + dateString + "']");
}
 
源代码26 项目: BioSolr   文件: MergeSearchComponent.java
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  // do the filterQParser stuff first
  super.modifyRequest(rb, who, sreq);
  
  if (! doMerge(rb)) {
    return;
  }
  
  ReturnFields rf = rb.rsp.getReturnFields();
  if (rf.wantsAllFields()) {
    // we already have what we need since we ask for everything...
    return;
  }

  IndexSchema schema = rb.req.getCore().getLatestSchema();
  for (SchemaField field : schema.getFields().values()) {
    if (! rf.wantsField(field.getName())) {
      continue;
    }
    for (String source : schema.getCopySources(field.getName())) {
      if (rf.wantsField(source)) {
        continue;
      }
      sreq.params.add(CommonParams.FL, source);
    }
  }
}
 
源代码27 项目: lucene-solr   文件: SolrTestCaseJ4.java
public Map<String,Object> toObject(IndexSchema schema) {
  Map<String,Object> result = new HashMap<>();
  for (Fld fld : fields) {
    SchemaField sf = schema.getField(fld.ftype.fname);
    if (!sf.multiValued()) {
      result.put(fld.ftype.fname, fld.vals.get(0));
    } else {
      result.put(fld.ftype.fname, fld.vals);
    }
  }
  return result;
}
 
源代码28 项目: BioSolr   文件: DJoinMergeStrategy.java
@SuppressWarnings({ "rawtypes", "unchecked" })
private NamedList unmarshalSortValues(SortSpec sortSpec, NamedList sortFieldValues, IndexSchema schema) {
  NamedList unmarshalledSortValsPerField = new NamedList();

  if (0 == sortFieldValues.size())
    return unmarshalledSortValsPerField;

  List<SchemaField> schemaFields = sortSpec.getSchemaFields();
  SortField[] sortFields = sortSpec.getSort().getSort();

  int marshalledFieldNum = 0;
  for (int sortFieldNum = 0; sortFieldNum < sortFields.length; sortFieldNum++) {
    final SortField sortField = sortFields[sortFieldNum];
    final SortField.Type type = sortField.getType();

    // :TODO: would be simpler to always serialize every position of SortField[]
    if (type == SortField.Type.SCORE || type == SortField.Type.DOC)
      continue;

    final String sortFieldName = sortField.getField();
    final String valueFieldName = sortFieldValues.getName(marshalledFieldNum);
    assert sortFieldName.equals(valueFieldName) : "sortFieldValues name key does not match expected SortField.getField";

    List sortVals = (List) sortFieldValues.getVal(marshalledFieldNum);

    final SchemaField schemaField = schemaFields.get(sortFieldNum);
    if (null == schemaField) {
      unmarshalledSortValsPerField.add(sortField.getField(), sortVals);
    } else {
      FieldType fieldType = schemaField.getType();
      List unmarshalledSortVals = new ArrayList();
      for (Object sortVal : sortVals) {
        unmarshalledSortVals.add(fieldType.unmarshalSortValue(sortVal));
      }
      unmarshalledSortValsPerField.add(sortField.getField(), unmarshalledSortVals);
    }
    marshalledFieldNum++;
  }
  return unmarshalledSortValsPerField;
}
 
/**
 * Obtains stop words for a field from the associated
 * {@link StopFilterFactory}, if any.
 */
private List<CharArraySet> getSolrStopWordsForField(String fieldName) {
  // No need to synchronize here, Carrot2 ensures that instances
  // of this class are not used by multiple threads at a time.
  synchronized (solrStopWords) {
    if (!solrStopWords.containsKey(fieldName)) {
      solrStopWords.put(fieldName, new ArrayList<>());

      IndexSchema schema = core.getLatestSchema();
      final Analyzer fieldAnalyzer = schema.getFieldType(fieldName).getIndexAnalyzer();
      if (fieldAnalyzer instanceof TokenizerChain) {
        final TokenFilterFactory[] filterFactories = 
            ((TokenizerChain) fieldAnalyzer).getTokenFilterFactories();
        for (TokenFilterFactory factory : filterFactories) {
          if (factory instanceof StopFilterFactory) {
            // StopFilterFactory holds the stop words in a CharArraySet
            CharArraySet stopWords = ((StopFilterFactory) factory).getStopWords();
            solrStopWords.get(fieldName).add(stopWords);
          }

          if (factory instanceof CommonGramsFilterFactory) {
            CharArraySet commonWords = ((CommonGramsFilterFactory) factory).getCommonWords();
            solrStopWords.get(fieldName).add(commonWords);
          }
        }
      }
    }
    return solrStopWords.get(fieldName);
  }
}
 
源代码30 项目: lucene-solr   文件: DisMaxQParser.java
/**
 * Uses {@link SolrPluginUtils#parseFieldBoosts(String)} with the 'qf' parameter. Falls back to the 'df' parameter
 */
public static Map<String, Float> parseQueryFields(final IndexSchema indexSchema, final SolrParams solrParams)
    throws SyntaxError {
  Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.QF));
  if (queryFields.isEmpty()) {
    String df = solrParams.get(CommonParams.DF);
    if (df == null) {
      throw new SyntaxError("Neither "+DisMaxParams.QF+" nor "+CommonParams.DF +" are present.");
    }
    queryFields.put(df, 1.0f);
  }
  return queryFields;
}