Skip to content

Commit

Permalink
add scored queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis95 committed Sep 27, 2017
1 parent 73e83a6 commit 1e69e40
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
51 changes: 51 additions & 0 deletions lumongo-client/src/main/java/org/lumongo/client/command/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Query extends SimpleCommand<QueryRequest, QueryResult> {
private List<FieldSort> fieldSorts = Collections.emptyList();
private Set<String> queryFields = Collections.emptySet();
private List<Lumongo.Query> filterQueries = Collections.emptyList();
private List<Lumongo.Query> scoredQueries = Collections.emptyList();
private List<HighlightRequest> highlightRequests = Collections.emptyList();
private List<AnalysisRequest> analysisRequests = Collections.emptyList();
private Integer minimumNumberShouldMatch;
Expand Down Expand Up @@ -280,6 +281,52 @@ public Query addFilterQuery(String query, Collection<String> queryFields, Operat
return this;
}

public List<Lumongo.Query> getScoredQueries() {
return scoredQueries;
}

public void setScoredQueries(List<Lumongo.Query> scoredQueries) {
this.scoredQueries = scoredQueries;
}

public Query addScoredQuery(String query) {
return addScoredQuery(query, null, null, null);
}

public Query addScoredQuery(String query, Collection<String> queryFields) {
return addScoredQuery(query, queryFields, null, null);
}

public Query addScoredQuery(String query, Collection<String> queryFields, Operator defaultOperator) {
return addScoredQuery(query, queryFields, defaultOperator, null);
}

public Query addScoredQuery(String query, Collection<String> queryFields, Integer minimumNumberShouldMatch) {
return addScoredQuery(query, queryFields, null, minimumNumberShouldMatch);
}

public Query addScoredQuery(String query, Collection<String> queryFields, Operator defaultOperator, Integer minimumNumberShouldMatch) {
if (scoredQueries.isEmpty()) {
this.scoredQueries = new ArrayList<>();
}

Lumongo.Query.Builder builder = Lumongo.Query.newBuilder();
if (query != null && !query.isEmpty()) {
builder.setQ(query);
}
if (minimumNumberShouldMatch != null) {
builder.setMm(minimumNumberShouldMatch);
}
if (defaultOperator != null) {
builder.setDefaultOp(defaultOperator);
}
if (queryFields != null && !queryFields.isEmpty()) {
builder.addAllQf(queryFields);
}
scoredQueries.add(builder.build());
return this;
}

public Query addHighlight(String field) {
return addHighlight(field, null, null, null);
}
Expand Down Expand Up @@ -508,6 +555,10 @@ public QueryRequest getRequest() {
requestBuilder.addAllFilterQuery(filterQueries);
}

if (!scoredQueries.isEmpty()) {
requestBuilder.addAllScoredQuery(scoredQueries);
}

if (!highlightRequests.isEmpty()) {
requestBuilder.addAllHighlightRequest(highlightRequests);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ public void openConnections(Set<Member> members) throws Exception {

}

public IndexSettingsResponse updateIndex(String indexName, org.lumongo.cluster.message.LumongoIndex.IndexSettings request) throws InvalidIndexConfig, MongoException, IOException {
public IndexSettingsResponse updateIndex(String indexName, org.lumongo.cluster.message.LumongoIndex.IndexSettings request)
throws InvalidIndexConfig, MongoException, IOException {
globalLock.readLock().lock();
try {
log.info("Updating index settings for <" + indexName + ">:\n" + JsonFormat.printer().print(request));
Expand Down Expand Up @@ -650,15 +651,12 @@ private Map<String, QueryWithFilters> getQueryMap(QueryRequest queryRequest) thr
queryWithFilters.addSimilarityOverride(fieldSimilarity);
}



if (queryRequest.hasFacetRequest()) {
FacetRequest facetRequest = queryRequest.getFacetRequest();

List<LMFacet> drillDownList = facetRequest.getDrillDownList();
if (!drillDownList.isEmpty()) {


Map<String, Set<String>> dimToValues = new HashMap<>();
for (LMFacet drillDown : drillDownList) {
String key = drillDown.getLabel();
Expand Down Expand Up @@ -688,6 +686,10 @@ private Map<String, QueryWithFilters> getQueryMap(QueryRequest queryRequest) thr
queryWithFilters.addFilterQuery(i.getQuery(filterQuery));
}

for (Lumongo.Query filterQuery : queryRequest.getScoredQueryList()) {
queryWithFilters.addScoredFilterQuery(i.getQuery(filterQuery));
}

for (CosineSimRequest cosineSimRequest : queryRequest.getCosineSimRequestList()) {
i.handleCosineSimQuery(queryWithFilters, cosineSimRequest);
}
Expand Down Expand Up @@ -1151,7 +1153,6 @@ public void getAssociatedDocuments(String indexName, OutputStream outputStream,
}
}


//rest
public InputStream getAssociatedDocumentStream(String indexName, String uniqueId, String fileName) throws IOException {
globalLock.readLock().lock();
Expand Down
1 change: 1 addition & 0 deletions lumongo-common/src/main/proto/lumongo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ message QueryRequest {
optional bool debug = 16 [default = false];
repeated CosineSimRequest cosineSimRequest = 17;
optional bool dontCache = 18 [default = false];
repeated Query scoredQuery = 19;
}

message CosineSimRequest {
Expand Down

0 comments on commit 1e69e40

Please sign in to comment.