[MRM-1043]

o moved the advanced search to the quick search page
o dynamically add search criteria
o added additional test in SearchAction


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@744080 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2009-02-13 11:25:47 +00:00
parent 7e85179685
commit 462af40d1e
7 changed files with 211 additions and 33 deletions

View File

@ -57,11 +57,11 @@ public class NexusIndexerConsumer
{
private static final Logger log = LoggerFactory.getLogger( NexusIndexerConsumer.class );
private final NexusIndexer indexer;
private NexusIndexer indexer;
private final ArtifactContextProducer artifactContextProducer;
private ArtifactContextProducer artifactContextProducer;
private final IndexPacker indexPacker;
private IndexPacker indexPacker;
private ManagedDefaultRepositoryContent repositoryContent;

View File

@ -425,4 +425,5 @@ public class NexusRepositorySearchTest
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
}
// TODO: add test when an existing index already exists
}

View File

@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -132,6 +133,8 @@ public class SearchAction
private RepositorySearch nexusSearch;
private Map<String, String> searchFields;
public boolean isFromResultsPage()
{
return fromResultsPage;
@ -161,12 +164,45 @@ public class SearchAction
{
managedRepositoryList.add( "all" );
}
searchFields = new HashMap<String, String>();
searchFields.put( "groupId", "Group ID" );
searchFields.put( "artifactId", "Artifact ID" );
searchFields.put( "version", "Version" );
searchFields.put( "className", "Class/Package Name" );
searchFields.put( "repositoryId", "Repository" );
super.clearErrorsAndMessages();
clearSearchFields();
}
private void clearSearchFields()
{
repositoryId = "";
artifactId = "";
groupId = "";
version = "";
className = "";
currentPage = 0;
}
// advanced search MRM-90 -- filtered search
public String filteredSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
{
// TODO:
// - repositories must be provided as a select box instead of as a textfield!
// - what about the row count?
// - remove advancedSearch.jsp
if ( ( groupId == null || "".equals( groupId ) ) &&
( artifactId == null || "".equals( artifactId ) ) && ( className == null || "".equals( className ) ) &&
( version == null || "".equals( version ) ) )
{
addActionError( "Advanced Search - At least one search criteria must be provided." );
return INPUT;
}
fromFilterSearch = true;
if ( CollectionUtils.isEmpty( managedRepositoryList ) )
@ -179,7 +215,8 @@ public class SearchAction
limits.setPageSize( rowCount );
List<String> selectedRepos = new ArrayList<String>();
if ( repositoryId.equals( "all" ) )
if ( repositoryId == null || StringUtils.isBlank( repositoryId ) ||
"all".equals( StringUtils.stripToEmpty( repositoryId ) ) )
{
selectedRepos = getObservableRepos();
}
@ -193,7 +230,8 @@ public class SearchAction
return GlobalResults.ACCESS_TO_NO_REPOS;
}
SearchFields searchFields = new SearchFields( groupId, artifactId, version, null, className, selectedRepos );
SearchFields searchFields =
new SearchFields( groupId, artifactId, version, null, className, selectedRepos );
// TODO: add packaging in the list of fields for advanced search (UI)?
try
@ -641,4 +679,14 @@ public class SearchAction
{
this.archivaXworkUser = archivaXworkUser;
}
public Map<String, String> getSearchFields()
{
return searchFields;
}
public void setSearchFields( Map<String, String> searchFields )
{
this.searchFields = searchFields;
}
}

View File

@ -147,7 +147,7 @@
</action>
<action name="filteredSearch" class="searchAction" method="filteredSearch">
<result name="input">/WEB-INF/jsp/advancedSearch.jsp</result>
<result name="input">/WEB-INF/jsp/quickSearch.jsp</result>
<result>/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
</action>

View File

