fix search query

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294405 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-02-28 00:03:26 +00:00
parent 202a699884
commit 7c71fde835
3 changed files with 47 additions and 17 deletions

View File

@ -56,7 +56,7 @@ public interface SearchService
List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString ) List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path( "quickSearch" ) @Path( "quickSearchWithRepositories" )
@POST @POST
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noPermission = true, noRestriction = true ) @RedbackAuthorization( noPermission = true, noRestriction = true )

View File

@ -598,6 +598,9 @@ $(function() {
} }
SearchRequest=function(){ SearchRequest=function(){
this.queryTerms=ko.observable();
//private String groupId; //private String groupId;
this.groupId=ko.observable(); this.groupId=ko.observable();
@ -614,7 +617,7 @@ $(function() {
this.className=ko.observable(); this.className=ko.observable();
//private List<String> repositories = new ArrayList<String>(); //private List<String> repositories = new ArrayList<String>();
this.repositories=ko.observableArray(); this.repositories=ko.observableArray([]);
//private String bundleVersion; //private String bundleVersion;
this.bundleVersion=ko.observable(); this.bundleVersion=ko.observable();
@ -635,21 +638,20 @@ $(function() {
this.includePomArtifacts=ko.observable(false); this.includePomArtifacts=ko.observable(false);
} }
ResultViewModel=function(artifacts){
SearchParameters=function(){ this.artifacts=artifacts;
this.basicQueryString=ko.observable();
this.searchRequest=ko.observable(new SearchRequest());
} }
SearchViewModel=function(){ SearchViewModel=function(){
this.searchParameters=ko.observable(new SearchParameters()); this.searchRequest=ko.observable(new SearchRequest());
this.observableRepoIds=ko.observableArray([]); this.observableRepoIds=ko.observableArray([]);
this.selectedRepoIds=[]; this.selectedRepoIds=[];
basicSearch=function(){ basicSearch=function(){
//$.log("query:"+this.searchParameters().basicQueryString()); //$.log("query:"+this.searchParameters().basicQueryString());
//$.log("repoIds:"+this.selectedRepoIds); //$.log("repoIds:"+this.selectedRepoIds);
var queryTerm=this.searchParameters().basicQueryString(); var queryTerm=this.searchRequest().queryTerms();
if (!queryTerm || $.trim(queryTerm).length<1){ if (!queryTerm || $.trim(queryTerm).length<1){
$.log("empty"); $.log("empty");
var errorList=[{ var errorList=[{
@ -662,8 +664,28 @@ $(function() {
// cleanup previours error message // cleanup previours error message
customShowError("#main-content #search-basic-form", null, null, []); customShowError("#main-content #search-basic-form", null, null, []);
} }
$("#main-content #search-results" ).html(mediumSpinnerImg()); var searchResults=$("#main-content #search-results" );
activateSearchResultsTab(); searchResults.html(mediumSpinnerImg());
this.searchRequest().repositories=this.selectedRepoIds;
$.ajax("restServices/archivaServices/searchService/quickSearchWithRepositories",
{
type: "POST",
data: "{\"searchRequest\": " + ko.toJSON(this.searchRequest)+"}",
contentType: 'application/json',
dataType: 'json',
success: function(data) {
var resultViewModel=new ResultViewModel(mapArtifacts(data));
searchResults.attr("data-bind","template:{name:'search-results-view-tmpl'}");
ko.applyBindings(resultViewModel,searchResults.get(0));
activateSearchResultsTab();
},
error: function(data) {
var res = $.parseJSON(data.responseText);
displayRestError(res);
}
}
);
} }

View File

@ -198,7 +198,7 @@
<label class="control-label" for="search-terms"></label> <label class="control-label" for="search-terms"></label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="search-terms" name="search-terms" size="50" <input type="text" class="input-medium search-query" id="search-terms" name="search-terms" size="50"
data-bind="value: searchParameters().basicQueryString" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/> data-bind="value: searchRequest().queryTerms" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
</div> </div>
</div> </div>
<button type="submit" class="btn" data-bind="click: basicSearch">Search</button> <button type="submit" class="btn" data-bind="click: basicSearch">Search</button>
@ -211,35 +211,35 @@
<label class="control-label" for="groupId">${$.i18n.prop('search.artifact.search.form.query.groupId')}</label> <label class="control-label" for="groupId">${$.i18n.prop('search.artifact.search.form.query.groupId')}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="groupId" name="groupId" size="50" <input type="text" class="input-medium search-query" id="groupId" name="groupId" size="50"
data-bind="value: searchParameters().searchRequest().groupId"/> data-bind="value: searchRequest().groupId"/>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.artifactId')}</label> <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.artifactId')}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="artifactId" name="artifactId" size="50" <input type="text" class="input-medium search-query" id="artifactId" name="artifactId" size="50"
data-bind="value: searchParameters().searchRequest().artifactId"/> data-bind="value: searchRequest().artifactId"/>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.version')}</label> <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.version')}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="version" name="version" size="50" <input type="text" class="input-medium search-query" id="version" name="version" size="50"
data-bind="value: searchParameters().searchRequest().version"/> data-bind="value: searchRequest().version"/>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.packaging')}</label> <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.packaging')}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="packaging" name="packaging" size="50" <input type="text" class="input-medium search-query" id="packaging" name="packaging" size="50"
data-bind="value: searchParameters().searchRequest().packaging"/> data-bind="value: searchRequest().packaging"/>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.className')}</label> <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.className')}</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-medium search-query" id="className" name="className" size="50" <input type="text" class="input-medium search-query" id="className" name="className" size="50"
data-bind="value: searchParameters().searchRequest().className"/> data-bind="value: searchRequest().className"/>
</div> </div>
</div> </div>
</fieldset> </fieldset>
@ -262,4 +262,12 @@
</div> </div>
</div> </div>
</script> </script>
<script id="search-results-view-tmpl" type="text/html">
{{if artifacts.length==0}}
no results
{{else}}
results
{{/if}}
</script>