2015-02-23 00:42:36 -05:00
|
|
|
/*
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
solrAdminApp.controller('QueryController',
|
2015-08-29 07:28:36 -04:00
|
|
|
function($scope, $routeParams, $location, Query, Constants){
|
|
|
|
$scope.resetMenu("query", Constants.IS_COLLECTION_PAGE);
|
2015-02-23 00:42:36 -05:00
|
|
|
|
|
|
|
// @todo read URL parameters into scope
|
2017-07-24 11:42:02 -04:00
|
|
|
$scope.query = {q:'*:*'};
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.filters = [{fq:""}];
|
|
|
|
$scope.dismax = {defType: "dismax"};
|
2017-06-20 07:39:36 -04:00
|
|
|
$scope.edismax = {defType: "edismax", stopwords: true, lowercaseOperators: false};
|
2015-09-18 06:22:33 -04:00
|
|
|
$scope.hl = {hl:"on"};
|
|
|
|
$scope.facet = {facet: "on"};
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.spatial = {};
|
2015-09-18 06:22:33 -04:00
|
|
|
$scope.spellcheck = {spellcheck:"on"};
|
2019-07-20 01:11:57 -04:00
|
|
|
$scope.debugQuery = {debugQuery: "on"};
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.qt = "/select";
|
|
|
|
|
2015-07-06 06:07:08 -04:00
|
|
|
$scope.doQuery = function() {
|
|
|
|
var params = {};
|
|
|
|
|
|
|
|
var set = function(key, value) {
|
|
|
|
if (params[key]) {
|
|
|
|
params[key].push(value);
|
|
|
|
} else {
|
|
|
|
params[key] = [value];
|
2015-02-23 00:42:36 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-06 06:07:08 -04:00
|
|
|
var copy = function(params, query) {
|
|
|
|
for (var key in query) {
|
|
|
|
terms = query[key];
|
2018-12-14 09:07:28 -05:00
|
|
|
// Booleans have no length property - only set them if true
|
|
|
|
if (((typeof(terms) == typeof(true) && terms) || terms.length > 0) && key[0]!="$") {
|
2015-07-06 06:07:08 -04:00
|
|
|
set(key, terms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-02-23 00:42:36 -05:00
|
|
|
|
|
|
|
copy(params, $scope.query);
|
|
|
|
|
|
|
|
if ($scope.isDismax) copy(params, $scope.dismax);
|
|
|
|
if ($scope.isEdismax) copy(params, $scope.edismax);
|
|
|
|
if ($scope.isHighlight) copy(params, $scope.hl);
|
|
|
|
if ($scope.isFacet) copy(params, $scope.facet);
|
|
|
|
if ($scope.isSpatial) copy(params, $scope.spatial);
|
|
|
|
if ($scope.isSpellcheck) copy(params, $scope.spellcheck);
|
2019-07-20 01:11:57 -04:00
|
|
|
if ($scope.isDebugQuery) copy(params, $scope.debugQuery);
|
2015-02-23 00:42:36 -05:00
|
|
|
|
|
|
|
if ($scope.rawParams) {
|
2015-10-20 22:57:17 -04:00
|
|
|
var rawParams = $scope.rawParams.split(/[&\n]/);
|
|
|
|
for (var i in rawParams) {
|
2016-07-26 20:02:00 -04:00
|
|
|
var param = rawParams[i];
|
|
|
|
var equalPos = param.indexOf("=");
|
|
|
|
if (equalPos > -1) {
|
|
|
|
set(param.substring(0, equalPos), param.substring(equalPos+1));
|
|
|
|
} else {
|
|
|
|
set(param, ""); // Use empty value for params without "="
|
|
|
|
}
|
2015-02-23 00:42:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:31:40 -04:00
|
|
|
var qt = $scope.qt ? $scope.qt : "/select";
|
2015-02-23 00:42:36 -05:00
|
|
|
|
|
|
|
for (var filter in $scope.filters) {
|
|
|
|
copy(params, $scope.filters[filter]);
|
|
|
|
}
|
|
|
|
|
2015-07-06 06:07:08 -04:00
|
|
|
params.core = $routeParams.core;
|
2016-03-28 18:31:40 -04:00
|
|
|
if (qt[0] == '/') {
|
|
|
|
params.handler = qt.substring(1);
|
|
|
|
} else { // Support legacy style handleSelect=true configs
|
|
|
|
params.handler = "select";
|
|
|
|
set("qt", qt);
|
|
|
|
}
|
2015-09-16 06:13:45 -04:00
|
|
|
var url = Query.url(params);
|
2015-07-06 06:07:08 -04:00
|
|
|
Query.query(params, function(data) {
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.lang = $scope.query.wt;
|
2017-07-24 11:42:02 -04:00
|
|
|
if ($scope.lang == undefined || $scope.lang == '') {
|
|
|
|
$scope.lang = "json";
|
|
|
|
}
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.response = data;
|
2017-02-17 04:45:10 -05:00
|
|
|
// Use relative URL to make it also work through proxies that may have a different host/port/context
|
|
|
|
$scope.url = url;
|
|
|
|
$scope.hostPortContext = $location.absUrl().substr(0,$location.absUrl().indexOf("#")); // For display only
|
2015-02-23 00:42:36 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-11-04 06:53:43 -05:00
|
|
|
if ($location.search().q) {
|
|
|
|
$scope.query.q = $location.search()["q"];
|
|
|
|
$scope.doQuery();
|
|
|
|
}
|
|
|
|
|
2015-02-23 00:42:36 -05:00
|
|
|
$scope.removeFilter = function(index) {
|
|
|
|
if ($scope.filters.length === 1) {
|
|
|
|
$scope.filters = [{fq: ""}];
|
|
|
|
} else {
|
|
|
|
$scope.filters.splice(index, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addFilter = function(index) {
|
|
|
|
$scope.filters.splice(index+1, 0, {fq:""});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|