Search in sources :

Example 86 with FieldType

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

the class CommandHandler method computeGroupedDocSet.

private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
    Command firstCommand = commands.get(0);
    String field = firstCommand.getKey();
    SchemaField sf = searcher.getSchema().getField(field);
    FieldType fieldType = sf.getType();
    final AllGroupHeadsCollector allGroupHeadsCollector;
    if (fieldType.getNumberType() != null) {
        ValueSource vs = fieldType.getValueSource(sf, null);
        allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new ValueSourceGroupSelector(vs, new HashMap<>()), firstCommand.getWithinGroupSort());
    } else {
        allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new TermGroupSelector(firstCommand.getKey()), firstCommand.getWithinGroupSort());
    }
    if (collectors.isEmpty()) {
        searchWithTimeLimiter(query, filter, allGroupHeadsCollector);
    } else {
        collectors.add(allGroupHeadsCollector);
        searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
    }
    return new BitDocSet(allGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) BitDocSet(org.apache.solr.search.BitDocSet) QueryCommand(org.apache.solr.search.QueryCommand) ValueSource(org.apache.lucene.queries.function.ValueSource) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) AllGroupHeadsCollector(org.apache.lucene.search.grouping.AllGroupHeadsCollector) FieldType(org.apache.solr.schema.FieldType)

Example 87 with FieldType

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

the class GroupConverter method fromMutable.

static TopGroups<BytesRef> fromMutable(SchemaField field, TopGroups<MutableValue> values) {
    if (values == null) {
        return null;
    }
    FieldType fieldType = field.getType();
    @SuppressWarnings("unchecked") GroupDocs<BytesRef>[] groupDocs = new GroupDocs[values.groups.length];
    for (int i = 0; i < values.groups.length; i++) {
        GroupDocs<MutableValue> original = values.groups[i];
        final BytesRef groupValue;
        if (original.groupValue.exists) {
            BytesRefBuilder binary = new BytesRefBuilder();
            fieldType.readableToIndexed(original.groupValue.toString(), binary);
            groupValue = binary.get();
        } else {
            groupValue = null;
        }
        groupDocs[i] = new GroupDocs<BytesRef>(original.score, original.maxScore, original.totalHits, original.scoreDocs, groupValue, original.groupSortValues);
    }
    return new TopGroups<BytesRef>(values.groupSort, values.withinGroupSort, values.totalHitCount, values.totalGroupedHitCount, groupDocs, values.maxScore);
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) MutableValue(org.apache.lucene.util.mutable.MutableValue) TopGroups(org.apache.lucene.search.grouping.TopGroups) GroupDocs(org.apache.lucene.search.grouping.GroupDocs) BytesRef(org.apache.lucene.util.BytesRef) FieldType(org.apache.solr.schema.FieldType)

Example 88 with FieldType

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

the class SearchGroupsFieldCommand method create.

@Override
public List<Collector> create() throws IOException {
    final List<Collector> collectors = new ArrayList<>(2);
    final FieldType fieldType = field.getType();
    if (topNGroups > 0) {
        if (fieldType.getNumberType() != null) {
            ValueSource vs = fieldType.getValueSource(field, null);
            firstPassGroupingCollector = new FirstPassGroupingCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()), groupSort, topNGroups);
        } else {
            firstPassGroupingCollector = new FirstPassGroupingCollector<>(new TermGroupSelector(field.getName()), groupSort, topNGroups);
        }
        collectors.add(firstPassGroupingCollector);
    }
    if (includeGroupCount) {
        if (fieldType.getNumberType() != null) {
            ValueSource vs = fieldType.getValueSource(field, null);
            allGroupsCollector = new AllGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()));
        } else {
            allGroupsCollector = new AllGroupsCollector<>(new TermGroupSelector(field.getName()));
        }
        collectors.add(allGroupsCollector);
    }
    return collectors;
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) ArrayList(java.util.ArrayList) AllGroupsCollector(org.apache.lucene.search.grouping.AllGroupsCollector) Collector(org.apache.lucene.search.Collector) FirstPassGroupingCollector(org.apache.lucene.search.grouping.FirstPassGroupingCollector) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) FieldType(org.apache.solr.schema.FieldType)