@ -25,6 +25,35 @@
<head>
<title>Quick Search</title>
<s:head/>
<script type="text/javascript">
function addSearchField(fieldText, field, divName)
{
var element = document.getElementById( field );
if( element != null )
{
alert( "Cannot add field! Field has already been added." );
return 0;
}
var table = document.getElementById( "dynamicTable" );
var row = document.createElement( "TR" );
var label = document.createElement("TD");
label.innerHTML = fieldText + ": ";
var textfield = document.createElement( "TD" );
var inp1 = document.createElement( "INPUT" );
inp1.setAttribute( "type", "text" );
inp1.setAttribute( "size", "30" );
inp1.setAttribute( "id", field );
inp1.setAttribute( "name", field );
textfield.appendChild( inp1 );
row.appendChild( label );
row.appendChild( textfield );
table.appendChild( row );
}
</script>
<script type="text/javascript" src="<c:url value='/js/jquery/jquery-1.2.6.pack.js'/>"></script>
<script type="text/javascript">
$(document).ready(function(){
@ -36,6 +65,18 @@
});
});
</script>
<%-- advanced search --%>
<script type="text/javascript">
$(document).ready(function(){
$("table.settings-search").hide();
$("a.expand-search").click(function(event){
event.preventDefault();
$(this).next().toggle("slow");
});
});
</script>
</head>
<s:if test="%{infoMessage != null}">
@ -48,30 +89,23 @@
<div id="contentArea">
<div id="searchBox">
<s:form method="get" action="quickSearch" validate="true">
<c:url var="iconCreateUrl" value="/images/icons/create.png" />
<s:form method="get" id="quickSearch" action="quickSearch" validate="true">
<s:textfield label="Search for" size="50" name="q"/>
<s:hidden name="completeQueryString" value="%{completeQueryString}"/>
<s:submit value="Search"/>
</s:form>
<s:url id="filteredSearchUrl" action="advancedSearch"/>
<s:a href="%{filteredSearchUrl}">
Advanced Search >>
</s:a>
<p>
<s:actionerror/>
</p>
</div>
<div id="searchHint">
<div id="searchHint">
Enter your search terms. A variety of data will be searched for your keywords. <a class="expand" href="#"><img src="<c:url value="/images/icon_info_sml.gif"/>" /></a>
<table class="settings">
<tr>
<td>
<b>*</b> To search for Java classes or packages, just type the class name or package name in the search box.<br/>
</td>
</tr>
<tr>
<td>
<b>*</b> To perform a boolean <code>NOT</code> search, use the keyword <code>NOT</code> after your search
@ -80,6 +114,28 @@
<code>myQueryTerm NOT dependency</code>
</td>
</tr>
<tr>
<td>
<b>*</b> To do a filtered or advanced search, select the criteria from the list below and click the <img src="${iconCreateUrl}"/> icon. Specify the term you want to be matched in the created text field.
</td>
</tr>
<tr>
<td>
<s:form id="filteredSearch" method="get" action="filteredSearch" validate="true">
<label><strong>Advanced Search Fields: </strong></label><s:select name="searchField" list="searchFields" theme="simple"/>
<s:a href="#" title="Add Search Field" onclick="addSearchField( document.filteredSearch.searchField.options[document.filteredSearch.searchField.selectedIndex].text, document.filteredSearch.searchField.value, 'dynamicFields' )" theme="simple">
<img src="${iconCreateUrl}" />
</s:a>
<table id="dynamicTable">
<tr>
<td/>
<td/>
</tr>
</table>
<s:submit value="Search" theme="simple"/>
</s:form>
</td>
</tr>
</table>
</div>

View File

@ -26,10 +26,40 @@
<head>
<title>Search Results</title>
<s:head/>
<script type="text/javascript">
function addSearchField(fieldText, field, divName)
{
var element = document.getElementById( field );
if( element != null )
{
alert( "Cannot add field! Field has already been added." );
return 0;
}
var table = document.getElementById( "dynamicTable" );
var row = document.createElement( "TR" );
var label = document.createElement("TD");
label.innerHTML = fieldText + ": ";
var textfield = document.createElement( "TD" );
var inp1 = document.createElement( "INPUT" );
inp1.setAttribute( "type", "text" );
inp1.setAttribute( "size", "30" );
inp1.setAttribute( "id", field );
inp1.setAttribute( "name", field );
textfield.appendChild( inp1 );
row.appendChild( label );
row.appendChild( textfield );
table.appendChild( row );
}
</script>
</head>
<body>
<c:url var="iconCreateUrl" value="/images/icons/create.png" />
<c:if test="${fromFilterSearch == true}">
<h1>Advanced Search</h1>
</c:if>
@ -46,6 +76,33 @@
<div id="searchBoxResults">
<c:if test="${fromFilterSearch == true}">
<table>
<tr>
<td>
<b>*</b> To do a filtered or advanced search, select the criteria from the list below and click the <img src="${iconCreateUrl}"/> icon. Specify the term you want to be matched in the created text field.
</td>
</tr>
<tr>
<td>
<s:form id="filteredSearch" method="get" action="filteredSearch" validate="true">
<s:hidden name="fromFilterSearch" value="%{#attr.fromFilterSearch}" theme="simple"/>
<label><strong>Advanced Search Fields: </strong></label><s:select name="searchField" list="searchFields" theme="simple"/>
<s:a href="#" title="Add Search Field" onclick="addSearchField( document.filteredSearch.searchField.options[document.filteredSearch.searchField.selectedIndex].text, document.filteredSearch.searchField.value, 'dynamicFields' )" theme="simple">
<img src="${iconCreateUrl}" />
</s:a>
<table id="dynamicTable">
<tr>
<td/>
<td/>
</tr>
</table>
<s:submit value="Search" theme="simple"/>
</s:form>
</td>
</tr>
</table>
<%--
<s:form method="get" action="filteredSearch" validate="true">
<s:textfield label="Row Count" size="50" name="rowCount"/>
<s:textfield label="Group Id" size="50" name="groupId"/>
@ -65,6 +122,7 @@
<script type="text/javascript">
document.getElementById("filteredSearch_groupId").focus();
</script>
--%>
</c:if>
<c:if test="${fromFilterSearch == false}">
<s:form method="get" action="quickSearch" validate="true">
@ -81,7 +139,6 @@
<p>
<s:actionerror/>
</p>
</div>
<h1>Results</h1>

View File

@ -451,6 +451,7 @@ public class SearchActionTest
{
List<String> managedRepos = new ArrayList<String>();
action.setGroupId( "org.apache.archiva" );
action.setManagedRepositoryList( managedRepos );
String result = action.filteredSearch();
@ -458,6 +459,21 @@ public class SearchActionTest
assertEquals( GlobalResults.ACCESS_TO_NO_REPOS, result );
}
public void testAdvancedSearchNoSpecifiedCriteria()
throws Exception
{
List<String> managedRepos = new ArrayList<String>();
action.setManagedRepositoryList( managedRepos );
String result = action.filteredSearch();
assertEquals( Action.INPUT, result );
assertFalse( action.getActionErrors().isEmpty() );
assertEquals( "Advanced Search - At least one search criteria must be provided.",
(String) action.getActionErrors().iterator().next() );
}
// find artifact..
public void testFindArtifactWithOneHit()