mirror of https://github.com/apache/archiva.git
[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:
parent
7e85179685
commit
462af40d1e
|
@ -57,11 +57,11 @@ public class NexusIndexerConsumer
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger( NexusIndexerConsumer.class );
|
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;
|
private ManagedDefaultRepositoryContent repositoryContent;
|
||||||
|
|
||||||
|
|
|
@ -425,4 +425,5 @@ public class NexusRepositorySearchTest
|
||||||
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add test when an existing index already exists
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
*
|
*
|
||||||
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="searchAction"
|
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="searchAction"
|
||||||
*/
|
*/
|
||||||
public class SearchAction
|
public class SearchAction
|
||||||
extends PlexusActionSupport
|
extends PlexusActionSupport
|
||||||
implements Preparable
|
implements Preparable
|
||||||
{
|
{
|
||||||
|
@ -131,6 +132,8 @@ public class SearchAction
|
||||||
private boolean fromResultsPage;
|
private boolean fromResultsPage;
|
||||||
|
|
||||||
private RepositorySearch nexusSearch;
|
private RepositorySearch nexusSearch;
|
||||||
|
|
||||||
|
private Map<String, String> searchFields;
|
||||||
|
|
||||||
public boolean isFromResultsPage()
|
public boolean isFromResultsPage()
|
||||||
{
|
{
|
||||||
|
@ -161,16 +164,49 @@ public class SearchAction
|
||||||
{
|
{
|
||||||
managedRepositoryList.add( "all" );
|
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
|
// advanced search MRM-90 -- filtered search
|
||||||
public String filteredSearch()
|
public String filteredSearch()
|
||||||
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
|
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;
|
fromFilterSearch = true;
|
||||||
|
|
||||||
if ( CollectionUtils.isEmpty( managedRepositoryList ) )
|
if ( CollectionUtils.isEmpty( managedRepositoryList ) )
|
||||||
{
|
{
|
||||||
return GlobalResults.ACCESS_TO_NO_REPOS;
|
return GlobalResults.ACCESS_TO_NO_REPOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,22 +214,24 @@ public class SearchAction
|
||||||
|
|
||||||
limits.setPageSize( rowCount );
|
limits.setPageSize( rowCount );
|
||||||
List<String> selectedRepos = new ArrayList<String>();
|
List<String> selectedRepos = new ArrayList<String>();
|
||||||
|
|
||||||
if ( repositoryId.equals( "all" ) )
|
if ( repositoryId == null || StringUtils.isBlank( repositoryId ) ||
|
||||||
|
"all".equals( StringUtils.stripToEmpty( repositoryId ) ) )
|
||||||
{
|
{
|
||||||
selectedRepos = getObservableRepos();
|
selectedRepos = getObservableRepos();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectedRepos.add( repositoryId );
|
selectedRepos.add( repositoryId );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( CollectionUtils.isEmpty( selectedRepos ) )
|
if ( CollectionUtils.isEmpty( selectedRepos ) )
|
||||||
{
|
{
|
||||||
return GlobalResults.ACCESS_TO_NO_REPOS;
|
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)?
|
// TODO: add packaging in the list of fields for advanced search (UI)?
|
||||||
try
|
try
|
||||||
|
@ -641,4 +679,14 @@ public class SearchAction
|
||||||
{
|
{
|
||||||
this.archivaXworkUser = archivaXworkUser;
|
this.archivaXworkUser = archivaXworkUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSearchFields()
|
||||||
|
{
|
||||||
|
return searchFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchFields( Map<String, String> searchFields )
|
||||||
|
{
|
||||||
|
this.searchFields = searchFields;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action name="filteredSearch" class="searchAction" method="filteredSearch">
|
<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>/WEB-INF/jsp/results.jsp</result>
|
||||||
<result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
|
<result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -25,6 +25,35 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Quick Search</title>
|
<title>Quick Search</title>
|
||||||
<s:head/>
|
<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" src="<c:url value='/js/jquery/jquery-1.2.6.pack.js'/>"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
@ -36,6 +65,18 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</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>
|
</head>
|
||||||
|
|
||||||
<s:if test="%{infoMessage != null}">
|
<s:if test="%{infoMessage != null}">
|
||||||
|
@ -48,30 +89,23 @@
|
||||||
|
|
||||||
<div id="contentArea">
|
<div id="contentArea">
|
||||||
<div id="searchBox">
|
<div id="searchBox">
|
||||||
<s:form method="get" 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>
|
|
||||||
|
|
||||||
|
<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>
|
||||||
<p>
|
<p>
|
||||||
<s:actionerror/>
|
<s:actionerror/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</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>
|
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">
|
<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>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<b>*</b> To perform a boolean <code>NOT</code> search, use the keyword <code>NOT</code> after your search
|
<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>
|
<code>myQueryTerm NOT dependency</code>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,10 +26,40 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Search Results</title>
|
<title>Search Results</title>
|
||||||
<s:head/>
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<c:url var="iconCreateUrl" value="/images/icons/create.png" />
|
||||||
|
|
||||||
<c:if test="${fromFilterSearch == true}">
|
<c:if test="${fromFilterSearch == true}">
|
||||||
<h1>Advanced Search</h1>
|
<h1>Advanced Search</h1>
|
||||||
</c:if>
|
</c:if>
|
||||||
|
@ -46,6 +76,33 @@
|
||||||
<div id="searchBoxResults">
|
<div id="searchBoxResults">
|
||||||
|
|
||||||
<c:if test="${fromFilterSearch == true}">
|
<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:form method="get" action="filteredSearch" validate="true">
|
||||||
<s:textfield label="Row Count" size="50" name="rowCount"/>
|
<s:textfield label="Row Count" size="50" name="rowCount"/>
|
||||||
<s:textfield label="Group Id" size="50" name="groupId"/>
|
<s:textfield label="Group Id" size="50" name="groupId"/>
|
||||||
|
@ -65,7 +122,8 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.getElementById("filteredSearch_groupId").focus();
|
document.getElementById("filteredSearch_groupId").focus();
|
||||||
</script>
|
</script>
|
||||||
</c:if>
|
--%>
|
||||||
|
</c:if>
|
||||||
<c:if test="${fromFilterSearch == false}">
|
<c:if test="${fromFilterSearch == false}">
|
||||||
<s:form method="get" action="quickSearch" validate="true">
|
<s:form method="get" action="quickSearch" validate="true">
|
||||||
<s:textfield label="Search for" size="50" name="q"/>
|
<s:textfield label="Search for" size="50" name="q"/>
|
||||||
|
@ -81,7 +139,6 @@
|
||||||
<p>
|
<p>
|
||||||
<s:actionerror/>
|
<s:actionerror/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1>Results</h1>
|
<h1>Results</h1>
|
||||||
|
@ -322,4 +379,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -451,6 +451,7 @@ public class SearchActionTest
|
||||||
{
|
{
|
||||||
List<String> managedRepos = new ArrayList<String>();
|
List<String> managedRepos = new ArrayList<String>();
|
||||||
|
|
||||||
|
action.setGroupId( "org.apache.archiva" );
|
||||||
action.setManagedRepositoryList( managedRepos );
|
action.setManagedRepositoryList( managedRepos );
|
||||||
|
|
||||||
String result = action.filteredSearch();
|
String result = action.filteredSearch();
|
||||||
|
@ -458,6 +459,21 @@ public class SearchActionTest
|
||||||
assertEquals( GlobalResults.ACCESS_TO_NO_REPOS, result );
|
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..
|
// find artifact..
|
||||||
|
|
||||||
public void testFindArtifactWithOneHit()
|
public void testFindArtifactWithOneHit()
|
||||||
|
|
Loading…
Reference in New Issue