com.jaeksoft.searchlib.webservice.query.document.DocumentResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearchserver Show documentation
Show all versions of opensearchserver Show documentation
OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.
The newest version!
/**
* License Agreement for OpenSearchServer
*
* Copyright (C) 2011-2014 Emmanuel Keller / Jaeksoft
*
* http://www.open-search-server.com
*
* This file is part of OpenSearchServer.
*
* OpenSearchServer is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSearchServer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSearchServer.
* If not, see .
**/
package com.jaeksoft.searchlib.webservice.query.document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.jaeksoft.searchlib.SearchLibException;
import com.jaeksoft.searchlib.result.AbstractResultSearch;
import com.jaeksoft.searchlib.result.ResultDocument;
import com.jaeksoft.searchlib.result.ResultDocumentsInterface;
import com.jaeksoft.searchlib.schema.FieldValue;
import com.jaeksoft.searchlib.snippet.SnippetFieldValue;
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@JsonInclude(Include.NON_NULL)
public class DocumentResult {
@XmlAttribute
public final Integer pos;
@XmlAttribute
public final Float score;
@XmlAttribute
public final Float distance;
@XmlAttribute
public final Integer collapseCount;
@XmlAttribute
public final String joinParameter;
@XmlElement(name = "field")
public final List fields;
@XmlElement(name = "snippet")
public final List snippets;
@XmlElement(name = "function")
public final List functions;
@XmlElement(name = "position")
public final List positions;
@XmlElement(name = "join")
public final List joins;
@XmlElement(name = "collapsed")
public final List collapsedDocs;
public static class Position {
public final int start;
public final int end;
public Position() {
start = 0;
end = 0;
}
public Position(int start, int end) {
this.start = start;
this.end = end;
}
public Position(OffsetAttribute offsetAtt) {
this.start = offsetAtt.startOffset();
this.end = offsetAtt.endOffset();
}
}
public DocumentResult() {
fields = null;
snippets = null;
functions = null;
positions = null;
collapseCount = null;
pos = null;
score = null;
distance = null;
joins = null;
joinParameter = null;
collapsedDocs = null;
}
public DocumentResult(ResultDocument resultDocument, Integer collapseDocCount, Integer position, Float docScore,
Float docDistance, List joinResultDocuments, List collapsedDocuments) {
Map returnFields = resultDocument.getReturnFields();
fields = MapUtils.isEmpty(returnFields) ? null : new ArrayList(returnFields.size());
if (returnFields != null)
for (FieldValue fiedValue : returnFields.values())
fields.add(new FieldValueList(fiedValue));
Map snippetFields = resultDocument.getSnippetFields();
snippets = MapUtils.isEmpty(snippetFields) ? null : new ArrayList(snippetFields.size());
if (snippetFields != null)
for (SnippetFieldValue snippetFiedValue : snippetFields.values())
snippets.add(new SnippetValueList(snippetFiedValue));
this.joinParameter = resultDocument.getJoinParameter();
joins = CollectionUtils.isEmpty(joinResultDocuments) ? null
: new ArrayList(joinResultDocuments.size());
if (joinResultDocuments != null) {
for (ResultDocument joinResultDocument : joinResultDocuments)
joins.add(new DocumentResult(joinResultDocument, null, null, null, null, null, null));
}
collapsedDocs = CollectionUtils.isEmpty(collapsedDocuments) ? null
: new ArrayList(collapsedDocuments.size());
if (collapsedDocuments != null) {
for (ResultDocument collapsedDocument : collapsedDocuments)
collapsedDocs.add(new DocumentResult(collapsedDocument, null, null, null, null, null, null));
}
functions = resultDocument.getFunctionFieldValues();
positions = resultDocument.getPositions();
collapseCount = collapseDocCount;
pos = position;
score = docScore;
distance = docDistance;
}
public final static List populateDocumentList(ResultDocumentsInterface> result,
List documents) throws SearchLibException {
int start = result.getRequestStart();
int end = result.getDocumentCount() + result.getRequestStart();
AbstractResultSearch> resultSearch = result instanceof AbstractResultSearch ? (AbstractResultSearch>) result
: null;
for (int i = start; i < end; i++) {
ResultDocument resultDocument = result.getDocument(i, null);
int collapseDocCount = result.getCollapseCount(i);
float docScore = result.getScore(i);
Float docDistance = result.getDistance(i);
List joinResultDocuments = resultSearch == null ? null
: resultSearch.getJoinDocumentList(i, null);
DocumentResult documentResult = new DocumentResult(resultDocument, collapseDocCount, i, docScore,
docDistance, joinResultDocuments, resultDocument.getCollapsedDocuments());
documents.add(documentResult);
}
return documents;
}
}