Example 89 with FieldType

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

the class TopGroupsFieldCommand method create.

@Override
public List<Collector> create() throws IOException {
    if (firstPhaseGroups.isEmpty()) {
        return Collections.emptyList();
    }
    final List<Collector> collectors = new ArrayList<>(1);
    final FieldType fieldType = field.getType();
    if (fieldType.getNumberType() != null) {
        ValueSource vs = fieldType.getValueSource(field, null);
        Collection<SearchGroup<MutableValue>> v = GroupConverter.toMutable(field, firstPhaseGroups);
        secondPassCollector = new TopGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()), v, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true);
    } else {
        secondPassCollector = new TopGroupsCollector<>(new TermGroupSelector(field.getName()), firstPhaseGroups, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true);
    }
    collectors.add(secondPassCollector);
    return collectors;
}
Also used : SearchGroup(org.apache.lucene.search.grouping.SearchGroup) ValueSource(org.apache.lucene.queries.function.ValueSource) ArrayList(java.util.ArrayList) Collector(org.apache.lucene.search.Collector) TopGroupsCollector(org.apache.lucene.search.grouping.TopGroupsCollector) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) FieldType(org.apache.solr.schema.FieldType)

Example 90 with FieldType

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

the class TopGroupsShardRequestFactory method createRequest.

private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards) {
    ShardRequest sreq = new ShardRequest();
    sreq.shards = shards;
    sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
    sreq.params = new ModifiableSolrParams(rb.req.getParams());
    // If group.format=simple group.offset doesn't make sense
    Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat();
    if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) {
        sreq.params.remove(GroupParams.GROUP_OFFSET);
    }
    sreq.params.remove(ShardParams.SHARDS);
    // results from the start.
    if (rb.shards_start > -1) {
        // if the client set shards.start set this explicitly
        sreq.params.set(CommonParams.START, rb.shards_start);
    } else {
        sreq.params.set(CommonParams.START, "0");
    }
    if (rb.shards_rows > -1) {
        // if the client set shards.rows set this explicitly
        sreq.params.set(CommonParams.ROWS, rb.shards_rows);
    } else {
        sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
    }
    sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true");
    final IndexSchema schema = rb.req.getSearcher().getSchema();
    for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) {
        for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
            String groupValue;
            if (searchGroup.groupValue != null) {
                FieldType fieldType = schema.getField(entry.getKey()).getType();
                groupValue = fieldType.indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString();
            } else {
                groupValue = GROUP_NULL_VALUE;
            }
            sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue);
        }
    }
    if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
        sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName() + ",score");
    } else {
        sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName());
    }
    int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1);
    if (origTimeAllowed > 0) {
        sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1, origTimeAllowed - rb.firstPhaseElapsedTime));
    }
    return new ShardRequest[] { sreq };
}
Also used : Grouping(org.apache.solr.search.Grouping) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldType(org.apache.solr.schema.FieldType) Collection(java.util.Collection) ShardRequest(org.apache.solr.handler.component.ShardRequest) IndexSchema(org.apache.solr.schema.IndexSchema) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

FieldType (org.apache.solr.schema.FieldType)93 SchemaField (org.apache.solr.schema.SchemaField)37 SolrException (org.apache.solr.common.SolrException)29 ArrayList (java.util.ArrayList)23 BytesRef (org.apache.lucene.util.BytesRef)23 NamedList (org.apache.solr.common.util.NamedList)23 IOException (java.io.IOException)18 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)15 IndexSchema (org.apache.solr.schema.IndexSchema)14 Query (org.apache.lucene.search.Query)13 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)13 Analyzer (org.apache.lucene.analysis.Analyzer)12 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)10 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)10 StrField (org.apache.solr.schema.StrField)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 DocIterator (org.apache.solr.search.DocIterator)7 DocList (org.apache.solr.search.DocList)7