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();
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations