Search in sources :

Example 21 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method review.

@Override
public Map<Long, List<String>> review(long record) {
    Identifier L = Identifier.of(record);
    TableRecord table = getTableRecord(L);
    return table.review();
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier)

Example 22 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method review.

@Override
public Map<Long, List<String>> review(String key, long record) {
    Identifier L = Identifier.of(record);
    Text K = Text.wrapCached(key);
    TableRecord table = getTableRecord(L, K);
    return table.review(K);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Text(com.cinchapi.concourse.server.model.Text)

Example 23 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method browse.

@Override
public Map<TObject, Set<Long>> browse(String key) {
    Text L = Text.wrapCached(key);
    IndexRecord index = getIndexRecord(L);
    Map<Value, Set<Identifier>> data = index.getAll();
    return Transformers.transformTreeMapSet(data, Value::getTObject, Identifier::longValue, TObjectSorter.INSTANCE);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 24 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method browse.

@Override
public Map<TObject, Set<Long>> browse(String key, long timestamp) {
    Text L = Text.wrapCached(key);
    IndexRecord index = getIndexRecord(L);
    Map<Value, Set<Identifier>> data = index.getAll(timestamp);
    return Transformers.transformTreeMapSet(data, Value::getTObject, Identifier::longValue, TObjectSorter.INSTANCE);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 25 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method search.

@Override
public Set<Long> search(String key, String query) {
    // NOTE: Locking must happen here since CorpusRecords are not cached and
    // search potentially works across multiple ones.
    masterLock.readLock().lock();
    try {
        Text L = Text.wrapCached(key);
        // Get each word in the query separately to ensure that multi word
        // search works.
        String[] words = query.toString().toLowerCase().split(TStrings.REGEX_GROUP_OF_ONE_OR_MORE_WHITESPACE_CHARS);
        Multimap<Identifier, Integer> reference = ImmutableMultimap.of();
        boolean initial = true;
        int offset = 0;
        for (String word : words) {
            if (GlobalState.STOPWORDS.contains(word)) {
                // When skipping a stop word, we must record an offset to
                // correctly determine if the next term match is in the
                // correct relative position to the previous term match
                ++offset;
                continue;
            }
            Text K = Text.wrap(word);
            CorpusRecord corpus = getCorpusRecord(L, K);
            Set<Position> appearances = corpus.get(K);
            Multimap<Identifier, Integer> temp = HashMultimap.create();
            for (Position appearance : appearances) {
                Identifier record = appearance.getIdentifier();
                int position = appearance.getIndex();
                if (initial) {
                    temp.put(record, position);
                } else {
                    for (int current : reference.get(record)) {
                        if (position == current + 1 + offset) {
                            temp.put(record, position);
                        }
                    }
                }
            }
            initial = false;
            reference = temp;
            offset = 0;
        }
        // Result Scoring: Scoring is simply the number of times the query
        // appears in a Record [e.g. the number of Positions mapped from
        // key: #reference.get(key).size()]. The total number of positions
        // in #reference is equal to the total number of times a document
        // appears in the corpus [e.g. reference.asMap().values().size()].
        Multimap<Integer, Long> sorted = TreeMultimap.create(Collections.<Integer>reverseOrder(), Long::compareUnsigned);
        for (Entry<Identifier, Collection<Integer>> entry : reference.asMap().entrySet()) {
            sorted.put(entry.getValue().size(), entry.getKey().longValue());
        }
        Set<Long> results = (Set<Long>) sorted.values().stream().collect(Collectors.toCollection(LinkedHashSet::new));
        return results;
    } finally {
        masterLock.readLock().unlock();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Position(com.cinchapi.concourse.server.model.Position) Text(com.cinchapi.concourse.server.model.Text) Identifier(com.cinchapi.concourse.server.model.Identifier) Collection(java.util.Collection)

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)40 Text (com.cinchapi.concourse.server.model.Text)28 Value (com.cinchapi.concourse.server.model.Value)25 Test (org.junit.Test)18 Set (java.util.Set)13 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)9 LinkedHashSet (java.util.LinkedHashSet)7 ByteBuffer (java.nio.ByteBuffer)6 Path (java.nio.file.Path)6 Write (com.cinchapi.concourse.server.storage.temp.Write)4 List (java.util.List)4 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 Position (com.cinchapi.concourse.server.model.Position)3 Action (com.cinchapi.concourse.server.storage.Action)3 Range (com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Composite (com.cinchapi.concourse.server.io.Composite)2 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)2