aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2012-07-23 16:27:42 (EDT)
committerMichael Fiedler2012-08-01 16:31:26 (EDT)
commit7c85286016f0996d7af1c41469d335aff7af367f (patch)
tree629e6338a7e36699b5cb96d75a5705b888b4678b
parenta10b2889dcc3d6072a65f685258733f0de3d149e (diff)
downloadorg.eclipse.lyo.docs-7c85286016f0996d7af1c41469d335aff7af367f.zip
org.eclipse.lyo.docs-7c85286016f0996d7af1c41469d335aff7af367f.tar.gz
org.eclipse.lyo.docs-7c85286016f0996d7af1c41469d335aff7af367f.tar.bz2
Bug 384760: Implement Use of oslc.searchTermsrefs/changes/28/6928/2
Change-Id: I3997ffe3d785f71757c24b0a9754694d1f4d5880 Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java61
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java31
2 files changed, 73 insertions, 19 deletions
diff --git a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
index c8706f8..096ddf1 100644
--- a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
+++ b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
@@ -41,6 +41,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
+import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -111,6 +112,8 @@ public class BugzillaManager implements ServletContextListener {
private static final String BUGZ_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss Z";
private static final String HOST = getHost();
+
+ private static QName OSLC_SCORE = new QName(OslcConstants.OSLC_CORE_NAMESPACE, "score");
//Bugzilla adapter properties from bugz.properties
static {
@@ -226,6 +229,7 @@ public class BugzillaManager implements ServletContextListener {
* @param prefixMap
* @param propMap
* @param orderBy
+ * @param searchTerms
*
* @return The list of change requests, paged if necessary
*
@@ -240,7 +244,8 @@ public class BugzillaManager implements ServletContextListener {
String oslcWhere,
Map<String, String> prefixMap,
Map<String, Object> propMap,
- String orderBy) throws IOException, ServletException
+ String orderBy,
+ String searchTerms) throws IOException, ServletException
{
List<BugzillaChangeRequest> results=new ArrayList<BugzillaChangeRequest>();
@@ -255,8 +260,29 @@ public class BugzillaManager implements ServletContextListener {
httpServletRequest, productIdString);
StringBuffer buffer = new StringBuffer();
- buffer.append(QUERY_PREFIX);
-
+ boolean fulltextSearch = searchTerms != null &&
+ searchTerms.length() != 0;
+
+ buffer.append(QUERY_PREFIX);
+
+ if (fulltextSearch) {
+
+ buffer.append(",relevance&content=");
+
+ boolean first = true;
+
+ for (String searchTerm : QueryUtils.parseSearchTerms(searchTerms)) {
+
+ if (first) {
+ first = false;
+ } else {
+ buffer.append('+');
+ }
+
+ buffer.append(URLEncoder.encode('"' + searchTerm + '"', "UTF-8"));
+ }
+ }
+
createBugSearch(page, limit, serviceProvider, oslcWhere, prefixMap, buffer);
if (orderBy != null && orderBy.length() != 0) {
@@ -266,7 +292,15 @@ public class BugzillaManager implements ServletContextListener {
buffer.append("&order=");
- addSort(buffer, orderByClause, toplevelQueryProperties, true);
+ if (fulltextSearch) {
+ buffer.append("relevance+DESC");
+ }
+
+ addSort(buffer, orderByClause, toplevelQueryProperties, ! fulltextSearch);
+
+ } else if (fulltextSearch) {
+
+ buffer.append("&order=relevance+DESC");
}
Credentials credentials = (Credentials)httpServletRequest.getSession().getAttribute(CredentialsFilter.CREDENTIALS_ATTRIBUTE);
@@ -289,7 +323,8 @@ public class BugzillaManager implements ServletContextListener {
Element p = (Element)list.item(idx);
- BugzillaChangeRequest changeRequest = createChangeRequest(p);
+ BugzillaChangeRequest changeRequest =
+ createChangeRequest(p, fulltextSearch);
if (propMap instanceof SingletonWildcardProperties ||
propMap.get(OslcConstants.DCTERMS_NAMESPACE + "created") != null ||
@@ -362,7 +397,7 @@ public class BugzillaManager implements ServletContextListener {
}
}
- private static BugzillaChangeRequest createChangeRequest(Element bug) throws IOException, URISyntaxException
+ private static BugzillaChangeRequest createChangeRequest(Element bug, boolean fulltextSearch) throws IOException, URISyntaxException
{
BugzillaChangeRequest changeRequest = new BugzillaChangeRequest();
@@ -389,6 +424,20 @@ public class BugzillaManager implements ServletContextListener {
changeRequest.setPlatform(elementText(bug, "rep_platform"));
changeRequest.setOperatingSystem(elementText(bug, "op_sys"));
+ if (fulltextSearch) {
+
+ String relevance = elementText(bug, "relevance");
+
+ if (relevance != null) {
+
+ Map<QName, Object> extProps = new HashMap<QName, Object>(1);
+
+ extProps.put(OSLC_SCORE, Float.valueOf(relevance));
+
+ changeRequest.setExtendedProperties(extProps);
+ }
+ }
+
return changeRequest;
}
diff --git a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
index 4d1c0e6..c53bade 100644
--- a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
+++ b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
@@ -124,18 +124,20 @@ public class BugzillaChangeRequestService
* @param prefix
* @param pageString
* @param orderBy
+ * @param searchTerms
* @return
* @throws IOException
* @throws ServletException
*/
@GET
@Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
- public List<BugzillaChangeRequest> getChangeRequests(@PathParam("productId") final String productId,
- @QueryParam("oslc.where") final String where,
- @QueryParam("oslc.select") final String select,
- @QueryParam("oslc.prefix") final String prefix,
- @QueryParam("page") final String pageString,
- @QueryParam("oslc.orderBy") final String orderBy) throws IOException, ServletException
+ public List<BugzillaChangeRequest> getChangeRequests(@PathParam("productId") final String productId,
+ @QueryParam("oslc.where") final String where,
+ @QueryParam("oslc.select") final String select,
+ @QueryParam("oslc.prefix") final String prefix,
+ @QueryParam("page") final String pageString,
+ @QueryParam("oslc.orderBy") final String orderBy,
+ @QueryParam("oslc.searchTerms") final String searchTerms) throws IOException, ServletException
{
int page=0;
@@ -172,7 +174,7 @@ public class BugzillaChangeRequestService
final List<BugzillaChangeRequest> results =
BugzillaManager.getBugsByProduct(httpServletRequest, productId, page, limit,
where, prefixMap,
- propMap, orderBy);
+ propMap, orderBy, searchTerms);
httpServletRequest.setAttribute(OSLC4JConstants.OSLC4J_SELECTED_PROPERTIES,
propMap);
@@ -233,17 +235,19 @@ public class BugzillaChangeRequestService
* @param prefix
* @param pageString
* @param orderBy
+ * @param searchTerms
* @return
* @throws ServletException
* @throws IOException
*/
@GET
@Produces({ MediaType.TEXT_HTML })
- public Response getHtmlCollection(@PathParam("productId") final String productId,
- @QueryParam("oslc.where") final String where,
- @QueryParam("oslc.prefix") final String prefix,
- @QueryParam("page") final String pageString,
- @QueryParam("oslc.orderBy") final String orderBy) throws ServletException, IOException
+ public Response getHtmlCollection(@PathParam("productId") final String productId,
+ @QueryParam("oslc.where") final String where,
+ @QueryParam("oslc.prefix") final String prefix,
+ @QueryParam("page") final String pageString,
+ @QueryParam("oslc.orderBy") final String orderBy,
+ @QueryParam("oslc.searchTerms") final String searchTerms) throws ServletException, IOException
{
int page=0;
@@ -276,7 +280,8 @@ public class BugzillaChangeRequestService
final List<BugzillaChangeRequest> results =
BugzillaManager.getBugsByProduct(httpServletRequest, productId, page, limit,
- where, prefixMap, propMap, orderBy);
+ where, prefixMap, propMap, orderBy,
+ searchTerms);
if (results != null) {
final String bugzillaUri = BugzillaManager.getBugzillaUri().toString();