Search in sources :

Example 1 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class UIMATokenizersSolrIntegrationTest method testInitialization.

@Test
public void testInitialization() throws Exception {
    IndexSchema schema = h.getCore().getLatestSchema();
    assertNotNull(schema.getField("sentences"));
    assertNotNull(schema.getFieldType("sentences"));
    assertNotNull(schema.getField("nouns"));
    assertNotNull(schema.getFieldType("nouns"));
}
Also used : IndexSchema(org.apache.solr.schema.IndexSchema) Test(org.junit.Test)

Example 2 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class QueryElevationComponent method inform.

@Override
public void inform(SolrCore core) {
    IndexSchema schema = core.getLatestSchema();
    String a = initArgs.get(FIELD_TYPE);
    if (a != null) {
        FieldType ft = schema.getFieldTypes().get(a);
        if (ft == null) {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown FieldType: '" + a + "' used in QueryElevationComponent");
        }
        analyzer = ft.getQueryAnalyzer();
    }
    SchemaField sf = schema.getUniqueKeyField();
    if (sf == null) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent requires the schema to have a uniqueKeyField.");
    }
    idSchemaFT = sf.getType();
    idField = sf.getName();
    //register the EditorialMarkerFactory
    String excludeName = initArgs.get(QueryElevationParams.EXCLUDE_MARKER_FIELD_NAME, "excluded");
    if (excludeName == null || excludeName.equals("") == true) {
        excludeName = "excluded";
    }
    ExcludedMarkerFactory excludedMarkerFactory = new ExcludedMarkerFactory();
    core.addTransformerFactory(excludeName, excludedMarkerFactory);
    ElevatedMarkerFactory elevatedMarkerFactory = new ElevatedMarkerFactory();
    String markerName = initArgs.get(QueryElevationParams.EDITORIAL_MARKER_FIELD_NAME, "elevated");
    if (markerName == null || markerName.equals("") == true) {
        markerName = "elevated";
    }
    core.addTransformerFactory(markerName, elevatedMarkerFactory);
    forceElevation = initArgs.getBool(QueryElevationParams.FORCE_ELEVATION, forceElevation);
    try {
        synchronized (elevationCache) {
            elevationCache.clear();
            String f = initArgs.get(CONFIG_FILE);
            if (f == null) {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent must specify argument: '" + CONFIG_FILE + "' -- path to elevate.xml");
            }
            boolean exists = false;
            // check if using ZooKeeper
            ZkController zkController = core.getCoreContainer().getZkController();
            if (zkController != null) {
                // TODO : shouldn't have to keep reading the config name when it has been read before
                exists = zkController.configFileExists(zkController.getZkStateReader().readConfigName(core.getCoreDescriptor().getCloudDescriptor().getCollectionName()), f);
            } else {
                File fC = new File(core.getResourceLoader().getConfigDir(), f);
                File fD = new File(core.getDataDir(), f);
                if (fC.exists() == fD.exists()) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent missing config file: '" + f + "\n" + "either: " + fC.getAbsolutePath() + " or " + fD.getAbsolutePath() + " must exist, but not both.");
                }
                if (fC.exists()) {
                    exists = true;
                    log.info("Loading QueryElevation from: " + fC.getAbsolutePath());
                    Config cfg = new Config(core.getResourceLoader(), f);
                    elevationCache.put(null, loadElevationMap(cfg));
                }
            }
            //in other words, we think this is in the data dir, not the conf dir
            if (!exists) {
                // preload the first data
                RefCounted<SolrIndexSearcher> searchHolder = null;
                try {
                    searchHolder = core.getNewestSearcher(false);
                    IndexReader reader = searchHolder.get().getIndexReader();
                    getElevationMap(reader, core);
                } finally {
                    if (searchHolder != null)
                        searchHolder.decref();
                }
            }
        }
    } catch (Exception ex) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error initializing QueryElevationComponent.", ex);
    }
}
Also used : ExcludedMarkerFactory(org.apache.solr.response.transform.ExcludedMarkerFactory) Config(org.apache.solr.core.Config) ElevatedMarkerFactory(org.apache.solr.response.transform.ElevatedMarkerFactory) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) ZkController(org.apache.solr.cloud.ZkController) IndexReader(org.apache.lucene.index.IndexReader) IndexSchema(org.apache.solr.schema.IndexSchema) VersionedFile(org.apache.solr.util.VersionedFile) File(java.io.File) SolrException(org.apache.solr.common.SolrException)

