aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/FieldSets.java
blob: abe19ddf8310e3421284924ff486d101cd49fbfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import com.yahoo.searchdefinition.document.FieldSet;

/**
 * The field sets owned by a {@link Search}
 * Both built in and user defined.
 * @author vegardh
 *
 */
public class FieldSets {

    private final Map<String, FieldSet> userFieldSets = new LinkedHashMap<>();
    private final Map<String, FieldSet> builtInFieldSets = new LinkedHashMap<>();

    /**
     * Adds an entry to user field sets, creating entries as needed
     *
     * @param setName name of a field set
     * @param field field to add to field set
     */
    public void addUserFieldSetItem(String setName, String field) {
        if (userFieldSets.get(setName) == null) {
            // First entry in this set
            userFieldSets.put(setName, new FieldSet(setName));
        }
        userFieldSets.get(setName).addFieldName(field);
    }

    /**
     * Adds an entry to built in field sets, creating entries as needed
     *
     * @param setName name of a field set
     * @param field field to add to field set
     */
    public void addBuiltInFieldSetItem(String setName, String field) {
        if (builtInFieldSets.get(setName) == null) {
            // First entry in this set
            builtInFieldSets.put(setName, new FieldSet(setName));
        }
        builtInFieldSets.get(setName).addFieldName(field);
    }

    /**
     * The built in field sets, unmodifiable
     * @return built in field sets
     */
    public Map<String, FieldSet> builtInFieldSets() {
        return Collections.unmodifiableMap(builtInFieldSets);
    }
    
    /**
     * The user defined field sets, unmodifiable
     * @return user field sets
     */
    public Map<String, FieldSet> userFieldSets() {
        return Collections.unmodifiableMap(userFieldSets);
    }
    
}