use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.
the class SearchService method createNewsItem.
private Document createNewsItem(String _id, String _title, ZonedDateTime _created, int _ranking, String... _categories) {
Document document = newsItems.createDoc(_id);
document.setValue(title, _title);
document.setValue(created, _created);
document.setValues(category, Arrays.asList(_categories));
document.setValue(ranking, _ranking);
return document;
}
use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.
the class SearchService method index.
public boolean index() {
GuardianNewsIterator iterator = new GuardianNewsIterator(this.guardianApiKey);
while (iterator.hasNext()) {
for (GuardianNewsItem item : iterator.getNext()) {
Document document = newsItems.createDoc(item.getId());
document.setValue(title, item.getWebTitle());
document.setValue(publicationDate, item.getWebPublicationDate());
document.setValue(category, item.getSectionName());
document.setValue(kind, item.getType());
document.setValue(url, item.getWebUrl());
server.index(document);
}
server.commit();
}
return true;
}
use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.
the class SolrSearchServer method getUpdatedSolrDocument.
private SolrInputDocument getUpdatedSolrDocument(SolrInputDocument sdoc, SolrDocument updatedDoc, List<SolrInputDocument> nestedDocs) {
// TODO:find a better way - non deprecated way
// Create an input document from the original doc to be updated
final SolrInputDocument inputDoc = ClientUtils.toSolrInputDocument(updatedDoc);
// Add nested documents to the doc
inputDoc.addChildDocuments(nestedDocs);
// TODO: think about a cleaner solution
// Update the original document
sdoc.getFieldNames().stream().filter(// TODO: Add all the special fields or do the oposite check, whether it fits a dynamic Vind field
fn -> !fn.equals(ID) && !fn.equals(TYPE) && !fn.equals("_version_")).forEach(fn -> {
final ArrayList fieldOp = (ArrayList) sdoc.getFieldValues(fn);
fieldOp.stream().forEach(op -> {
final Set<String> keys = ((HashMap<String, String>) op).keySet();
keys.stream().forEach(k -> {
switch(UpdateOperations.valueOf(k)) {
case set:
inputDoc.setField(fn, ((HashMap<String, String>) op).get(k));
break;
case add:
inputDoc.addField(fn, ((HashMap<String, String>) op).get(k));
break;
case inc:
final Number fieldValue;
try {
fieldValue = NumberFormat.getInstance().parse((String) inputDoc.getFieldValue(fn));
} catch (ParseException e) {
throw new RuntimeException();
}
inputDoc.setField(fn, String.valueOf(fieldValue.floatValue() + 1));
break;
case remove:
inputDoc.removeField(fn);
break;
case removeregex:
final String fieldStringValue = (String) inputDoc.getFieldValue(fn);
final String regex = ((HashMap<String, String>) op).get(k);
if (regex.matches(fieldStringValue)) {
inputDoc.removeField(fn);
}
break;
}
});
});
});
return inputDoc;
}
use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.
the class SolrSearchServer method createInputDocument.
private SolrInputDocument createInputDocument(Document doc) {
final SolrInputDocument document = new SolrInputDocument();
// add fields
doc.listFieldDescriptors().values().stream().filter(doc::hasValue).forEach(descriptor -> doc.getFieldContexts(descriptor).stream().forEach(context -> Stream.of(UseCase.values()).forEach(useCase -> {
final String fieldname = getFieldname(descriptor, useCase, context);
if (Objects.nonNull(fieldname)) {
final Object value = doc.getContextualizedValue(descriptor, context);
final Object caseValue = SolrUtils.FieldValue.getFieldCaseValue(value, descriptor, useCase);
if (Objects.nonNull(caseValue)) {
document.addField(fieldname, toSolrJType(caseValue));
}
}
})));
// add subdocuments
if (doc.hasChildren()) {
doc.getChildren().forEach(childDocument -> document.addChildDocument(createInputDocument(childDocument)));
}
document.addField(ID, doc.getId());
document.addField(TYPE, doc.getType());
return document;
}
use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.
the class SolrSearchServer method execute.
@Override
public SearchResult execute(FulltextSearch search, DocumentFactory factory) {
final SolrQuery query = buildSolrQuery(search, factory);
// query
try {
solrClientLogger.debug(">>> query({})", query.toString());
final QueryResponse response = solrClient.query(query, SolrRequest.METHOD.POST);
if (response != null) {
final Map<String, Integer> childCounts = SolrUtils.getChildCounts(response);
final List<Document> documents = SolrUtils.Result.buildResultList(response.getResults(), childCounts, factory, search.getSearchContext());
final FacetResults facetResults = SolrUtils.Result.buildFacetResult(response, factory, search.getChildrenFactory(), search.getFacets(), search.getSearchContext());
switch(search.getResultSet().getType()) {
case page:
{
return new PageResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime());
}
case slice:
{
return new SliceResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime());
}
default:
return new PageResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime());
}
} else {
throw new SolrServerException("Null result from SolrClient");
}
} catch (SolrServerException | IOException e) {
throw new SearchServerException("Cannot issue query", e);
}
}
Aggregations