Example 3 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class MoreLikeThisComponent method getMoreLikeThese.

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;
}
Also used : DocIterator(org.apache.solr.search.DocIterator) MoreLikeThisHandler(org.apache.solr.handler.MoreLikeThisHandler) DocListAndSet(org.apache.solr.search.DocListAndSet) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IndexSchema(org.apache.solr.schema.IndexSchema) DocList(org.apache.solr.search.DocList)

Example 4 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class RangeFacetProcessor method getFacetRangeCounts.

/**
   * Returns a list of value constraints and the associated facet counts
   * for each facet range specified by the given {@link RangeFacetRequest}
   */
public void getFacetRangeCounts(RangeFacetRequest rangeFacetRequest, NamedList<Object> resOuter) throws IOException, SyntaxError {
    final IndexSchema schema = searcher.getSchema();
    final String key = rangeFacetRequest.getKey();
    final String f = rangeFacetRequest.facetOn;
    FacetRangeMethod method = rangeFacetRequest.getMethod();
    final SchemaField sf = schema.getField(f);
    final FieldType ft = sf.getType();
    if (method.equals(FacetRangeMethod.DV)) {
        assert ft instanceof TrieField || ft.isPointField();
        resOuter.add(key, getFacetRangeCountsDocValues(rangeFacetRequest));
    } else {
        resOuter.add(key, getFacetRangeCounts(rangeFacetRequest));
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) FacetRangeMethod(org.apache.solr.common.params.FacetParams.FacetRangeMethod) IndexSchema(org.apache.solr.schema.IndexSchema) TrieField(org.apache.solr.schema.TrieField) FieldType(org.apache.solr.schema.FieldType)

Example 5 with IndexSchema

use of org.apache.solr.schema.IndexSchema in project lucene-solr by apache.

the class TopGroupsResultTransformer method serializeTopDocs.

protected NamedList serializeTopDocs(QueryCommandResult result) throws IOException {
    NamedList<Object> queryResult = new NamedList<>();
    queryResult.add("matches", result.getMatches());
    queryResult.add("totalHits", result.getTopDocs().totalHits);
    // debug: assert !Float.isNaN(result.getTopDocs().getMaxScore()) == rb.getGroupingSpec().isNeedScore();
    if (!Float.isNaN(result.getTopDocs().getMaxScore())) {
        queryResult.add("maxScore", result.getTopDocs().getMaxScore());
    }
    List<NamedList> documents = new ArrayList<>();
    queryResult.add("documents", documents);
    final IndexSchema schema = rb.req.getSearcher().getSchema();
    SchemaField uniqueField = schema.getUniqueKeyField();
    for (ScoreDoc scoreDoc : result.getTopDocs().scoreDocs) {
        NamedList<Object> document = new NamedList<>();
        documents.add(document);
        Document doc = retrieveDocument(uniqueField, scoreDoc.doc);
        document.add(ID, uniqueField.getType().toExternal(doc.getField(uniqueField.getName())));
        if (!Float.isNaN(scoreDoc.score)) {
            document.add("score", scoreDoc.score);
        }
        if (!FieldDoc.class.isInstance(scoreDoc)) {
            // thus don't add sortValues below
            continue;
        }
        FieldDoc fieldDoc = (FieldDoc) scoreDoc;
        Object[] convertedSortValues = new Object[fieldDoc.fields.length];
        for (int j = 0; j < fieldDoc.fields.length; j++) {
            Object sortValue = fieldDoc.fields[j];
            Sort groupSort = rb.getGroupingSpec().getGroupSort();
            SchemaField field = groupSort.getSort()[j].getField() != null ? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;
            convertedSortValues[j] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
        }
        document.add("sortValues", convertedSortValues);
    }
    return queryResult;
}
Also used : FieldDoc(org.apache.lucene.search.FieldDoc) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) SchemaField(org.apache.solr.schema.SchemaField) Sort(org.apache.lucene.search.Sort) IndexSchema(org.apache.solr.schema.IndexSchema)

Aggregations

IndexSchema (org.apache.solr.schema.IndexSchema)116 SolrInputDocument (org.apache.solr.common.SolrInputDocument)42 SchemaField (org.apache.solr.schema.SchemaField)34 HashMap (java.util.HashMap)16 SolrException (org.apache.solr.common.SolrException)15 IOException (java.io.IOException)14 FieldType (org.apache.solr.schema.FieldType)14 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)13 Date (java.util.Date)12 LinkedHashMap (java.util.LinkedHashMap)12 NamedList (org.apache.solr.common.util.NamedList)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 ArrayList (java.util.ArrayList)11 Document (org.apache.lucene.document.Document)11 SolrParams (org.apache.solr.common.params.SolrParams)11 DateTime (org.joda.time.DateTime)10 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)9 SolrConfig (org.apache.solr.core.SolrConfig)8 Test (org.junit.Test)7