Java Code Examples for org.apache.solr.search.SolrIndexSearcher#getSlowAtomicReader()

The following examples show how to use org.apache.solr.search.SolrIndexSearcher#getSlowAtomicReader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FieldFacetStats.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public FieldFacetStats(SolrIndexSearcher searcher, SchemaField facet_sf, StatsField statsField) {
  this.statsField = statsField;
  this.facet_sf = facet_sf;
  this.name = facet_sf.getName();

  topLevelReader = searcher.getSlowAtomicReader();
  valueSource = facet_sf.getType().getValueSource(facet_sf, null);

  facetStatsValues = new HashMap<>();
  facetStatsTerms = new ArrayList<>();
  missingStats = new HashMap<>();
}
 
Example 2
Source File: DocValuesMultiTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocValues() throws IOException {

  final DocValuesType expectedNumericDvType = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP) ?
    DocValuesType.SORTED_NUMERIC : DocValuesType.SORTED_SET;
  
  assertU(adoc("id", "1", "floatdv", "4.5", "intdv", "-1", "intdv", "3",
      "stringdv", "value1", "stringdv", "value2",
      "booldv", "false", "booldv", "true"));
  assertU(commit());
  try (SolrCore core = h.getCoreInc()) {
    final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
    final SolrIndexSearcher searcher = searcherRef.get();
    try {
      final LeafReader reader = searcher.getSlowAtomicReader();
      assertEquals(1, reader.numDocs());
      final FieldInfos infos = reader.getFieldInfos();
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("stringdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("booldv").getDocValuesType());
      assertEquals(expectedNumericDvType, infos.fieldInfo("floatdv").getDocValuesType());
      assertEquals(expectedNumericDvType, infos.fieldInfo("intdv").getDocValuesType());

      SortedSetDocValues dv = reader.getSortedSetDocValues("stringdv");
      assertEquals(0, dv.nextDoc());
      assertEquals(0, dv.nextOrd());
      assertEquals(1, dv.nextOrd());
      assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.nextOrd());

      dv = reader.getSortedSetDocValues("booldv");
      assertEquals(0, dv.nextDoc());
      assertEquals(0, dv.nextOrd());
      assertEquals(1, dv.nextOrd());
      assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.nextOrd());


    } finally {
      searcherRef.decref();
    }
  }
}
 
Example 3
Source File: AlfrescoLukeRequestHandler.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
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]+")));
	}

	LeafReader reader = searcher.getSlowAtomicReader();
	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> vInfo = new SimpleOrderedMap<>();
	SimpleOrderedMap<Object> aInfo = 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)
			vInfo.add(AlfrescoSolrDataModel.getInstance()
					.getAlfrescoPropertyFromSchemaField(fieldName),
					fieldMap);
			aInfo.add(fieldName, fieldMap);
			continue;
		}

		if (sfield != null && sfield.indexed()) {
			if (params.getBool(INCLUDE_INDEX_FIELD_FLAGS, true)) {
				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
		vInfo.add(fieldName, fieldMap);
		aInfo.add(AlfrescoSolrDataModel.getInstance()
				.getAlfrescoPropertyFromSchemaField(fieldName), fieldMap);
	}

	SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();
	finfo.addAll(vInfo);
	// finfo.add("mimetype()", finfo.get("cm:content.mimetype"));
	// finfo.add("contentSize()", finfo.get("cm:content.size"));
	finfo.addAll(aInfo);
	return finfo;
}
 
Example 4
Source File: LukeRequestHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
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]+" )));
  }

  LeafReader reader = searcher.getSlowAtomicReader();
  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.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() ) {
      if (params.getBool(INCLUDE_INDEX_FIELD_FLAGS,true)) {
        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;
}
 
Example 5
Source File: DocValuesTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testDocValues() throws IOException {
  assertU(adoc("id", "1"));
  assertU(commit());
  try (SolrCore core = h.getCoreInc()) {
    final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
    final SolrIndexSearcher searcher = searcherRef.get();
    try {
      final LeafReader reader = searcher.getSlowAtomicReader();
      assertEquals(1, reader.numDocs());
      final FieldInfos infos = reader.getFieldInfos();
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("floatdv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("intdv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("doubledv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("longdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED, infos.fieldInfo("stringdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED, infos.fieldInfo("booldv").getDocValuesType());

      NumericDocValues dvs = reader.getNumericDocValues("floatdv");
      assertEquals(0, dvs.nextDoc());
      assertEquals((long) Float.floatToIntBits(1), dvs.longValue());
      dvs = reader.getNumericDocValues("intdv");
      assertEquals(0, dvs.nextDoc());
      assertEquals(2L, dvs.longValue());
      dvs = reader.getNumericDocValues("doubledv");
      assertEquals(0, dvs.nextDoc());
      assertEquals(Double.doubleToLongBits(3), dvs.longValue());
      dvs = reader.getNumericDocValues("longdv");
      assertEquals(0, dvs.nextDoc());
      assertEquals(4L, dvs.longValue());
      SortedDocValues sdv = reader.getSortedDocValues("stringdv");
      assertEquals(0, sdv.nextDoc());
      assertEquals("solr", sdv.binaryValue().utf8ToString());
      sdv = reader.getSortedDocValues("booldv");
      assertEquals(0, sdv.nextDoc());
      assertEquals("T", sdv.binaryValue().utf8ToString());

      final IndexSchema schema = core.getLatestSchema();
      final SchemaField floatDv = schema.getField("floatdv");
      final SchemaField intDv = schema.getField("intdv");
      final SchemaField doubleDv = schema.getField("doubledv");
      final SchemaField longDv = schema.getField("longdv");
      final SchemaField boolDv = schema.getField("booldv");

      FunctionValues values = floatDv.getType().getValueSource(floatDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
      assertEquals(1f, values.floatVal(0), 0f);
      assertEquals(1f, values.objectVal(0));
      values = intDv.getType().getValueSource(intDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
      assertEquals(2, values.intVal(0));
      assertEquals(2, values.objectVal(0));
      values = doubleDv.getType().getValueSource(doubleDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
      assertEquals(3d, values.doubleVal(0), 0d);
      assertEquals(3d, values.objectVal(0));
      values = longDv.getType().getValueSource(longDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
      assertEquals(4L, values.longVal(0));
      assertEquals(4L, values.objectVal(0));
      
      values = boolDv.getType().getValueSource(boolDv, null).getValues(null, searcher.getSlowAtomicReader().leaves().get(0));
      assertEquals("true", values.strVal(0));
      assertEquals(true, values.objectVal(0));

      // check reversibility of created fields
      tstToObj(schema.getField("floatdv"), -1.5f);
      tstToObj(schema.getField("floatdvs"), -1.5f);
      tstToObj(schema.getField("doubledv"), -1.5d);
      tstToObj(schema.getField("doubledvs"), -1.5d);
      tstToObj(schema.getField("intdv"), -7);
      tstToObj(schema.getField("intdvs"), -7);
      tstToObj(schema.getField("longdv"), -11L);
      tstToObj(schema.getField("longdvs"), -11L);
      tstToObj(schema.getField("datedv"), new Date(1000));
      tstToObj(schema.getField("datedvs"), new Date(1000));
      tstToObj(schema.getField("stringdv"), "foo");
      tstToObj(schema.getField("stringdvs"), "foo");
      tstToObj(schema.getField("booldv"), true);
      tstToObj(schema.getField("booldvs"), true);

    } finally {
      searcherRef.decref();
    }
  }
}