From 632934346563a32cdd8d1f6e05400372ce14b5a7 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 10:32:27 -0400 Subject: [PATCH 1/9] VIVO-742 Create the interfaces for Application and SearchEngine Also some stubs for unit tests. --- .../webapp/application/ApplicationUtils.java | 29 ++++ .../vitro/webapp/modules/Application.java | 35 +++++ .../modules/ComponentStartupStatus.java | 21 +++ .../modules/searchEngine/SearchEngine.java | 90 ++++++++++++ .../searchEngine/SearchEngineException.java | 26 ++++ .../searchEngine/SearchFacetField.java | 39 +++++ .../searchEngine/SearchInputDocument.java | 68 +++++++++ .../searchEngine/SearchInputField.java | 42 ++++++ .../modules/searchEngine/SearchQuery.java | 137 ++++++++++++++++++ .../modules/searchEngine/SearchResponse.java | 34 +++++ .../searchEngine/SearchResultDocument.java | 47 ++++++ .../SearchResultDocumentList.java | 23 +++ .../vitro/webapp/modules/ApplicationStub.java | 61 ++++++++ .../searchEngine/SearchEngineStub.java | 136 +++++++++++++++++ .../modules/searchEngine/SearchQueryStub.java | 38 +++++ .../searchEngine/SearchResponseStub.java | 60 ++++++++ 16 files changed, 886 insertions(+) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/Application.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/ComponentStartupStatus.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngine.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineException.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchFacetField.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputDocument.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputField.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponse.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocument.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocumentList.java create mode 100644 webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java create mode 100644 webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java create mode 100644 webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQueryStub.java create mode 100644 webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponseStub.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java new file mode 100644 index 000000000..1aeb7c500 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java @@ -0,0 +1,29 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.application; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; + +/** + * Tools for working with the current Application instance. + */ +public class ApplicationUtils { + private static final Log log = LogFactory.getLog(ApplicationUtils.class); + + private static volatile Application instance; + + public static Application instance() { + try { + instance.getClass(); + return instance; + } catch (NullPointerException e) { + log.error("Called for Application before it was available", e); + throw new IllegalStateException( + "Called for Application before it was available", e); + } + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/Application.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/Application.java new file mode 100644 index 000000000..cbe44766d --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/Application.java @@ -0,0 +1,35 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules; + +import javax.servlet.ServletContext; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; + +/** + * The interface that holds the modules and extensions together. + */ +public interface Application { + ServletContext getServletContext(); + + SearchEngine getSearchEngine(); + + public interface Component { + enum LifecycleState { + NEW, ACTIVE, STOPPED + } + + void startup(Application application, ComponentStartupStatus ss); + + void shutdown(Application application); + } + + public static interface Module extends Component { + // Nothing except lifecycle so far. + } + + public static interface Extension extends Component { + // Nothing except lifecycle so far. + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/ComponentStartupStatus.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/ComponentStartupStatus.java new file mode 100644 index 000000000..6edc6822c --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/ComponentStartupStatus.java @@ -0,0 +1,21 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules; + +/** + * A facade for the StartupStatus that already knows who the + * ServletContextListener is. + */ +public interface ComponentStartupStatus { + void info(String message); + + void info(String message, Throwable cause); + + void warning(String message); + + void warning(String message, Throwable cause); + + void fatal(String message); + + void fatal(String message, Throwable cause); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngine.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngine.java new file mode 100644 index 000000000..0b8e92d31 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngine.java @@ -0,0 +1,90 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; + +/** + * The principle interface for the SearchEngine. All search-related objects are + * created by these methods. + */ +public interface SearchEngine extends Application.Module { + + /** + * Check to see whether the SearchEngine is alive. + * + * @throws SearchEngineException + * if the SearchEngine does not respond. + */ + void ping() throws SearchEngineException; + + // ---------------------------------------------------------------------- + // Indexing operations + // ---------------------------------------------------------------------- + + /** + * Create a SearchInputDocument that can be populated and added to the + * index. + */ + SearchInputDocument createInputDocument(); + + /** + * Add documents to the search index. + */ + void add(SearchInputDocument... docs) throws SearchEngineException; + + /** + * Add documents to the search index. + */ + void add(Collection docs) throws SearchEngineException; + + /** + * Explicitly commit all pending changes, and wait until they are visible to + * the search. + */ + void commit() throws SearchEngineException; + + /** + * Explicitly commit all pending changes, and optionally wait until they are + * visible to the search. + */ + void commit(boolean wait) throws SearchEngineException; + + /** + * Delete documents from the search index, by unique ID. + */ + void deleteById(String... ids) throws SearchEngineException; + + /** + * Delete documents from the search index, by unique ID. + */ + void deleteById(Collection ids) throws SearchEngineException; + + /** + * Delete documents from the search index if they satisfy the query. + */ + void deleteByQuery(String query) throws SearchEngineException; + + // ---------------------------------------------------------------------- + // Searching operations + // ---------------------------------------------------------------------- + + /** + * Create a SearchQuery that can be populated and used for searching. + */ + SearchQuery createQuery(); + + /** + * Convenience method to create a SearchQuery and set the query text in one + * step. + */ + SearchQuery createQuery(String queryText); + + /** + * Query the search index and return the results. Response is never null. + */ + SearchResponse query(SearchQuery query) throws SearchEngineException; + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineException.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineException.java new file mode 100644 index 000000000..33fa85892 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineException.java @@ -0,0 +1,26 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +/** + * Indicates a problem with a request to the SearchEngine. + */ +public class SearchEngineException extends Exception { + + public SearchEngineException() { + super(); + } + + public SearchEngineException(String message) { + super(message); + } + + public SearchEngineException(Throwable cause) { + super(cause); + } + + public SearchEngineException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchFacetField.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchFacetField.java new file mode 100644 index 000000000..0b3c2b68a --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchFacetField.java @@ -0,0 +1,39 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.List; + +/** + * Holds the faceting information from a query result. + */ +public interface SearchFacetField { + + /** + * The name of the field that was faceted. Never null. + */ + String getName(); + + /** + * The different facet values. May return an empty list, but never null. + */ + List getValues(); + + /** + * Holds one facet from this field. + */ + public interface Count { + + /** + * The value of this facet. Never null. + */ + String getName(); + + /** + * The number of times that the value occurs in the results. + */ + long getCount(); + + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputDocument.java new file mode 100644 index 000000000..34e2dbd10 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputDocument.java @@ -0,0 +1,68 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; +import java.util.Map; + +/** + * A collection of fields and values that will be used to build a record in the + * search index. + */ +public interface SearchInputDocument { + /** + * Create a field that can be populated and added to the document. + */ + SearchInputField createField(String name); + + /** + * Put the field into the document. If a field with this name already exists + * in the document, it will be replaced. + */ + void addField(SearchInputField field); + + /** + * Create a field with this name and values, and put it into the document. If + * a field with this name already exists in the document, it will be + * replaced. + */ + void addField(String name, Object... values); + + /** + * Create a field with this name and values, and put it into the document. If + * a field with this name already exists in the document, it will be + * replaced. + */ + void addField(String name, Collection values); + + /** + * Create a field with this name, boost level and values, and put it into + * the document. If a field with this name already exists in the document, + * it will be replaced. + */ + void addField(String name, float boost, Object... values); + + /** + * Create a field with this name, boost level and values, and put it into + * the document. If a field with this name already exists in the document, + * it will be replaced. + */ + void addField(String name, float boost, Collection values); + + /** + * Set a boost level for the document as a whole. + */ + void setDocumentBoost(float searchBoost); + + float getDocumentBoost(); + + /** + * May return null. + */ + SearchInputField getField(String name); + + /** + * May return an empty map, but never null. + */ + Map getFieldMap(); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputField.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputField.java new file mode 100644 index 000000000..2c1ed9e64 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchInputField.java @@ -0,0 +1,42 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; + +/** + * A named field with a name and one or more values. This can be added to a + * SearchInputDocument and inserted into the search index. + */ +public interface SearchInputField { + + /** + * Add values to this field. + */ + void addValues(Object... values); + + /** + * Add values to this field. + */ + void addValues(Collection values); + + /** + * Set the boost level for this field. + */ + void setBoost(float boost); + + String getName(); + + float getBoost(); + + /** + * May return an empty collection, but never null. + */ + Collection getValues(); + + /** + * May return null. + */ + Object getFirstValue(); + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java new file mode 100644 index 000000000..10977367a --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java @@ -0,0 +1,137 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A collection of search terms that will be used to query the search index. + * + * Each of the "set" and "add" methods will return the searchQuery itself, so + * calls can easily be chained together. + */ +public interface SearchQuery { + public enum Order { + ASC, DESC + } + + /** + * Set the text of the query. This will be parsed using Lucene query syntax. + */ + SearchQuery setQuery(String query); + + /** + * Where in the ordered list of result documents should the response begin? + * That is, how many of the results should be skipped? (allows paging of + * results) + */ + SearchQuery setStart(int start); + + /** + * What is the maximum number of documents that will be returned from the + * query? + */ + SearchQuery setRows(int rows); + + /** + * Which fields should be returned from the query? + */ + SearchQuery addFields(String... names); + + /** + * Which fields should be returned from the query? + */ + SearchQuery addFields(Collection names); + + /** + * What field should be used to sort the results, and in what order? + */ + SearchQuery addSortField(String name, Order order); + + /** + * Restrict the results by thisw query. + */ + SearchQuery addFilterQuery(String filterQuery); + + /** + * Restrict the results by these queries. + */ + SearchQuery addFilterQueries(String... filterQueries); + + /** + * Should the results be faceted? + */ + SearchQuery setFaceting(boolean b); + + /** + * What fields should be used to facet the results? + */ + SearchQuery addFacetFields(String... fields); + + /** + * Add queries that can be used to facet the results. + */ + SearchQuery addFacetQueries(String... queries); + + /** + * Facet having fewer hits will be excluded from the list. + */ + SearchQuery setFacetMinCount(int cnt); + + /** + * Add a system-dependent parameter to the query. + */ + SearchQuery addParameter(String name, String... values); + + /** + * Get the text of the query. + */ + String getQuery(); + + int getStart(); + + /** + * A value of -1 means that no limit has been specified. + */ + int getRows(); + + /** + * May return an empty set, but never null. + */ + Set getFieldsToReturn(); + + /** + * May return an empty map, but never null. + */ + Map getSortFields(); + + /** + * May return an empty set, but never null. + */ + Set getFilters(); + + boolean isFaceting(); + + /** + * May return an empty set, but never null. + */ + Set getFacetFields(); + + /** + * May return an empty set, but never null. + */ + Set getFacetQueries(); + + /** + * A value of -1 means that no limit has been specified. + */ + int getFacetMinCount(); + + /** + * May return an empty map, but never null. + */ + Map> getParameterMap(); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponse.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponse.java new file mode 100644 index 000000000..912fff67e --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponse.java @@ -0,0 +1,34 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.List; +import java.util.Map; + +/** + * The response to a query against the search index. It includes a list of the + * results, as well as an optional collection of facet fields. + */ +public interface SearchResponse { + + /** + * May return an empty list, but never null. + */ + SearchResultDocumentList getResults(); + + /** + * May return an empty map, but never null. + */ + Map>> getHighlighting(); + + /** + * May return null. + */ + SearchFacetField getFacetField(String name); + + /** + * May return an empty list, but never null. + */ + List getFacetFields(); + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocument.java new file mode 100644 index 000000000..3583b5576 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocument.java @@ -0,0 +1,47 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; +import java.util.Map; + +/** + * The concrete representation of a document in the search index. Obtained in + * response to a query. + */ +public interface SearchResultDocument { + + /** + * A document identifier that can be used in SearchEngine.deleteById(); + * Never null. + */ + public String getUniqueId(); + + /** + * May return an empty collection, but never null. + */ + public Collection getFieldNames(); + + /** + * May return null. + */ + public Object getFirstValue(String name); + + /** + * Gets the first value for the named field, and converts it to a String. + * May return null. + */ + public String getStringValue(String name); + + /** + * Get the values for the named field. May return an empty collection, but + * never null. + */ + public Collection getFieldValues(String name); + + /** + * May return an empty map, but never null. The values collection for any + * key may be empty, but never null. + */ + public Map> getFieldValuesMap(); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocumentList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocumentList.java new file mode 100644 index 000000000..37563e45d --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResultDocumentList.java @@ -0,0 +1,23 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +/** + * A collection of results that are returned from a query. + */ +public interface SearchResultDocumentList extends + Iterable { + + /** + * The number of documents that would satisfy the query + */ + long getNumFound(); + + /** + * The number of documents that are included in this result. + */ + int size(); + + SearchResultDocument get(int i); + +} diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java new file mode 100644 index 000000000..39f2e892b --- /dev/null +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java @@ -0,0 +1,61 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package stubs.edu.cornell.mannlib.vitro.webapp.modules; + +import java.lang.reflect.Field; + +import javax.servlet.ServletContext; + +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; + +/** + * TODO + */ +public class ApplicationStub implements Application { + /** + * Create an ApplicationStub and set it as the instance in ApplicationUtils. + */ + public static void setup(ServletContext ctx, SearchEngine searchEngine) { + ApplicationStub instance = new ApplicationStub(ctx, searchEngine); + try { + Field instanceField = ApplicationUtils.class + .getDeclaredField("instance"); + instanceField.setAccessible(true); + instanceField.set(null, instance); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + // ---------------------------------------------------------------------- + // Stub infrastructure + // ---------------------------------------------------------------------- + + private final ServletContext ctx; + private final SearchEngine searchEngine; + + public ApplicationStub(ServletContext ctx, SearchEngine searchEngine) { + this.ctx = ctx; + this.searchEngine = searchEngine; + } + + // ---------------------------------------------------------------------- + // Stub methods + // ---------------------------------------------------------------------- + + @Override + public ServletContext getServletContext() { + return ctx; + } + + @Override + public SearchEngine getSearchEngine() { + return searchEngine; + } + + // ---------------------------------------------------------------------- + // Un-implemented methods + // ---------------------------------------------------------------------- +} diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java new file mode 100644 index 000000000..77dd3b488 --- /dev/null +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java @@ -0,0 +1,136 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; + +/** + * TODO + */ +public class SearchEngineStub implements SearchEngine { + // ---------------------------------------------------------------------- + // Stub infrastructure + // ---------------------------------------------------------------------- + + Map queryResponses = new HashMap<>(); + + public void setQueryResponse(String queryText, SearchResponseStub response) { + queryResponses.put(queryText, response); + } + + // ---------------------------------------------------------------------- + // Stub methods + // ---------------------------------------------------------------------- + + @Override + public SearchQuery createQuery() { + return new SearchQueryStub(); + } + + @Override + public SearchQuery createQuery(String queryText) { + return new SearchQueryStub(queryText); + } + + @Override + public SearchResponse query(SearchQuery query) throws SearchEngineException { + SearchResponseStub response = queryResponses.get(query.getQuery()); + if (response == null) { + return SearchResponseStub.EMPTY_RESPONSE; + } else { + return response; + } + } + + + // ---------------------------------------------------------------------- + // Un-implemented methods + // ---------------------------------------------------------------------- + + + + @Override + public void startup(Application application, ComponentStartupStatus ss) { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.startup() not implemented."); + } + + @Override + public void shutdown(Application application) { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.shutdown() not implemented."); + } + + @Override + public void ping() throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException("SearchEngineStub.ping() not implemented."); + } + + @Override + public SearchInputDocument createInputDocument() { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.createInputDocument() not implemented."); + } + + @Override + public void add(SearchInputDocument... docs) throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException("SearchEngineStub.add() not implemented."); + } + + @Override + public void add(Collection docs) + throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException("SearchEngineStub.add() not implemented."); + } + + @Override + public void commit() throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException("SearchEngineStub.commit() not implemented."); + } + + @Override + public void commit(boolean wait) throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException("SearchEngineStub.commit() not implemented."); + } + + @Override + public void deleteById(String... ids) throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.deleteById() not implemented."); + } + + @Override + public void deleteById(Collection ids) throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.deleteById() not implemented."); + } + + @Override + public void deleteByQuery(String query) throws SearchEngineException { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchEngineStub.deleteByQuery() not implemented."); + } + +} diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQueryStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQueryStub.java new file mode 100644 index 000000000..d24e3ec26 --- /dev/null +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQueryStub.java @@ -0,0 +1,38 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchQuery; + +/** + * TODO + */ +public class SearchQueryStub extends BaseSearchQuery { + // ---------------------------------------------------------------------- + // Stub infrastructure + // ---------------------------------------------------------------------- + + /** + * @param queryText + */ + public SearchQueryStub() { + super(); + } + + /** + * @param queryText + */ + public SearchQueryStub(String queryText) { + super(); + setQuery(queryText); + } + + // ---------------------------------------------------------------------- + // Stub methods + // ---------------------------------------------------------------------- + + // ---------------------------------------------------------------------- + // Un-implemented methods + // ---------------------------------------------------------------------- + +} diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponseStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponseStub.java new file mode 100644 index 000000000..6325573d2 --- /dev/null +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchResponseStub.java @@ -0,0 +1,60 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine; + +import java.util.List; +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; + +/** + * TODO + */ +public class SearchResponseStub implements SearchResponse { + + // ---------------------------------------------------------------------- + // Stub infrastructure + // ---------------------------------------------------------------------- + + public static final SearchResponseStub EMPTY_RESPONSE = null; + + + // ---------------------------------------------------------------------- + // Stub methods + // ---------------------------------------------------------------------- + + // ---------------------------------------------------------------------- + // Un-implemented methods + // ---------------------------------------------------------------------- + + @Override + public SearchResultDocumentList getResults() { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchResponseStub.getResults() not implemented."); + } + + @Override + public Map>> getHighlighting() { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchResponseStub.getHighlighting() not implemented."); + } + + @Override + public SearchFacetField getFacetField(String name) { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchResponseStub.getFacetField() not implemented."); + } + + @Override + public List getFacetFields() { + // TODO Auto-generated method stub + throw new RuntimeException( + "SearchResponseStub.getFacetFields() not implemented."); + } + +} From 5d653ebc9c88cbc8ba47fbfd1976abbe02e55901 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 10:40:17 -0400 Subject: [PATCH 2/9] VIVO-742 Base and Solr Implementations of SearchEngine --- .../base/BaseSearchFacetField.java | 55 ++++++ .../base/BaseSearchInputDocument.java | 77 ++++++++ .../base/BaseSearchInputField.java | 64 +++++++ .../searchengine/base/BaseSearchQuery.java | 179 ++++++++++++++++++ .../searchengine/base/BaseSearchResponse.java | 51 +++++ .../base/BaseSearchResultDocument.java | 75 ++++++++ .../solr/SolrConversionUtils.java | 173 +++++++++++++++++ .../searchengine/solr/SolrSearchEngine.java | 170 +++++++++++++++++ .../solr/SolrSearchResultDocumentList.java | 79 ++++++++ 9 files changed, 923 insertions(+) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchFacetField.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputDocument.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputField.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResponse.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResultDocument.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchEngine.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchFacetField.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchFacetField.java new file mode 100644 index 000000000..55caed27e --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchFacetField.java @@ -0,0 +1,55 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.ArrayList; +import java.util.List; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; + +/** + * A foundation class for implementing SearchFacetField. + */ +public class BaseSearchFacetField implements SearchFacetField { + private final String name; + private final List values; + + public BaseSearchFacetField(String name, List values) { + this.name = name; + this.values = new ArrayList<>(values); + } + + @Override + public String getName() { + return name; + } + + @Override + public List getValues() { + return values; + } + + /** + * A foundation class for implementing SearchFacetField.Count. + */ + public static class BaseCount implements SearchFacetField.Count { + private final String name; + private final long count; + + public BaseCount(String name, long count) { + this.name = name; + this.count = count; + } + + @Override + public String getName() { + return name; + } + + @Override + public long getCount() { + return count; + } + + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputDocument.java new file mode 100644 index 000000000..e2603dd8e --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputDocument.java @@ -0,0 +1,77 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; + +/** + * A foundation class for implementing SearchInputDocument. + */ +public class BaseSearchInputDocument implements SearchInputDocument { + private final Map fieldMap = new HashMap<>(); + private float documentBoost = 1.0F; + + @Override + public void addField(SearchInputField field) { + fieldMap.put(field.getName(), field); + } + + @Override + public void addField(String name, Object... values) { + addField(name, 1.0F, Arrays.asList(values)); + } + + @Override + public void addField(String name, Collection values) { + addField(name, 1.0F, values); + } + + @Override + public void addField(String name, float boost, Object... values) { + addField(name, boost, Arrays.asList(values)); + } + + @Override + public void addField(String name, float boost, Collection values) { + BaseSearchInputField field = new BaseSearchInputField(name); + field.setBoost(boost); + field.addValues(values); + fieldMap.put(name, field); + } + + @Override + public void setDocumentBoost(float searchBoost) { + this.documentBoost = searchBoost; + } + + @Override + public float getDocumentBoost() { + return this.documentBoost; + } + + @Override + public SearchInputField getField(String name) { + return fieldMap.get(name); + } + + @Override + public Map getFieldMap() { + return new HashMap<>(fieldMap); + } + + /** + * Sub-classes should override this if the field requires special + * functionality. + */ + @Override + public SearchInputField createField(String name) { + return new BaseSearchInputField(name); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputField.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputField.java new file mode 100644 index 000000000..69dd3857e --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchInputField.java @@ -0,0 +1,64 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; + +/** + * A foundation class for implementing SearchInputField. + */ +public class BaseSearchInputField implements SearchInputField { + private final String name; + private final List valueList = new ArrayList<>(); + + private float boost = 1.0F; + + public BaseSearchInputField(String name) { + this.name = name; + } + + @Override + public void addValues(Object... values) { + addValues(Arrays.asList(values)); + } + + @Override + public void addValues(Collection values) { + valueList.addAll(values); + } + + @Override + public void setBoost(float boost) { + this.boost = boost; + } + + @Override + public String getName() { + return name; + } + + @Override + public float getBoost() { + return boost; + } + + @Override + public Collection getValues() { + return new ArrayList(valueList); + } + + @Override + public Object getFirstValue() { + if (valueList.isEmpty()) { + return null; + } else { + return valueList.get(0); + } + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java new file mode 100644 index 000000000..eccc6b243 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java @@ -0,0 +1,179 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; + +/** + * A foundation class for implementing SearchQuery. + */ +public class BaseSearchQuery implements SearchQuery { + private String queryText; + private int start = 0; + private int rows = -1; + + private final Set fieldsToReturn = new HashSet<>(); + private final Map sortFields = new HashMap<>(); + private final Set filters = new HashSet<>(); + + private boolean faceting; + private final Set facetFields = new HashSet<>(); + private final Set facetQueries = new HashSet<>(); + private int facetMinCount = -1; + + private final Map> parameterMap = new HashMap<>(); + + @Override + public SearchQuery setQuery(String query) { + this.queryText = query; + return this; + } + + @Override + public SearchQuery setStart(int start) { + this.start = start; + return this; + } + + @Override + public SearchQuery setRows(int rows) { + this.rows = rows; + return this; + } + + @Override + public SearchQuery addFields(String... names) { + return addFields(Arrays.asList(names)); + } + + @Override + public SearchQuery addFields(Collection names) { + this.fieldsToReturn.addAll(names); + return this; + } + + @Override + public SearchQuery addSortField(String name, Order order) { + sortFields.put(name, order); + return this; + } + + @Override + public SearchQuery addFilterQuery(String filterQuery) { + filters.add(filterQuery); + return this; + } + + @Override + public SearchQuery addFilterQueries(String... filterQueries) { + this.filters.addAll(Arrays.asList(filterQueries)); + return this; + } + + @Override + public SearchQuery setFaceting(boolean b) { + this.faceting = b; + return this; + } + + @Override + public SearchQuery addFacetFields(String... fields) { + facetFields.addAll(Arrays.asList(fields)); + return this; + } + + @Override + public SearchQuery addFacetQueries(String... queries) { + facetQueries.addAll(Arrays.asList(queries)); + return this; + } + + @Override + public SearchQuery setFacetMinCount(int cnt) { + facetMinCount = cnt; + return this; + } + + @Override + public SearchQuery addParameter(String name, String... values) { + parameterMap.put(name, Collections.unmodifiableList(new ArrayList<>( + Arrays.asList(values)))); + return this; + } + + @Override + public String getQuery() { + return queryText; + } + + @Override + public int getStart() { + return start; + } + + @Override + public int getRows() { + return rows; + } + + @Override + public Set getFieldsToReturn() { + return Collections.unmodifiableSet(fieldsToReturn); + } + + @Override + public Map getSortFields() { + return Collections.unmodifiableMap(sortFields); + } + + @Override + public Set getFilters() { + return Collections.unmodifiableSet(filters); + } + + @Override + public boolean isFaceting() { + return faceting; + } + + @Override + public Set getFacetFields() { + return Collections.unmodifiableSet(facetFields); + } + + @Override + public Set getFacetQueries() { + return Collections.unmodifiableSet(facetQueries); + } + + @Override + public int getFacetMinCount() { + return facetMinCount; + } + + @Override + public Map> getParameterMap() { + return Collections.unmodifiableMap(parameterMap); + } + + @Override + public String toString() { + return "BaseSearchQuery [queryText=" + queryText + ", start=" + start + + ", rows=" + rows + ", fieldsToReturn=" + fieldsToReturn + + ", sortFields=" + sortFields + ", filters=" + filters + + ", faceting=" + faceting + ", facetFields=" + facetFields + + ", facetQueries=" + facetQueries + ", facetMinCount=" + + facetMinCount + ", parameterMap=" + parameterMap + "]"; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResponse.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResponse.java new file mode 100644 index 000000000..955b1f20a --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResponse.java @@ -0,0 +1,51 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; + +/** + * A foundation class for implementing SearchResponse; + */ +public class BaseSearchResponse implements SearchResponse { + private final Map>> highlighting; + private final Map facetFields; + private final SearchResultDocumentList results; + + public BaseSearchResponse( + Map>> highlighting, + Map facetFields, + SearchResultDocumentList results) { + this.highlighting = highlighting; + this.facetFields = facetFields; + this.results = results; + } + + @Override + public SearchResultDocumentList getResults() { + return results; + } + + @Override + public Map>> getHighlighting() { + return Collections.unmodifiableMap(highlighting); + } + + @Override + public SearchFacetField getFacetField(String name) { + return facetFields.get(name); + } + + @Override + public List getFacetFields() { + return new ArrayList<>(facetFields.values()); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResultDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResultDocument.java new file mode 100644 index 000000000..6c33823b6 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchResultDocument.java @@ -0,0 +1,75 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.base; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; + +/** + * A foundation class for implementing SearchResultDocument. + */ +public class BaseSearchResultDocument implements SearchResultDocument { + private final String uniqueId; + private final Map> fieldValuesMap; + + public BaseSearchResultDocument(String uniqueId, Map> fieldValuesMap) { + this.uniqueId = uniqueId; + + Map> map = new HashMap<>(); + for (String name : fieldValuesMap.keySet()) { + map.put(name, Collections.unmodifiableList(new ArrayList<>( + fieldValuesMap.get(name)))); + } + this.fieldValuesMap = Collections.unmodifiableMap(map); + } + + @Override + public String getUniqueId() { + return uniqueId; + } + + @Override + public Collection getFieldNames() { + return fieldValuesMap.keySet(); + } + + @Override + public Object getFirstValue(String name) { + Collection values = fieldValuesMap.get(name); + if (values == null || values.isEmpty()) { + return null; + } + return values.iterator().next(); + } + + @Override + public String getStringValue(String name) { + Object o = getFirstValue(name); + if (o == null) { + return null; + } else { + return String.valueOf(o); + } + } + + @Override + public Collection getFieldValues(String name) { + Collection values = fieldValuesMap.get(name); + if (values == null) { + return Collections.emptyList(); + } else { + return values; + } + } + + @Override + public Map> getFieldValuesMap() { + return fieldValuesMap; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java new file mode 100644 index 000000000..752c81b94 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java @@ -0,0 +1,173 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.solr; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrQuery.ORDER; +import org.apache.solr.client.solrj.response.FacetField; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.SolrInputField; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchFacetField; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchFacetField.BaseCount; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchResponse; + +/** + * Utility method for converting from Solr-specific instances to Search-generic + * instances, and back. + */ +public class SolrConversionUtils { + + // ---------------------------------------------------------------------- + // Convert input documents to Solr-specific. + // ---------------------------------------------------------------------- + + static List convertToSolrInputDocuments( + Collection docs) { + List solrDocs = new ArrayList<>(); + for (SearchInputDocument doc : docs) { + solrDocs.add(convertToSolrInputDocument(doc)); + } + return solrDocs; + } + + private static SolrInputDocument convertToSolrInputDocument( + SearchInputDocument doc) { + SolrInputDocument solrDoc = new SolrInputDocument( + convertToSolrInputFieldMap(doc.getFieldMap())); + solrDoc.setDocumentBoost(doc.getDocumentBoost()); + return solrDoc; + } + + private static Map convertToSolrInputFieldMap( + Map fieldMap) { + Map solrFieldMap = new HashMap<>(); + for (String fieldName : fieldMap.keySet()) { + solrFieldMap.put(fieldName, + convertToSolrInputField(fieldMap.get(fieldName))); + } + return solrFieldMap; + } + + private static SolrInputField convertToSolrInputField( + SearchInputField searchInputField) { + SolrInputField solrField = new SolrInputField( + searchInputField.getName()); + solrField.addValue(searchInputField.getValues(), + searchInputField.getBoost()); + return solrField; + } + + // ---------------------------------------------------------------------- + // Convert queries to Solr-specific. + // ---------------------------------------------------------------------- + + /** + * Convert from a SearchQuery to a SolrQuery, so the Solr server may execute + * it. + */ + static SolrQuery convertToSolrQuery(SearchQuery query) { + SolrQuery solrQuery = new SolrQuery(query.getQuery()); + solrQuery.setStart(query.getStart()); + + int rows = query.getRows(); + if (rows >= 0) { + solrQuery.setRows(rows); + } + + for (String fieldToReturn : query.getFieldsToReturn()) { + solrQuery.addField(fieldToReturn); + } + + Map sortFields = query.getSortFields(); + for (String sortField : sortFields.keySet()) { + solrQuery.addSortField(sortField, + convertToSolrOrder(sortFields.get(sortField))); + } + + for (String filter : query.getFilters()) { + solrQuery.addFilterQuery(filter); + } + + solrQuery.setFacet(query.isFaceting()); + + for (String facetField : query.getFacetFields()) { + solrQuery.addFacetField(facetField); + } + + for (String facetQuery : query.getFacetQueries()) { + solrQuery.addFacetQuery(facetQuery); + } + + int minCount = query.getFacetMinCount(); + if (minCount >= 0) { + solrQuery.setFacetMinCount(minCount); + } + + Map> parameterMap = query.getParameterMap(); + for (String parameterName : parameterMap.keySet()) { + String[] values = parameterMap.get(parameterName).toArray( + new String[0]); + solrQuery.add(parameterName, values); + } + + return solrQuery; + } + + private static ORDER convertToSolrOrder(Order order) { + if (order == Order.DESC) { + return ORDER.desc; + } else { + return ORDER.asc; + } + } + + // ---------------------------------------------------------------------- + // Convert responses to Search-generic + // ---------------------------------------------------------------------- + + static SearchResponse convertToSearchResponse(QueryResponse response) { + return new BaseSearchResponse(response.getHighlighting(), + convertToSearchFacetFieldMap(response.getFacetFields()), + new SolrSearchResultDocumentList(response.getResults())); + } + + private static Map convertToSearchFacetFieldMap( + List facetFields) { + Map map = new HashMap<>(); + for (FacetField facetField : facetFields) { + map.put(facetField.getName(), convertToSearchFacetField(facetField)); + } + return map; + } + + private static SearchFacetField convertToSearchFacetField( + FacetField facetField) { + return new BaseSearchFacetField(facetField.getName(), + convertToSearchFacetFieldCounts(facetField.getValues())); + } + + private static List convertToSearchFacetFieldCounts( + List solrCounts) { + List searchCounts = new ArrayList<>(); + for (FacetField.Count solrCount : solrCounts) { + searchCounts.add(new BaseCount(solrCount.getName(), solrCount + .getCount())); + } + return searchCounts; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchEngine.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchEngine.java new file mode 100644 index 000000000..7a3dbf993 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchEngine.java @@ -0,0 +1,170 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.solr; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +import javax.servlet.ServletContext; + +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.apache.solr.client.solrj.response.QueryResponse; + +import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchQuery; + +/** + * The Solr-based implementation of SearchEngine. + */ +public class SolrSearchEngine implements SearchEngine { + private HttpSolrServer server; + + /** + * Set up the http connection with the solr server + */ + @Override + public void startup(Application application, ComponentStartupStatus css) { + ServletContext ctx = application.getServletContext(); + String solrServerUrlString = ConfigurationProperties.getBean(ctx) + .getProperty("vitro.local.solr.url"); + if (solrServerUrlString == null) { + css.fatal("Could not find vitro.local.solr.url in " + + "runtime.properties. Vitro application needs the URL of " + + "a solr server that it can use to index its data. It " + + "should be something like http://localhost:${port}" + + ctx.getContextPath() + "solr"); + return; + } + + try { + server = new HttpSolrServer(solrServerUrlString); + server.setSoTimeout(10000); // socket read timeout + server.setConnectionTimeout(10000); + server.setDefaultMaxConnectionsPerHost(100); + server.setMaxTotalConnections(100); + server.setMaxRetries(1); + css.info("Set up the Solr search engine; URL = '" + + solrServerUrlString + "'."); + } catch (Exception e) { + css.fatal("Could not set up the Solr search engine", e); + } + } + + @Override + public void shutdown(Application application) { + server.shutdown(); + } + + @Override + public void ping() throws SearchEngineException { + try { + server.ping(); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException( + "Solr server did not respont to ping.", e); + } + } + + @Override + public SearchInputDocument createInputDocument() { + return new BaseSearchInputDocument(); + } + + @Override + public void add(SearchInputDocument... docs) throws SearchEngineException { + add(Arrays.asList(docs)); + } + + @Override + public void add(Collection docs) + throws SearchEngineException { + try { + server.add(SolrConversionUtils.convertToSolrInputDocuments(docs)); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException( + "Solr server failed to add documents " + docs, e); + } + } + + @Override + public void commit() throws SearchEngineException { + try { + server.commit(); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException("Failed to commit to Solr server.", + e); + } + } + + @Override + public void commit(boolean wait) throws SearchEngineException { + try { + server.commit(wait, wait); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException("Failed to commit to Solr server.", + e); + } + } + + @Override + public void deleteById(String... ids) throws SearchEngineException { + deleteById(Arrays.asList(ids)); + } + + @Override + public void deleteById(Collection ids) throws SearchEngineException { + try { + server.deleteById(new ArrayList<>(ids)); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException( + "Solr server failed to delete documents: " + ids, e); + } + } + + @Override + public void deleteByQuery(String query) throws SearchEngineException { + try { + server.deleteByQuery(query); + } catch (SolrServerException | IOException e) { + throw new SearchEngineException( + "Solr server failed to delete documents: " + query, e); + } + } + + @Override + public SearchQuery createQuery() { + return new BaseSearchQuery(); + } + + @Override + public SearchQuery createQuery(String queryText) { + BaseSearchQuery query = new BaseSearchQuery(); + query.setQuery(queryText); + return query; + } + + @Override + public SearchResponse query(SearchQuery query) throws SearchEngineException { + try { + SolrQuery solrQuery = SolrConversionUtils.convertToSolrQuery(query); + QueryResponse response = server.query(solrQuery); + return SolrConversionUtils.convertToSearchResponse(response); + } catch (SolrServerException e) { + throw new SearchEngineException( + "Solr server failed to execute the query" + query, e); + } + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java new file mode 100644 index 000000000..196b87217 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java @@ -0,0 +1,79 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine.solr; + +import java.util.Iterator; + +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrDocumentList; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchResultDocument; + +/** + * A Solr-based implementation of SearchResultDocumentList. + * + * It's necessary to use this instead of the base version, so the iterator can + * convert each document as it is requested. + */ +public class SolrSearchResultDocumentList implements SearchResultDocumentList { + private SolrDocumentList solrDocs; + + public SolrSearchResultDocumentList(SolrDocumentList solrDocs) { + this.solrDocs = solrDocs; + } + + @Override + public Iterator iterator() { + return new SearchResultDocumentIterator(solrDocs.iterator()); + } + + @Override + public long getNumFound() { + return solrDocs.getNumFound(); + } + + @Override + public int size() { + return solrDocs.size(); + } + + @Override + public SearchResultDocument get(int i) { + return convertToSearchResultDocument(solrDocs.get(i)); + } + + private static class SearchResultDocumentIterator implements + Iterator { + private final Iterator solrIterator; + + public SearchResultDocumentIterator(Iterator solrIterator) { + this.solrIterator = solrIterator; + } + + @Override + public boolean hasNext() { + return solrIterator.hasNext(); + } + + @Override + public SearchResultDocument next() { + return convertToSearchResultDocument(solrIterator.next()); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + } + + private static SearchResultDocument convertToSearchResultDocument( + SolrDocument solrDoc) { + return new BaseSearchResultDocument( + (String) solrDoc.getFieldValue("DocId"), + solrDoc.getFieldValuesMap()); + } + +} From 823848123fe29056ab821bd02d4ccf02b64a067a Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 10:56:00 -0400 Subject: [PATCH 3/9] VIVO-742 Create SearchEngineSetup and SearchIndexerSetup --- .../webapp/application/ApplicationImpl.java | 41 ++++ .../searchengine/SearchEngineSetup.java | 32 +++ .../searchengine/SearchEngineWrapper.java | 178 ++++++++++++++++ .../searchindex/SearchIndexerSetup.java | 193 ++++++++++++++++++ .../startup/ComponentStartupStatusImpl.java | 53 +++++ .../WEB-INF/resources/startup_listeners.txt | 5 +- 6 files changed, 500 insertions(+), 2 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineSetup.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineWrapper.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/startup/ComponentStartupStatusImpl.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java new file mode 100644 index 000000000..0d33ad0e9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java @@ -0,0 +1,41 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.application; + +import javax.servlet.ServletContext; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineWrapper; +import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine; + +/** + * The basic implementation of the Application interface. + */ +public class ApplicationImpl implements Application { + private final ServletContext ctx; + private SearchEngine searchEngine; + + public ApplicationImpl(ServletContext ctx) { + this.ctx = ctx; + setSearchEngine(new SolrSearchEngine()); + } + + @Override + public ServletContext getServletContext() { + return ctx; + } + + @Override + public SearchEngine getSearchEngine() { + return searchEngine; + } + + public void setSearchEngine(SearchEngine searchEngine) { + if (searchEngine instanceof SearchEngineWrapper) { + this.searchEngine = searchEngine; + } else { + this.searchEngine = new SearchEngineWrapper(searchEngine); + } + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineSetup.java new file mode 100644 index 000000000..0a4748d90 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineSetup.java @@ -0,0 +1,32 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; +import edu.cornell.mannlib.vitro.webapp.startup.ComponentStartupStatusImpl; +import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; + +/** + * Whatever search engine we have, start it up and shut it down. + */ +public class SearchEngineSetup implements ServletContextListener { + @Override + public void contextInitialized(ServletContextEvent sce) { + Application application = ApplicationUtils.instance(); + StartupStatus ss = StartupStatus.getBean(sce.getServletContext()); + ComponentStartupStatus css = new ComponentStartupStatusImpl(this, ss); + application.getSearchEngine().startup(application, css); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + Application application = ApplicationUtils.instance(); + application.getSearchEngine().shutdown(application); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineWrapper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineWrapper.java new file mode 100644 index 000000000..6cbd9b52b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/SearchEngineWrapper.java @@ -0,0 +1,178 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchengine; + +import static edu.cornell.mannlib.vitro.webapp.modules.Application.Component.LifecycleState.ACTIVE; +import static edu.cornell.mannlib.vitro.webapp.modules.Application.Component.LifecycleState.NEW; +import static edu.cornell.mannlib.vitro.webapp.modules.Application.Component.LifecycleState.STOPPED; + +import java.util.Collection; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; + +/** + * TODO + */ +public class SearchEngineWrapper implements SearchEngine { + private static final Log log = LogFactory.getLog(SearchEngineWrapper.class); + + private final SearchEngine innerEngine; + + private volatile LifecycleState lifecycleState = NEW; + + public SearchEngineWrapper(SearchEngine innerEngine) { + if (innerEngine == null) { + throw new NullPointerException("innerEngine may not be null."); + } + this.innerEngine = innerEngine; + } + + /** + * Complain unless ACTIVE. + */ + private void confirmActive() { + if (lifecycleState == NEW) { + throw new IllegalStateException( + "Search engine has not been started."); + } else if (lifecycleState == STOPPED) { + throw new IllegalStateException("Search engine has stopped."); + } + } + + // ---------------------------------------------------------------------- + // Overridden methods. + // ---------------------------------------------------------------------- + + /** + * If NEW, do startup. If STOPPED, throw an exception. If ACTIVE, just + * complain. + */ + @Override + public void startup(Application application, ComponentStartupStatus css) { + if (application == null) { + throw new NullPointerException("application may not be null."); + } + switch (lifecycleState) { + case NEW: + innerEngine.startup(application, css); + lifecycleState = ACTIVE; + break; + case STOPPED: + throw new IllegalStateException( + "startup called when already STOPPED"); + default: // ACTIVE: + try { + throw new IllegalStateException(); + } catch (Exception e) { + log.warn("startup called when already ACTIVE", e); + } + break; + } + } + + /** + * If ACTIVE, do shutdown. Otherwise, complain and do nothing. + */ + @Override + public void shutdown(Application application) { + if (application == null) { + throw new NullPointerException("application may not be null."); + } + switch (lifecycleState) { + case ACTIVE: + innerEngine.shutdown(application); + lifecycleState = STOPPED; + break; + default: // NEW, STOPPED: + try { + throw new IllegalStateException(); + } catch (Exception e) { + log.warn("startup called when state was " + lifecycleState, e); + } + break; + } + } + + @Override + public void ping() throws SearchEngineException { + confirmActive(); + innerEngine.ping(); + } + + @Override + public SearchInputDocument createInputDocument() { + confirmActive(); + return innerEngine.createInputDocument(); + } + + @Override + public void add(SearchInputDocument... docs) throws SearchEngineException { + confirmActive(); + innerEngine.add(docs); + } + + @Override + public void add(Collection docs) + throws SearchEngineException { + confirmActive(); + innerEngine.add(docs); + } + + @Override + public void commit() throws SearchEngineException { + confirmActive(); + innerEngine.commit(); + } + + @Override + public void commit(boolean wait) throws SearchEngineException { + confirmActive(); + innerEngine.commit(wait); + } + + @Override + public void deleteById(String... ids) throws SearchEngineException { + confirmActive(); + innerEngine.deleteById(ids); + } + + @Override + public void deleteById(Collection ids) throws SearchEngineException { + confirmActive(); + innerEngine.deleteById(ids); + } + + @Override + public void deleteByQuery(String query) throws SearchEngineException { + confirmActive(); + innerEngine.deleteByQuery(query); + } + + @Override + public SearchQuery createQuery() { + confirmActive(); + return innerEngine.createQuery(); + } + + @Override + public SearchQuery createQuery(String queryText) { + confirmActive(); + return innerEngine.createQuery(queryText); + } + + @Override + public SearchResponse query(SearchQuery query) throws SearchEngineException { + confirmActive(); + return innerEngine.query(query); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java new file mode 100644 index 000000000..a5fff0582 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java @@ -0,0 +1,193 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.searchindex; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.solr.client.solrj.impl.HttpSolrServer; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.vocabulary.OWL; + +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; +import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; +import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; +import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; +import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate; +import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalUriFinders; +import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; +import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener; +import edu.cornell.mannlib.vitro.webapp.search.solr.SolrIndexer; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnNamespace; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnType; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnTypeNamespace; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeNonFlagVitro; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameBoost; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameFields; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SearchIndexExcluder; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SyncingExcludeBasedOnType; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL; +import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; + +/** + * TODO + */ +public class SearchIndexerSetup implements ServletContextListener { + public static final String PROHIBITED_FROM_SEARCH = "edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch"; + + /** + * Exclude from the search index Individuals with types from these + * namespaces + */ + private static final String[] TYPE_NS_EXCLUDES = { VitroVocabulary.PUBLIC + // if you do OWL.NS here you will exclude all of owl:Thing. + }; + + /** + * Exclude from the search index individuals who's URIs start with these + * namespaces. + */ + private static final String[] INDIVIDUAL_NS_EXCLUDES = { + VitroVocabulary.vitroURI, VitroVocabulary.VITRO_PUBLIC, + VitroVocabulary.PSEUDO_BNODE_NS, OWL.NS }; + + /** Individuals of these types will be excluded from the search index */ + private static final String[] OWL_TYPES_EXCLUDES = { + OWL.ObjectProperty.getURI(), OWL.DatatypeProperty.getURI(), + OWL.AnnotationProperty.getURI() }; + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + StartupStatus ss = StartupStatus.getBean(context); + HttpSolrServer server = (HttpSolrServer) ApplicationUtils.instance().getSearchEngine(); + + try { + /* set up the individual to solr doc translation */ + OntModel jenaOntModel = ModelAccess.on(context).getJenaOntModel(); + OntModel displayModel = ModelAccess.on(context).getDisplayModel(); + + /* + * try to get context attribute DocumentModifiers and use that as + * the start of the list of DocumentModifier objects. This allows + * other ContextListeners to add to the basic set of + * DocumentModifiers. + */ + @SuppressWarnings("unchecked") + List modifiersFromContext = (List) context + .getAttribute("DocumentModifiers"); + + /* + * try to get context attribute SearchIndexExcludes and use that as + * the start of the list of exclude objects. This allows other + * ContextListeners to add to the basic set of SearchIndexExcludes . + */ + @SuppressWarnings("unchecked") + List searchIndexExcludesFromContext = (List) context + .getAttribute("SearchIndexExcludes"); + + IndividualToSolrDocument indToSolrDoc = setupTransltion( + jenaOntModel, displayModel, + RDFServiceUtils.getRDFServiceFactory(context), + modifiersFromContext, searchIndexExcludesFromContext); + + /* setup solr indexer */ + SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc); + + // This is where the builder gets the list of places to try to + // get objects to index. It is filtered so that non-public text + // does not get into the search index. + WebappDaoFactory wadf = ModelAccess.on(context) + .getWebappDaoFactory(); + VitroFilters vf = VitroFilterUtils.getPublicFilter(context); + wadf = new WebappDaoFactoryFiltering(wadf, vf); + + // make objects that will find additional URIs for context nodes etc + RDFService rdfService = RDFServiceUtils.getRDFServiceFactory( + context).getRDFService(); + List uriFinders = AdditionalUriFinders + .getList(rdfService, wadf.getIndividualDao()); + + // Make the IndexBuilder + IndexBuilder builder = new IndexBuilder(solrIndexer, wadf, + uriFinders); + // Save it to the servlet context so we can access it later in the + // webapp. + context.setAttribute(IndexBuilder.class.getName(), builder); + + // set up listeners so search index builder is notified of changes + // to model + ServletContext ctx = sce.getServletContext(); + SearchReindexingListener srl = new SearchReindexingListener(builder); + ModelContext.registerListenerForChanges(ctx, srl); + + ss.info(this, "Setup of Solr index completed."); + } catch (Throwable e) { + ss.fatal(this, "could not setup local solr server", e); + } + + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + IndexBuilder builder = (IndexBuilder) sce.getServletContext() + .getAttribute(IndexBuilder.class.getName()); + if (builder != null) + builder.stopIndexingThread(); + + } + + public static IndividualToSolrDocument setupTransltion( + OntModel jenaOntModel, Model displayModel, + RDFServiceFactory rdfServiceFactory, + List modifiersFromContext, + List searchIndexExcludesFromContext) { + + /* + * try to get context attribute DocumentModifiers and use that as the + * start of the list of DocumentModifier objects. This allows other + * ContextListeners to add to the basic set of DocumentModifiers. + */ + List modifiers = new ArrayList(); + if (modifiersFromContext != null) { + modifiers.addAll(modifiersFromContext); + } + + modifiers.add(new NameFields(rdfServiceFactory)); + modifiers.add(new NameBoost(1.2f)); + modifiers.add(new ThumbnailImageURL(rdfServiceFactory)); + + /* + * try to get context attribute SearchIndexExcludes and use that as the + * start of the list of exclude objects. This allows other + * ContextListeners to add to the basic set of SearchIndexExcludes . + */ + List excludes = new ArrayList(); + if (searchIndexExcludesFromContext != null) { + excludes.addAll(searchIndexExcludesFromContext); + } + + excludes.add(new ExcludeBasedOnNamespace(INDIVIDUAL_NS_EXCLUDES)); + excludes.add(new ExcludeBasedOnTypeNamespace(TYPE_NS_EXCLUDES)); + excludes.add(new ExcludeBasedOnType(OWL_TYPES_EXCLUDES)); + excludes.add(new ExcludeNonFlagVitro()); + excludes.add(new SyncingExcludeBasedOnType(displayModel)); + + return new IndividualToSolrDocument(excludes, modifiers); + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/startup/ComponentStartupStatusImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/startup/ComponentStartupStatusImpl.java new file mode 100644 index 000000000..65ad2e206 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/startup/ComponentStartupStatusImpl.java @@ -0,0 +1,53 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.startup; + +import javax.servlet.ServletContextListener; + +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; + +/** + * A temporary wrapper around the StartupStatus, with the ServletContextListener + * built in. + */ +public class ComponentStartupStatusImpl implements ComponentStartupStatus { + private final ServletContextListener listener; + private final StartupStatus ss; + + public ComponentStartupStatusImpl(ServletContextListener listener, + StartupStatus ss) { + this.listener = listener; + this.ss = ss; + } + + @Override + public void info(String message) { + ss.info(listener, message); + } + + @Override + public void info(String message, Throwable cause) { + ss.info(listener, message, cause); + } + + @Override + public void warning(String message) { + ss.warning(listener, message); + } + + @Override + public void warning(String message, Throwable cause) { + ss.warning(listener, message, cause); + } + + @Override + public void fatal(String message) { + ss.fatal(listener, message); + } + + @Override + public void fatal(String message, Throwable cause) { + ss.fatal(listener, message, cause); + } + +} diff --git a/webapp/web/WEB-INF/resources/startup_listeners.txt b/webapp/web/WEB-INF/resources/startup_listeners.txt index 1744c622f..8899f7187 100644 --- a/webapp/web/WEB-INF/resources/startup_listeners.txt +++ b/webapp/web/WEB-INF/resources/startup_listeners.txt @@ -62,9 +62,10 @@ edu.ucsf.vitro.opensocial.OpenSocialSmokeTests # For multiple language support edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionSetup -# The Solr index uses a "public" permission, so the PropertyRestrictionPolicyHelper +# The search indexer uses a "public" permission, so the PropertyRestrictionPolicyHelper # and the PermissionRegistry must already be set up. -edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup +edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineSetup +edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerSetup edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerSetup edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration$Setup From 90886c564ef536bc8e5be3d7e6ada9f603c0705b Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 13:49:27 -0400 Subject: [PATCH 4/9] VIVO-742 Change client code to use SearchEngine interface. Removed SolrQueryTest until I can see how to update it. Everything compiles and tests run, but haven't tried running VIVO yet. --- .../IndividualListRdfController.java | 36 +- .../admin/ajax/ProfileAutoCompleter.java | 36 +- .../ajax/BasicProfilesGetter.java | 34 +- .../freemarker/IndividualListController.java | 25 +- .../IndividualListQueryResults.java | 32 +- .../grefine/JSONReconcileServlet.java | 67 ++-- .../webapp/controller/json/JsonServlet.java | 6 +- .../webapp/dao/jena/VClassGroupCache.java | 66 ++-- .../IndividualsViaSolrQueryOptions.java | 32 +- .../DefaultObjectPropertyFormGenerator.java | 36 +- .../IndividualsByRankFormGenerator.java | 29 -- .../webapp/filters/CachingResponseFilter.java | 21 +- .../controller/AutocompleteController.java | 72 ++-- .../DataAutocompleteController.java | 17 +- .../search/controller/IndexController.java | 6 +- .../controller/PagedSearchController.java | 70 ++-- .../vitro/webapp/search/solr/SolrIndexer.java | 64 ++-- .../vitro/webapp/search/solr/SolrSetup.java | 209 ----------- .../documentBuilding/ContextNodeFields.java | 12 +- .../documentBuilding/DocumentModifier.java | 7 +- .../ExcludeBasedOnTypeNamespace.java | 2 - .../IndividualToSolrDocument.java | 27 +- .../solr/documentBuilding/NameBoost.java | 9 +- .../solr/documentBuilding/NameFields.java | 4 +- .../documentBuilding/SourceInstitution.java | 5 +- .../documentBuilding/ThumbnailImageURL.java | 6 +- .../searchindex/SearchIndexerSetup.java | 7 +- .../utils/dataGetter/DataGetterUtils.java | 17 +- .../IndividualsForClassesDataGetter.java | 8 +- .../dataGetter/SolrIndividualsDataGetter.java | 3 +- .../webapp/utils/solr/SolrQueryUtils.java | 61 ++-- .../webapp/utils/solr/SolrResultsParser.java | 41 +-- .../grefine/JSONReconcileServletTest.java | 27 +- .../controller/json/JsonServletTest.java | 10 +- .../webapp/search/solr/SolrQueryTest.java | 327 ------------------ .../search/solr/ThumbnailImageURLTest.java | 16 +- .../searchEngine/SearchEngineStub.java | 14 +- .../solr/client/solrj/SolrServerStub.java | 46 --- 38 files changed, 398 insertions(+), 1109 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java delete mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java delete mode 100644 webapp/test/stubs/org/apache/solr/client/solrj/SolrServerStub.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java index d12db53fe..e57bfa65e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java @@ -8,11 +8,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -21,8 +16,13 @@ import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.vocabulary.RDF; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; public class IndividualListRdfController extends VitroHttpServlet { @@ -31,21 +31,22 @@ public class IndividualListRdfController extends VitroHttpServlet { public static final int ENTITY_LIST_CONTROLLER_MAX_RESULTS = 30000; - public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + @Override + public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { // Make the query String vclassUri = req.getParameter("vclass"); String queryStr = VitroSearchTermNames.RDFTYPE + ":\"" + vclassUri + "\""; - SolrQuery query = new SolrQuery(queryStr); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(queryStr); query.setStart(0) .setRows(ENTITY_LIST_CONTROLLER_MAX_RESULTS) - .setFields(VitroSearchTermNames.URI); + .addFields(VitroSearchTermNames.URI); // For now, we're only displaying the url, so no need to sort. - //.setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED); + //.addSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED); // Execute the query - SolrServer solr = SolrSetup.getSolrServer(getServletContext()); - QueryResponse response = null; + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchResponse response = null; try { response = solr.query(query); @@ -57,17 +58,17 @@ public class IndividualListRdfController extends VitroHttpServlet { throw new ServletException("Could not run search in IndividualListRdfController"); } - SolrDocumentList docs = response.getResults(); + SearchResultDocumentList docs = response.getResults(); if (docs == null) { throw new ServletException("Could not run search in IndividualListRdfController"); } Model model = ModelFactory.createDefaultModel(); - for (SolrDocument doc : docs) { - String uri = doc.get(VitroSearchTermNames.URI).toString(); + for (SearchResultDocument doc : docs) { + String uri = doc.getStringValue(VitroSearchTermNames.URI); Resource resource = ResourceFactory.createResource(uri); - RDFNode node = (RDFNode) ResourceFactory.createResource(vclassUri); + RDFNode node = ResourceFactory.createResource(vclassUri); model.add(resource, RDF.type, node); } @@ -75,7 +76,8 @@ public class IndividualListRdfController extends VitroHttpServlet { model.write(res.getOutputStream(), "RDF/XML"); } - public void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ + @Override + public void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ doGet(req,res); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java index 3ad16b77e..b545f899c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java @@ -16,17 +16,11 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrQuery.ORDER; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; import org.json.JSONException; import com.hp.hpl.jena.ontology.OntModel; @@ -39,11 +33,16 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Literal; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.ajax.AbstractAjaxResponder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.utils.solr.AutoCompleteWords; import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; @@ -121,8 +120,8 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements } try { - SolrQuery query = buildSolrQuery(); - QueryResponse queryResponse = executeSolrQuery(query); + SearchQuery query = buildSearchQuery(); + SearchResponse queryResponse = executeSearchQuery(query); List> maps = SolrQueryUtils .parseAndFilterResponse(queryResponse, RESPONSE_FIELDS, @@ -133,17 +132,17 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements String response = assembleJsonResponse(maps); log.debug(response); return response; - } catch (SolrServerException e) { + } catch (SearchEngineException e) { log.error("Failed to get basic profile info", e); return EMPTY_RESPONSE; } } - private SolrQuery buildSolrQuery() { - SolrQuery q = new SolrQuery(); - q.setFields(NAME_RAW, URI); - q.setSortField(NAME_LOWERCASE_SINGLE_VALUED, ORDER.asc); - q.setFilterQueries(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, + private SearchQuery buildSearchQuery() { + SearchQuery q = ApplicationUtils.instance().getSearchEngine().createQuery(); + q.addFields(NAME_RAW, URI); + q.addSortField(NAME_LOWERCASE_SINGLE_VALUED, Order.ASC); + q.addFilterQuery(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR)); q.setStart(0); q.setRows(10000); @@ -151,10 +150,9 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements return q; } - private QueryResponse executeSolrQuery(SolrQuery query) - throws SolrServerException { - ServletContext ctx = servlet.getServletContext(); - SolrServer solr = SolrSetup.getSolrServer(ctx); + private SearchResponse executeSearchQuery(SearchQuery query) + throws SearchEngineException { + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); return solr.query(query); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java index 368f8df42..d507db074 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java @@ -1,7 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ajax; - import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.AC_NAME_STEMMED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW; @@ -14,23 +13,22 @@ import java.io.IOException; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrQuery.ORDER; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; import org.json.JSONException; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.ajax.AbstractAjaxResponder; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.utils.solr.AutoCompleteWords; import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; @@ -88,10 +86,9 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { } try { - ServletContext ctx = servlet.getServletContext(); - SolrServer solr = SolrSetup.getSolrServer(ctx); - SolrQuery query = buildSolrQuery(); - QueryResponse queryResponse = solr.query(query); + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchQuery query = buildSearchQuery(); + SearchResponse queryResponse = solr.query(query); List> parsed = SolrQueryUtils .parseResponse(queryResponse, RESPONSE_FIELDS); @@ -99,18 +96,17 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { String response = assembleJsonResponse(parsed); log.debug(response); return response; - } catch (SolrServerException e) { + } catch (SearchEngineException e) { log.error("Failed to get basic profile info", e); return EMPTY_RESPONSE; } } - private SolrQuery buildSolrQuery() { - SolrQuery q = new SolrQuery(); - q.setFields(NAME_RAW, URI); - q.setSortField(NAME_LOWERCASE_SINGLE_VALUED, ORDER.asc); - q.setFilterQueries(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, - profileTypes, OR)); + private SearchQuery buildSearchQuery() { + SearchQuery q = ApplicationUtils.instance().getSearchEngine().createQuery(); + q.addFields(NAME_RAW, URI); + q.addSortField(NAME_LOWERCASE_SINGLE_VALUED, Order.ASC); + q.addFilterQuery(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR)); q.setStart(0); q.setRows(30); q.setQuery(searchWords.assembleQuery(NAME_UNSTEMMED, AC_NAME_STEMMED)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index 184bda547..492d3b420 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -8,12 +8,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; - import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrServerException; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; @@ -24,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual; @@ -94,8 +92,7 @@ public class IndividualListController extends FreemarkerHttpServlet { vclass.getURI(), page, alpha, - vreq.getWebappDaoFactory().getIndividualDao(), - getServletContext()); + vreq.getWebappDaoFactory().getIndividualDao()); body.putAll(vcResults.asFreemarkerMap()); List inds = vcResults.getEntities(); @@ -149,13 +146,13 @@ public class IndividualListController extends FreemarkerHttpServlet { return SolrQueryUtils.getPageParameter(request); } - public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context) + public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao) throws SearchException{ try{ List classUris = Collections.singletonList(vclassURI); - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, context, indDao); + IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, indDao); return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha); - } catch (SolrServerException e) { + } catch (SearchEngineException e) { String msg = "An error occurred retrieving results for vclass query"; log.error(msg, e); // Throw this up to processRequest, so the template gets the error message. @@ -166,9 +163,9 @@ public class IndividualListController extends FreemarkerHttpServlet { } } - public static IndividualListResults getResultsForVClassIntersections(List vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context) { + public static IndividualListResults getResultsForVClassIntersections(List vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao) { try{ - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, context, indDao); + IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, indDao); return getResultsForVClassQuery(results, page, pageSize, alpha); } catch(Throwable th) { log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th); @@ -176,10 +173,10 @@ public class IndividualListController extends FreemarkerHttpServlet { } } - public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) { + public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao) { try{ List classUris = Collections.singletonList(vclassURI); - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao); + IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, indDao); return getResultsForVClassQuery(results, page, pageSize, ""); } catch(Throwable th) { log.error("An error occurred retrieving random results for vclass query", th); @@ -189,8 +186,8 @@ public class IndividualListController extends FreemarkerHttpServlet { //TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced //only within DataGetterUtils - public static long getIndividualCount(List vclassUris, IndividualDao indDao, ServletContext context) { - return SolrQueryUtils.getIndividualCount(vclassUris, indDao, context); + public static long getIndividualCount(List vclassUris, IndividualDao indDao) { + return SolrQueryUtils.getIndividualCount(vclassUris, indDao); } private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java index 34c7792cc..337e100f4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java @@ -5,21 +5,19 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker; import java.util.ArrayList; import java.util.List; -import javax.servlet.ServletContext; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; /** * Holds the Individuals that were found in a Solr search query. @@ -37,12 +35,12 @@ public class IndividualListQueryResults { // Convenience method // ---------------------------------------------------------------------- - public static IndividualListQueryResults runQuery(SolrQuery query, - IndividualDao indDao, ServletContext context) - throws SolrServerException { + public static IndividualListQueryResults runQuery(SearchQuery query, + IndividualDao indDao) + throws SearchEngineException { - SolrServer solr = SolrSetup.getSolrServer(context); - QueryResponse response = null; + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchResponse response = null; response = solr.query(query); if (response == null) { @@ -50,7 +48,7 @@ public class IndividualListQueryResults { return EMPTY_RESULT; } - SolrDocumentList docs = response.getResults(); + SearchResultDocumentList docs = response.getResults(); if (docs == null) { log.debug("results from search query response was null"); return EMPTY_RESULT; @@ -61,8 +59,8 @@ public class IndividualListQueryResults { log.debug("Number of search results: " + hitCount); List individuals = new ArrayList(docs.size()); - for (SolrDocument doc : docs) { - String uri = doc.get(VitroSearchTermNames.URI).toString(); + for (SearchResultDocument doc : docs) { + String uri = doc.getStringValue(VitroSearchTermNames.URI); Individual individual = indDao.getIndividualByURI(uri); if (individual == null) { log.debug("No individual for search document with uri = " + uri); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java index 670eeeda3..604db6533 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java @@ -18,23 +18,21 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; - -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; /** * This servlet is for servicing JSON requests from Google Refine's @@ -125,7 +123,7 @@ public class JSONReconcileServlet extends VitroHttpServlet { try { for (int i = 0; i < queries.size(); i++) { - String queryStr = (String) queries.get(i); + String queryStr = queries.get(i); JSONObject json = new JSONObject(queryStr); if (json.has("query")) { // single query @@ -138,7 +136,7 @@ public class JSONReconcileServlet extends VitroHttpServlet { } else { // multiple queries for (Iterator iter = json.keys(); iter.hasNext();) { ArrayList jsonList = new ArrayList(); - String key = (String) iter.next(); + String key = iter.next(); Object obj = json.get(key); JSONObject jsonLvl2 = (JSONObject) obj; if (jsonLvl2.has("query")) { @@ -234,7 +232,7 @@ public class JSONReconcileServlet extends VitroHttpServlet { for (Map.Entry entry : currMap.entrySet()) { JSONObject resultAllJson = new JSONObject(); String key = entry.getKey(); - JSONObject json = (JSONObject) entry.getValue(); + JSONObject json = entry.getValue(); String queryVal = json.getString("query"); // System.out.println("query: " + json.toString()); @@ -274,16 +272,16 @@ public class JSONReconcileServlet extends VitroHttpServlet { JSONArray resultJsonArr = new JSONArray(); // Solr - SolrQuery query = getQuery(queryVal, searchType, limit, propertiesList); - QueryResponse queryResponse = null; + SearchQuery query = getQuery(queryVal, searchType, limit, propertiesList); + SearchResponse queryResponse = null; if (query != null) { - SolrServer solr = SolrSetup.getSolrServer(getServletContext()); + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); queryResponse = solr.query(query); } else { log.error("Query for a search was null"); } - SolrDocumentList docs = null; + SearchResultDocumentList docs = null; if (queryResponse != null) { docs = queryResponse.getResults(); } else { @@ -293,29 +291,16 @@ public class JSONReconcileServlet extends VitroHttpServlet { if (docs != null) { List results = new ArrayList(); - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { try { - String uri = doc.get(VitroSearchTermNames.URI).toString(); - // RY 7/1/2011 - // Comment was: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() returns a list. - // Changed to: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() could return a list - // But in fact: I'm no longer seeing any lists returned for individuals with multiple labels. Not sure - // if this is new behavior or what. ??? - Object nameRaw = doc.get(VitroSearchTermNames.NAME_RAW); - String name = null; - if (nameRaw instanceof List) { - @SuppressWarnings("unchecked") - List nameRawList = (List) nameRaw; - name = nameRawList.get(0); - } else { - name = (String) nameRaw; - } + String uri = doc.getStringValue(VitroSearchTermNames.URI); + String name = doc.getStringValue(VitroSearchTermNames.NAME_RAW); SearchResult result = new SearchResult(name, uri); // populate result for Google Refine JSONObject resultJson = new JSONObject(); - resultJson.put("score", doc.getFieldValue("score")); + resultJson.put("score", doc.getFirstValue("score")); String modUri = result.getUri().replace("#", "%23"); resultJson.put("id", modUri); resultJson.put("name", result.getLabel()); @@ -361,16 +346,16 @@ public class JSONReconcileServlet extends VitroHttpServlet { log.error("JSONException: " + ex); throw new ServletException("JSONReconcileServlet JSONException: " + ex); - } catch (SolrServerException ex) { + } catch (SearchEngineException ex) { log.error("JSONException: " + ex); - throw new ServletException("JSONReconcileServlet SolrServerException: " + throw new ServletException("JSONReconcileServlet SearchEngineException: " + ex); } return qJson; } - protected SolrQuery getQuery(String queryStr, String searchType, int limit, ArrayList propertiesList) { + protected SearchQuery getQuery(String queryStr, String searchType, int limit, ArrayList propertiesList) { if ( queryStr == null) { log.error("There was no parameter '"+ PARAM_QUERY @@ -383,10 +368,10 @@ public class JSONReconcileServlet extends VitroHttpServlet { } /// original - ///SolrQuery query = new SolrQuery(); + ///SearchQuery query = new SearchQuery(); /// test - SolrQuery query = new SolrQuery(queryStr.toLowerCase()); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(queryStr.toLowerCase()); // original code: // query.setStart(0).setRows(DEFAULT_MAX_HIT_COUNT); @@ -403,17 +388,17 @@ public class JSONReconcileServlet extends VitroHttpServlet { } // Added score to original code: - query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, "*", "score"); // fields to retrieve + query.addFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, "*", "score"); // fields to retrieve // if propertiesList has elements, add extra queries to query Iterator it = propertiesList.iterator(); while (it.hasNext()) { String[] pvPair = it.next(); - query.addFilterQuery(tokenizeNameQuery(pvPair[1]), VitroSearchTermNames.RDFTYPE + ":\"" + pvPair[0] + "\""); + query.addFilterQueries(tokenizeNameQuery(pvPair[1]), VitroSearchTermNames.RDFTYPE + ":\"" + pvPair[0] + "\""); } // Can't sort on multivalued field, so we sort the results in Java when we get them. - // query.setSortField(VitroSearchTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc); + // query.addSortField(VitroSearchTermNames.NAME_LOWERCASE, Order.ASC); return query; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java index 6ed8a362e..6af92cf44 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java @@ -113,8 +113,7 @@ public class JsonServlet extends VitroHttpServlet { vclassURIs, page, INDIVIDUALS_PER_PAGE, alpha, - vreq.getWebappDaoFactory().getIndividualDao(), - context); + vreq.getWebappDaoFactory().getIndividualDao()); } catch(Exception ex) { log.error("Error in retrieval of search results for VClass " + vclassURIs.toString(), ex); return IndividualListResults.EMPTY; @@ -149,8 +148,7 @@ public class JsonServlet extends VitroHttpServlet { vclassURI, page, pageSize, - vreq.getWebappDaoFactory().getIndividualDao(), - context); + vreq.getWebappDaoFactory().getIndividualDao()); } catch(Exception ex) { log.error("Error in retrieval of search results for VClass " + vclassURI, ex); return IndividualListResults.EMPTY; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java index 4ea91aed7..5cebc62c0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java @@ -14,12 +14,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.FacetField; -import org.apache.solr.client.solrj.response.FacetField.Count; -import org.apache.solr.client.solrj.response.QueryResponse; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.listeners.StatementListener; @@ -30,6 +24,7 @@ import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; @@ -40,11 +35,17 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField.Count; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexingEventListener; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; +import edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerSetup; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; @@ -188,14 +189,14 @@ public class VClassGroupCache implements IndexingEventListener { int attempts = 0; int maxTries = 3; - SolrServerException exception = null; + SearchEngineException exception = null; while( attempts < maxTries ){ try { attempts++; rebuildCacheUsingSolr(this); break; - } catch (SolrServerException e) { + } catch (SearchEngineException e) { exception = e; try { Thread.sleep(250); } catch (InterruptedException e1) {/*ignore interrupt*/} @@ -203,7 +204,7 @@ public class VClassGroupCache implements IndexingEventListener { } if( exception != null ) - log.error("Could not rebuild cache. " + exception.getRootCause().getMessage() ); + log.error("Could not rebuild cache. " + exception.getCause().getMessage() ); } /** @@ -247,17 +248,13 @@ public class VClassGroupCache implements IndexingEventListener { * * If ProhibitedFromSearch is not found in the context, that will be skipped. * - * @throws SolrServerException if there are problems with the Solr server. + * @throws SearchEngineException if there are problems with the Solr server. */ - protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SolrServerException{ + protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SearchEngineException{ long start = System.currentTimeMillis(); WebappDaoFactory wdFactory = ModelAccess.on(cache.context).getWebappDaoFactory(); - SolrServer solrServer = (SolrServer)cache.context.getAttribute(SolrSetup.SOLR_SERVER); - if( solrServer == null){ - log.error("Unable to rebuild cache: could not get solrServer from ServletContext"); - return; - } + SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); VitroFilters vFilters = VitroFilterUtils.getPublicFilter(cache.context); VClassGroupDao vcgDao = new WebappDaoFactoryFiltering(wdFactory, vFilters).getVClassGroupDao(); @@ -291,7 +288,7 @@ public class VClassGroupCache implements IndexingEventListener { * Removes classes from groups that are prohibited from search. */ protected static void removeClassesHiddenFromSearch(List groups, ServletContext context2) { - ProhibitedFromSearch pfs = (ProhibitedFromSearch)context2.getAttribute(SolrSetup.PROHIBITED_FROM_SEARCH); + ProhibitedFromSearch pfs = (ProhibitedFromSearch)context2.getAttribute(SearchIndexerSetup.PROHIBITED_FROM_SEARCH); if(pfs==null){ log.debug("Could not get ProhibitedFromSearch from ServletContext"); return; @@ -311,10 +308,10 @@ public class VClassGroupCache implements IndexingEventListener { /** * Add the Individual count to classes in groups. - * @throws SolrServerException + * @throws SearchEngineException */ - protected static void addCountsUsingSolr(List groups, SolrServer solrServer) - throws SolrServerException { + protected static void addCountsUsingSolr(List groups, SearchEngine solrServer) + throws SearchEngineException { if( groups == null || solrServer == null ) return; for( VClassGroup group : groups){ @@ -322,23 +319,23 @@ public class VClassGroupCache implements IndexingEventListener { } } - protected static void addClassCountsToGroup(VClassGroup group, SolrServer solrServer) - throws SolrServerException { + protected static void addClassCountsToGroup(VClassGroup group, SearchEngine solrServer) + throws SearchEngineException { if( group == null ) return; String groupUri = group.getURI(); String facetOnField = VitroSearchTermNames.RDFTYPE; - SolrQuery query = new SolrQuery( ). + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(). setRows(0). setQuery(VitroSearchTermNames.CLASSGROUP_URI + ":" + groupUri ). - setFacet(true). //facet on type to get counts for classes in classgroup - addFacetField( facetOnField ). + setFaceting(true). //facet on type to get counts for classes in classgroup + addFacetFields( facetOnField ). setFacetMinCount(0); log.debug("query: " + query); - QueryResponse rsp = solrServer.query(query); + SearchResponse rsp = solrServer.query(query); //Get individual count long individualCount = rsp.getResults().getNumFound(); @@ -346,7 +343,7 @@ public class VClassGroupCache implements IndexingEventListener { group.setIndividualCount((int) individualCount); //get counts for classes - FacetField ff = rsp.getFacetField( facetOnField ); + SearchFacetField ff = rsp.getFacetField( facetOnField ); if( ff != null ){ List counts = ff.getValues(); if( counts != null ){ @@ -407,7 +404,8 @@ public class VClassGroupCache implements IndexingEventListener { this.cache = cache; } - public void run() { + @Override + public void run() { while (!die) { int delay; @@ -425,12 +423,12 @@ public class VClassGroupCache implements IndexingEventListener { log.debug("rebuildGroupCacheThread.run() -- rebuilt cache "); failedAttempts = 0; delay = 100; - } catch (SolrServerException e) { + } catch (SearchEngineException e) { failedAttempts++; if( failedAttempts >= maxFailedAttempts ){ log.error("Could not build VClassGroupCache. " + "Could not connect with Solr after " + - failedAttempts + " attempts.", e.getRootCause()); + failedAttempts + " attempts.", e.getCause()); rebuildRequested = false; failedAttempts = 0; delay = 1000; @@ -479,11 +477,13 @@ public class VClassGroupCache implements IndexingEventListener { * Listen for changes to what class group classes are in and their display rank. */ protected class VClassGroupCacheChangeListener extends StatementListener { - public void addedStatement(Statement stmt) { + @Override + public void addedStatement(Statement stmt) { checkAndDoUpdate(stmt); } - public void removedStatement(Statement stmt) { + @Override + public void removedStatement(Statement stmt) { checkAndDoUpdate(stmt); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java index 75cac343e..472af6204 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java @@ -8,23 +8,21 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; -import javax.servlet.ServletContext; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils; /* @@ -34,13 +32,11 @@ import edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils; public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions implements FieldOptions { private Log log = LogFactory.getLog(IndividualsViaSolrQueryOptions.class); - private ServletContext servletContext; private String subjectUri; private String predicateUri; private String objectUri; - public IndividualsViaSolrQueryOptions(ServletContext context, String inputSubjectUri, String inputPredicateUri, String inputObjectUri, String ... vclassURIs) throws Exception { + public IndividualsViaSolrQueryOptions(String inputSubjectUri, String inputPredicateUri, String inputObjectUri, String ... vclassURIs) throws Exception { super(vclassURIs); - this.servletContext = context; this.subjectUri = inputSubjectUri; this.predicateUri = inputPredicateUri; this.objectUri = inputObjectUri; @@ -50,10 +46,10 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions protected Map getIndividualsForClass(String vclassURI, WebappDaoFactory wDaoFact ){ Map individualMap = new HashMap(); try { - SolrServer solrServer = SolrSetup.getSolrServer(servletContext); + SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); //solr query for type count. - SolrQuery query = new SolrQuery(); + SearchQuery query = solrServer.createQuery(); if( VitroVocabulary.OWL_THING.equals( vclassURI )){ query.setQuery( "*:*" ); }else{ @@ -61,15 +57,15 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions } query.setStart(0) .setRows(1000); - query.setFields(VitroSearchTermNames.URI); // fields to retrieve + query.addFields(VitroSearchTermNames.URI); // fields to retrieve - QueryResponse rsp = solrServer.query(query); - SolrDocumentList docs = rsp.getResults(); + SearchResponse rsp = solrServer.query(query); + SearchResultDocumentList docs = rsp.getResults(); long found = docs.getNumFound(); if(found > 0) { - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { try { - String uri = doc.get(VitroSearchTermNames.URI).toString(); + String uri = doc.getStringValue(VitroSearchTermNames.URI); Individual individual = wDaoFact.getIndividualDao().getIndividualByURI(uri); if (individual == null) { log.debug("No individual for search document with uri = " + uri); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index f6c2f95c1..84c974da2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -5,24 +5,18 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import javax.servlet.http.HttpSession; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocumentList; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Literal; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.VClass; @@ -37,9 +31,13 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaObjectPropetyOptions; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation; import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils; import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode; @@ -175,9 +173,9 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene return types; } - private boolean tooManyRangeOptions(VitroRequest vreq, HttpSession session ) throws SolrServerException { + private boolean tooManyRangeOptions(VitroRequest vreq, HttpSession session ) throws SearchEngineException { List rangeTypes = getRangeTypes(vreq); - SolrServer solrServer = SolrSetup.getSolrServer(session.getServletContext()); + SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); List types = new ArrayList(); for (VClass vclass : rangeTypes) { @@ -194,15 +192,15 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene long count = 0; for( String type:types){ //solr query for type count. - SolrQuery query = new SolrQuery(); + SearchQuery query = solrServer.createQuery(); if( VitroVocabulary.OWL_THING.equals( type )){ query.setQuery( "*:*" ); }else{ query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type); } query.setRows(0); - QueryResponse rsp = solrServer.query(query); - SolrDocumentList docs = rsp.getResults(); + SearchResponse rsp = solrServer.query(query); + SearchResultDocumentList docs = rsp.getResults(); long found = docs.getNumFound(); count = count + found; if( count > maxNonACRangeIndividualCount ) @@ -524,7 +522,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene editConfiguration.setFormSpecificData(formSpecificData); } - public void addFormSpecificDataForAC(EditConfigurationVTwo editConfiguration, VitroRequest vreq, HttpSession session) throws SolrServerException { + public void addFormSpecificDataForAC(EditConfigurationVTwo editConfiguration, VitroRequest vreq, HttpSession session) throws SearchEngineException { HashMap formSpecificData = new HashMap(); //Get the edit mode formSpecificData.put("editMode", getEditMode(vreq).toString().toLowerCase()); @@ -564,19 +562,19 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene editConfiguration.setFormSpecificData(formSpecificData); } - private Object rangeIndividualsExist(HttpSession session, List types) throws SolrServerException { - SolrServer solrServer = SolrSetup.getSolrServer(session.getServletContext()); + private Object rangeIndividualsExist(HttpSession session, List types) throws SearchEngineException { + SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); boolean rangeIndividualsFound = false; for( VClass type:types){ //solr for type count. - SolrQuery query = new SolrQuery(); + SearchQuery query =ApplicationUtils.instance().getSearchEngine().createQuery(); query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type.getURI()); query.setRows(0); - QueryResponse rsp = solrServer.query(query); - SolrDocumentList docs = rsp.getResults(); + SearchResponse rsp = solrServer.query(query); + SearchResultDocumentList docs = rsp.getResults(); if( docs.getNumFound() > 0 ){ rangeIndividualsFound = true; break; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/IndividualsByRankFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/IndividualsByRankFormGenerator.java index c6fa8c0a0..5f6fb8a4d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/IndividualsByRankFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/IndividualsByRankFormGenerator.java @@ -2,47 +2,18 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.*; - import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpSession; - -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocumentList; -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Model; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaObjectPropertyByRankOptions; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaObjectPropetyOptions; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation; -import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; -import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils; -import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode; /** * Generates the edit configuration for a default property form. diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java index 26c8e452d..044de5e31 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java @@ -21,15 +21,15 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.collections.EnumerationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResultsParser; @@ -244,13 +244,12 @@ public class CachingResponseFilter implements Filter { * Ask Solr whether it has an ETAG for this URI. */ private String findEtagForIndividual(String individualUri) { - SolrQuery query = new SolrQuery("URI:" + individualUri) - .setFields(ETAG_FIELD); - - SolrServer solr = SolrSetup.getSolrServer(ctx); + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchQuery query = solr.createQuery("URI:" + individualUri) + .addFields(ETAG_FIELD); try { - QueryResponse response = solr.query(query); + SearchResponse response = solr.query(query); List> maps = new SolrResultsParser(response, parserFieldMap).parse(); log.debug("Solr response for '" + query.getQuery() + "' was " @@ -261,7 +260,7 @@ public class CachingResponseFilter implements Filter { } else { return maps.get(0).get(ETAG_FIELD); } - } catch (SolrServerException e) { + } catch (SearchEngineException e) { log.warn( "Solr query '" + query.getQuery() + "' threw an exception", e); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java index 51958ba45..9a56983e5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java @@ -16,20 +16,20 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; import org.json.JSONArray; import org.json.JSONObject; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; /** * AutocompleteController generates autocomplete content @@ -66,7 +66,7 @@ public class AutocompleteController extends VitroAjaxController { String qtxt = vreq.getParameter(PARAM_QUERY); - SolrQuery query = getQuery(qtxt, vreq); + SearchQuery query = getQuery(qtxt, vreq); if (query == null ) { log.debug("query for '" + qtxt +"' is null."); doNoQuery(response); @@ -74,8 +74,8 @@ public class AutocompleteController extends VitroAjaxController { } log.debug("query for '" + qtxt +"' is " + query.toString()); - SolrServer solr = SolrSetup.getSolrServer(getServletContext()); - QueryResponse queryResponse = solr.query(query); + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchResponse queryResponse = solr.query(query); if ( queryResponse == null) { log.error("Query response for a search was null"); @@ -83,7 +83,7 @@ public class AutocompleteController extends VitroAjaxController { return; } - SolrDocumentList docs = queryResponse.getResults(); + SearchResultDocumentList docs = queryResponse.getResults(); if ( docs == null) { log.error("Docs for a search was null"); @@ -99,33 +99,11 @@ public class AutocompleteController extends VitroAjaxController { } List results = new ArrayList(); - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { try { - String uri = doc.get(VitroSearchTermNames.URI).toString(); - // RY 7/1/2011 - // Comment was: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() returns a list. - // Changed to: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() could return a list - // But in fact: I'm no longer seeing any lists returned for individuals with multiple labels. Not sure - // if this is new behavior or what. ??? - Object nameRaw = doc.get(VitroSearchTermNames.NAME_RAW); - String name = null; - if (nameRaw instanceof List) { - @SuppressWarnings("unchecked") - List nameRawList = (List) nameRaw; - name = nameRawList.get(0); - } else { - name = (String) nameRaw; - } - - Object mostSpecificType = doc.get(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); - String mst = null; - if (mostSpecificType instanceof List) { - @SuppressWarnings("unchecked") - List mstList = (List) mostSpecificType; - mst = mstList.get(0); - } else { - mst = (String) mostSpecificType; - } + String uri = doc.getStringValue(VitroSearchTermNames.URI); + String name = doc.getStringValue(VitroSearchTermNames.NAME_RAW); + String mst = doc.getStringValue(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); SearchResult result = new SearchResult(name, uri, mst); results.add(result); @@ -150,7 +128,7 @@ public class AutocompleteController extends VitroAjaxController { } } - private SolrQuery getQuery(String queryStr, VitroRequest vreq) { + private SearchQuery getQuery(String queryStr, VitroRequest vreq) { if ( queryStr == null) { log.error("There was no parameter '"+ PARAM_QUERY @@ -162,26 +140,26 @@ public class AutocompleteController extends VitroAjaxController { return null; } - SolrQuery query = new SolrQuery(); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(); query.setStart(0) .setRows(DEFAULT_MAX_HIT_COUNT); setNameQuery(query, queryStr, vreq); // Filter by type - String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE); - String multipleTypesParam = (String) vreq.getParameter(PARAM_MULTIPLE_RDFTYPE); + String typeParam = vreq.getParameter(PARAM_RDFTYPE); + String multipleTypesParam = vreq.getParameter(PARAM_MULTIPLE_RDFTYPE); if (typeParam != null) { addFilterQuery(query, typeParam, multipleTypesParam); } - query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); // fields to retrieve + query.addFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); // fields to retrieve // Can't sort on multivalued field, so we sort the results in Java when we get them. - // query.setSortField(VitroSearchTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc); + // query.addSortField(VitroSearchTermNames.NAME_LOWERCASE, Order.ASC); return query; } - private void addFilterQuery(SolrQuery query, String typeParam, String multipleTypesParam) { + private void addFilterQuery(SearchQuery query, String typeParam, String multipleTypesParam) { if(multipleTypesParam == null || multipleTypesParam.equals("null") || multipleTypesParam.isEmpty()) { //Single type parameter, process as usual query.addFilterQuery(VitroSearchTermNames.RDFTYPE + ":\"" + typeParam + "\""); @@ -200,12 +178,12 @@ public class AutocompleteController extends VitroAjaxController { } } - private void setNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) { + private void setNameQuery(SearchQuery query, String queryStr, HttpServletRequest request) { if (StringUtils.isBlank(queryStr)) { log.error("No query string"); } - String tokenizeParam = (String) request.getParameter("tokenize"); + String tokenizeParam = request.getParameter("tokenize"); boolean tokenize = "true".equals(tokenizeParam); // Note: Stemming is only relevant if we are tokenizing: an untokenized name @@ -218,7 +196,7 @@ public class AutocompleteController extends VitroAjaxController { } } - private void setTokenizedNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) { + private void setTokenizedNameQuery(SearchQuery query, String queryStr, HttpServletRequest request) { /* We currently have no use case for a tokenized, unstemmed autocomplete search field, so the option * has been disabled. If needed in the future, will need to add a new field and field type which @@ -262,7 +240,7 @@ public class AutocompleteController extends VitroAjaxController { } - private void setUntokenizedNameQuery(SolrQuery query, String queryStr) { + private void setUntokenizedNameQuery(SearchQuery query, String queryStr) { queryStr = queryStr.trim(); queryStr = makeTermQuery(VitroSearchTermNames.AC_NAME_UNTOKENIZED, queryStr, true); query.setQuery(queryStr); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/DataAutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/DataAutocompleteController.java index a8a26b217..23d7444d1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/DataAutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/DataAutocompleteController.java @@ -5,28 +5,15 @@ package edu.cornell.mannlib.vitro.webapp.search.controller; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import java.io.IOException; -import java.net.URLEncoder; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; import org.json.JSONArray; -import org.json.JSONObject; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.DatasetFactory; @@ -42,10 +29,8 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.ajax.SparqlUtils; -import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; import edu.cornell.mannlib.vitro.webapp.controller.ajax.SparqlUtils.AjaxControllerException; -import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; +import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; /** * DataAutocompleteController generates autocomplete content diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java index 0738a5772..18d827e4b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java @@ -15,9 +15,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -28,7 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Red import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevel; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevelStamp; @@ -160,7 +158,7 @@ public class IndexController extends FreemarkerHttpServlet { private Boolean testIndexConnection() { try { - SolrSetup.getSolrServer(getServletContext()).ping(); + ApplicationUtils.instance().getSearchEngine().ping(); return Boolean.TRUE; } catch (Exception e) { log.error("Can't connect to the Solr server.", e); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index b777733b3..2d052d22b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -21,14 +21,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.response.FacetField; -import org.apache.solr.client.solrj.response.FacetField.Count; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; @@ -47,9 +41,15 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField.Count; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.IndexConstants; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult.IndividualSearchResult; import edu.ucsf.vitro.opensocial.OpenSocialManager; @@ -169,9 +169,9 @@ public class PagedSearchController extends FreemarkerHttpServlet { return doFailedSearch(badQueryMsg, queryText, format, vreq); } - SolrQuery query = getQuery(queryText, hitsPerPage, startIndex, vreq); - SolrServer solr = SolrSetup.getSolrServer(getServletContext()); - QueryResponse response = null; + SearchQuery query = getQuery(queryText, hitsPerPage, startIndex, vreq); + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchResponse response = null; try { response = solr.query(query); @@ -186,7 +186,7 @@ public class PagedSearchController extends FreemarkerHttpServlet { return doFailedSearch(I18n.text(vreq, "error_in_search_request"), queryText, format, vreq); } - SolrDocumentList docs = response.getResults(); + SearchResultDocumentList docs = response.getResults(); if (docs == null) { log.error("Document list for a search was null"); return doFailedSearch(I18n.text(vreq, "error_in_search_request"), queryText,format, vreq); @@ -199,11 +199,11 @@ public class PagedSearchController extends FreemarkerHttpServlet { } List individuals = new ArrayList(docs.size()); - Iterator docIter = docs.iterator(); + Iterator docIter = docs.iterator(); while( docIter.hasNext() ){ try { - SolrDocument doc = docIter.next(); - String uri = doc.get(VitroSearchTermNames.URI).toString(); + SearchResultDocument doc = docIter.next(); + String uri = doc.getStringValue(VitroSearchTermNames.URI); Individual ind = iDao.getIndividualByURI(uri); if(ind != null) { ind.setSearchSnippet( getSnippet(doc, response) ); @@ -353,12 +353,12 @@ public class PagedSearchController extends FreemarkerHttpServlet { * Get the class groups represented for the individuals in the documents. * @param qtxt */ - private List getClassGroupsLinks(VitroRequest vreq, VClassGroupDao grpDao, SolrDocumentList docs, QueryResponse rsp, String qtxt) { + private List getClassGroupsLinks(VitroRequest vreq, VClassGroupDao grpDao, SearchResultDocumentList docs, SearchResponse rsp, String qtxt) { Map cgURItoCount = new HashMap(); List classgroups = new ArrayList( ); - List ffs = rsp.getFacetFields(); - for(FacetField ff : ffs){ + List ffs = rsp.getFacetFields(); + for(SearchFacetField ff : ffs){ if(VitroSearchTermNames.CLASSGROUP_URI.equals(ff.getName())){ List counts = ff.getValues(); for( Count ct: counts){ @@ -388,13 +388,13 @@ public class PagedSearchController extends FreemarkerHttpServlet { return classGroupLinks; } - private List getVClassLinks(VClassDao vclassDao, SolrDocumentList docs, QueryResponse rsp, String qtxt){ + private List getVClassLinks(VClassDao vclassDao, SearchResultDocumentList docs, SearchResponse rsp, String qtxt){ HashSet typesInHits = getVClassUrisForHits(docs); List classes = new ArrayList(typesInHits.size()); Map typeURItoCount = new HashMap(); - List ffs = rsp.getFacetFields(); - for(FacetField ff : ffs){ + List ffs = rsp.getFacetFields(); + for(SearchFacetField ff : ffs){ if(VitroSearchTermNames.RDFTYPE.equals(ff.getName())){ List counts = ff.getValues(); for( Count ct: counts){ @@ -435,9 +435,9 @@ public class PagedSearchController extends FreemarkerHttpServlet { return vClassLinks; } - private HashSet getVClassUrisForHits(SolrDocumentList docs){ + private HashSet getVClassUrisForHits(SearchResultDocumentList docs){ HashSet typesInHits = new HashSet(); - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { try { Collection types = doc.getFieldValues(VitroSearchTermNames.RDFTYPE); if (types != null) { @@ -453,8 +453,8 @@ public class PagedSearchController extends FreemarkerHttpServlet { return typesInHits; } - private String getSnippet(SolrDocument doc, QueryResponse response) { - String docId = doc.get(VitroSearchTermNames.DOCID).toString(); + private String getSnippet(SearchResultDocument doc, SearchResponse response) { + String docId = doc.getStringValue(VitroSearchTermNames.DOCID); StringBuffer text = new StringBuffer(); Map>> highlights = response.getHighlighting(); if (highlights != null && highlights.get(docId) != null) { @@ -466,19 +466,19 @@ public class PagedSearchController extends FreemarkerHttpServlet { return text.toString(); } - private SolrQuery getQuery(String queryText, int hitsPerPage, int startIndex, VitroRequest vreq) { + private SearchQuery getQuery(String queryText, int hitsPerPage, int startIndex, VitroRequest vreq) { // Lowercase the search term to support wildcard searches: Solr applies no text // processing to a wildcard search term. - SolrQuery query = new SolrQuery( queryText ); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(queryText); query.setStart( startIndex ) .setRows(hitsPerPage); // ClassGroup filtering param - String classgroupParam = (String) vreq.getParameter(PARAM_CLASSGROUP); + String classgroupParam = vreq.getParameter(PARAM_CLASSGROUP); // rdf:type filtering param - String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE); + String typeParam = vreq.getParameter(PARAM_RDFTYPE); if ( ! StringUtils.isBlank(classgroupParam) ) { // ClassGroup filtering @@ -487,9 +487,9 @@ public class PagedSearchController extends FreemarkerHttpServlet { query.addFilterQuery(VitroSearchTermNames.CLASSGROUP_URI + ":\"" + classgroupParam + "\""); //with ClassGroup filtering we want type facets - query.add("facet","true"); - query.add("facet.limit","-1"); - query.add("facet.field",VitroSearchTermNames.RDFTYPE); + query.addParameter("facet","true"); + query.addParameter("facet.limit","-1"); + query.addParameter("facet.field",VitroSearchTermNames.RDFTYPE); }else if ( ! StringUtils.isBlank(typeParam) ) { // rdf:type filtering @@ -500,9 +500,9 @@ public class PagedSearchController extends FreemarkerHttpServlet { //with type filtering we don't have facets. }else{ //When no filtering is set, we want ClassGroup facets - query.add("facet","true"); - query.add("facet.limit","-1"); - query.add("facet.field",VitroSearchTermNames.CLASSGROUP_URI); + query.addParameter("facet","true"); + query.addParameter("facet.limit","-1"); + query.addParameter("facet.field",VitroSearchTermNames.CLASSGROUP_URI); } log.debug("Query = " + query.toString()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java index d0e8a5f98..afd4deb30 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java @@ -7,15 +7,16 @@ import java.util.HashSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.client.solrj.response.UpdateResponse; -import org.apache.solr.common.SolrDocumentList; -import org.apache.solr.common.SolrInputDocument; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; @@ -24,7 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualT public class SolrIndexer implements IndexerIface { private final static Log log = LogFactory.getLog(SolrIndexer.class); - protected SolrServer server; + protected SearchEngine server; protected boolean indexing; protected HashSet urisIndexed; protected IndividualToSolrDocument individualToSolrDoc; @@ -48,7 +49,7 @@ public class SolrIndexer implements IndexerIface { */ protected boolean doingFullIndexRebuild = false; - public SolrIndexer( SolrServer server, IndividualToSolrDocument indToDoc){ + public SolrIndexer( SearchEngine server, IndividualToSolrDocument indToDoc){ this.server = server; this.individualToSolrDoc = indToDoc; } @@ -59,15 +60,17 @@ public class SolrIndexer implements IndexerIface { throw new IndexingException("SolrIndexer: must call " + "startIndexing() before index()."); - if( ind == null ) + if( ind == null ) { log.debug("Individual to index was null, ignoring."); + return; + } try{ if( urisIndexed.contains(ind.getURI()) ){ log.debug("already indexed " + ind.getURI() ); return; }else{ - SolrInputDocument solrDoc = null; + SearchInputDocument solrDoc = null; synchronized(this){ urisIndexed.add(ind.getURI()); } @@ -80,16 +83,14 @@ public class SolrIndexer implements IndexerIface { log.debug( solrDoc.toString() ); } - UpdateResponse res = server.add( solrDoc ); - log.debug("response after adding docs to server: "+ res); + server.add( solrDoc ); + log.debug("Added docs to server."); }else{ log.debug("removing from index " + ind.getURI()); removeFromIndex(ind.getURI()); } } - } catch (IOException ex) { - throw new IndexingException(ex.getMessage()); - } catch (SolrServerException ex) { + } catch (SearchEngineException ex) { throw new IndexingException(ex.getMessage()); } } @@ -111,9 +112,7 @@ public class SolrIndexer implements IndexerIface { try { server.deleteById(individualToSolrDoc.getIdForUri(uri)); log.debug("deleted " + " " + uri); - } catch (SolrServerException e) { - log.error( "could not delete individual " + uri, e); - } catch (IOException e) { + } catch (SearchEngineException e) { log.error( "could not delete individual " + uri, e); } } @@ -172,12 +171,9 @@ public class SolrIndexer implements IndexerIface { try { server.deleteByQuery("indexedTime:[ * TO " + reindexStart + " ]"); server.commit(); - } catch (SolrServerException e) { + } catch (SearchEngineException e) { if( ! shutdownRequested ) log.error("could not delete documents from before rebuild.",e); - } catch (IOException e) { - if( ! shutdownRequested ) - log.error("could not delete documents from before rebuild.",e); } } @@ -186,17 +182,17 @@ public class SolrIndexer implements IndexerIface { public long getModified() { long modified = 0; - SolrQuery query = new SolrQuery(); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(); query.setQuery("*:*"); - query.addSortField("indexedTime", SolrQuery.ORDER.desc); + query.addSortField("indexedTime", Order.DESC); try { - QueryResponse rsp = server.query(query); - SolrDocumentList docs = rsp.getResults(); + SearchResponse rsp = server.query(query); + SearchResultDocumentList docs = rsp.getResults(); if(docs!=null){ - modified = (Long)docs.get(0).getFieldValue("indexedTime"); + modified = (Long)docs.get(0).getFirstValue("indexedTime"); } - } catch (SolrServerException e) { + } catch (SearchEngineException e) { log.error(e,e); } @@ -208,16 +204,16 @@ public class SolrIndexer implements IndexerIface { * and returns false on failure to connect to server. */ public boolean isIndexEmpty() { - SolrQuery query = new SolrQuery(); + SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(); query.setQuery("*:*"); try { - QueryResponse rsp = server.query(query); - SolrDocumentList docs = rsp.getResults(); + SearchResponse rsp = server.query(query); + SearchResultDocumentList docs = rsp.getResults(); if(docs==null || docs.size()==0){ return true; } - } catch (SolrServerException e) { - log.error("Could not connect to solr server" ,e.getRootCause()); + } catch (SearchEngineException e) { + log.error("Could not connect to solr server" ,e.getCause()); } return false; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java deleted file mode 100644 index 883418cee..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ /dev/null @@ -1,209 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.search.solr; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.impl.HttpSolrServer; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.vocabulary.OWL; - -import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; -import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; -import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; -import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; -import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; -import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; -import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate; -import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalUriFinders; -import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; -import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnNamespace; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnType; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnTypeNamespace; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeNonFlagVitro; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameBoost; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameFields; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SearchIndexExcluder; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SyncingExcludeBasedOnType; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL; -import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; - -public class SolrSetup implements javax.servlet.ServletContextListener{ - - public static final String SOLR_SERVER = "vitro.local.solr.server"; - public static final String PROHIBITED_FROM_SEARCH = "edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch"; - - /** Exclude from the search index Individuals with types from these namespaces */ - private static final String[] TYPE_NS_EXCLUDES = { - VitroVocabulary.PUBLIC - //if you do OWL.NS here you will exclude all of owl:Thing. - }; - - /** Exclude from the search index individuals who's URIs start with these namespaces. */ - private static final String[] INDIVIDUAL_NS_EXCLUDES={ - VitroVocabulary.vitroURI, - VitroVocabulary.VITRO_PUBLIC, - VitroVocabulary.PSEUDO_BNODE_NS, - OWL.NS - }; - - - /** Individuals of these types will be excluded from the search index */ - private static final String[] OWL_TYPES_EXCLUDES = { - OWL.ObjectProperty.getURI(), - OWL.DatatypeProperty.getURI(), - OWL.AnnotationProperty.getURI() - }; - - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - StartupStatus ss = StartupStatus.getBean(context); - - /* setup the http connection with the solr server */ - String solrServerUrlString = ConfigurationProperties.getBean(sce).getProperty("vitro.local.solr.url"); - if( solrServerUrlString == null ){ - ss.fatal(this, "Could not find vitro.local.solr.url in runtime.properties. "+ - "Vitro application needs a URL of a solr server that it can use to index its data. " + - "It should be something like http://localhost:${port}" + context.getContextPath() + "solr" - ); - return; - } - - try { - HttpSolrServer server; - boolean useMultiPartPost = true; - server = new HttpSolrServer( solrServerUrlString ); - server.setSoTimeout(10000); // socket read timeout - server.setConnectionTimeout(10000); - server.setDefaultMaxConnectionsPerHost(100); - server.setMaxTotalConnections(100); - server.setMaxRetries(1); - - context.setAttribute(SOLR_SERVER, server); - - /* set up the individual to solr doc translation */ - OntModel jenaOntModel = ModelAccess.on(context).getJenaOntModel(); - OntModel displayModel = ModelAccess.on(context).getDisplayModel(); - - /* try to get context attribute DocumentModifiers - * and use that as the start of the list of DocumentModifier - * objects. This allows other ContextListeners to add to - * the basic set of DocumentModifiers. */ - @SuppressWarnings("unchecked") - List modifiersFromContext = - (List)context.getAttribute("DocumentModifiers"); - - /* try to get context attribute SearchIndexExcludes - * and use that as the start of the list of exclude - * objects. This allows other ContextListeners to add to - * the basic set of SearchIndexExcludes . */ - @SuppressWarnings("unchecked") - List searchIndexExcludesFromContext = - (List)context.getAttribute("SearchIndexExcludes"); - - IndividualToSolrDocument indToSolrDoc = - setupTransltion(jenaOntModel, displayModel, - RDFServiceUtils.getRDFServiceFactory(context), - modifiersFromContext, - searchIndexExcludesFromContext); - - /* setup solr indexer */ - SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc); - - // This is where the builder gets the list of places to try to - // get objects to index. It is filtered so that non-public text - // does not get into the search index. - WebappDaoFactory wadf = ModelAccess.on(context).getWebappDaoFactory(); - VitroFilters vf = VitroFilterUtils.getPublicFilter(context); - wadf = new WebappDaoFactoryFiltering(wadf, vf); - - // make objects that will find additional URIs for context nodes etc - RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(context).getRDFService(); - List uriFinders = AdditionalUriFinders.getList(rdfService,wadf.getIndividualDao()); - - // Make the IndexBuilder - IndexBuilder builder = new IndexBuilder( solrIndexer, wadf, uriFinders ); - // Save it to the servlet context so we can access it later in the webapp. - context.setAttribute(IndexBuilder.class.getName(), builder); - - // set up listeners so search index builder is notified of changes to model - ServletContext ctx = sce.getServletContext(); - SearchReindexingListener srl = new SearchReindexingListener( builder ); - ModelContext.registerListenerForChanges(ctx, srl); - - ss.info(this, "Setup of Solr index completed."); - } catch (Throwable e) { - ss.fatal(this, "could not setup local solr server",e); - } - - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - IndexBuilder builder = (IndexBuilder)sce.getServletContext().getAttribute(IndexBuilder.class.getName()); - if( builder != null ) - builder.stopIndexingThread(); - - } - - public static SolrServer getSolrServer(ServletContext ctx){ - return (SolrServer) ctx.getAttribute(SOLR_SERVER); - } - - - public static IndividualToSolrDocument setupTransltion( - OntModel jenaOntModel, - Model displayModel, - RDFServiceFactory rdfServiceFactory, - List modifiersFromContext, - List searchIndexExcludesFromContext - ) { - - /* try to get context attribute DocumentModifiers - * and use that as the start of the list of DocumentModifier - * objects. This allows other ContextListeners to add to - * the basic set of DocumentModifiers. */ - List modifiers = new ArrayList(); - if( modifiersFromContext != null ){ - modifiers.addAll( modifiersFromContext); - } - - modifiers.add( new NameFields( rdfServiceFactory )); - modifiers.add( new NameBoost( 1.2f )); - modifiers.add( new ThumbnailImageURL( rdfServiceFactory )); - - /* try to get context attribute SearchIndexExcludes - * and use that as the start of the list of exclude - * objects. This allows other ContextListeners to add to - * the basic set of SearchIndexExcludes . */ - List excludes = - new ArrayList(); - if( searchIndexExcludesFromContext != null ){ - excludes.addAll(searchIndexExcludesFromContext); - } - - excludes.add(new ExcludeBasedOnNamespace( INDIVIDUAL_NS_EXCLUDES )); - excludes.add(new ExcludeBasedOnTypeNamespace( TYPE_NS_EXCLUDES ) ); - excludes.add(new ExcludeBasedOnType( OWL_TYPES_EXCLUDES) ); - excludes.add(new ExcludeNonFlagVitro() ); - excludes.add( new SyncingExcludeBasedOnType( displayModel ) ); - - return new IndividualToSolrDocument(excludes, modifiers); - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java index 693018358..68e6b88ea 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java @@ -9,16 +9,14 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.SolrInputField; import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.QuerySolutionMap; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.RDFNode; -import com.hp.hpl.jena.rdf.model.ResourceFactory; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; @@ -53,7 +51,7 @@ public class ContextNodeFields implements DocumentModifier{ } @Override - public void modifyDocument(Individual individual, SolrInputDocument doc, StringBuffer addUri) { + public void modifyDocument(Individual individual, SearchInputDocument doc, StringBuffer addUri) { if( individual == null ) return; @@ -65,11 +63,11 @@ public class ContextNodeFields implements DocumentModifier{ /* get text from the context nodes and add the to ALLTEXT */ StringBuffer values = executeQueryForValues(individual, queries); - SolrInputField field = doc.getField(VitroSearchTermNames.ALLTEXT); + SearchInputField field = doc.getField(VitroSearchTermNames.ALLTEXT); if( field == null ){ doc.addField(VitroSearchTermNames.ALLTEXT, values); }else{ - field.addValue(values, field.getBoost()); + field.addValues(values, field.getBoost()); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java index 28259ece6..a3ff1e8bf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java @@ -2,14 +2,13 @@ package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; -import org.apache.solr.common.SolrInputDocument; - import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; /** - * This interface represents an object that can add to a SolrInputDocument. + * This interface represents an object that can add to a SearchInputDocument. */ public interface DocumentModifier { - public void modifyDocument(Individual individual, SolrInputDocument doc, StringBuffer addUri) throws SkipIndividualException; + public void modifyDocument(Individual individual, SearchInputDocument doc, StringBuffer addUri) throws SkipIndividualException; //called to inform the DocumentModifier that the system is shutting down public void shutdown(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java index 9e864f898..7e3ba57ea 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java @@ -7,8 +7,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.solr.common.SolrInputDocument; - import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java index a2f62782c..3a3ca5e71 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java @@ -12,19 +12,20 @@ import java.util.Map.Entry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrInputDocument; import org.joda.time.DateTime; import org.jsoup.Jsoup; import com.hp.hpl.jena.shared.JenaException; import com.hp.hpl.jena.vocabulary.OWL; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; @@ -46,7 +47,7 @@ public class IndividualToSolrDocument { } @SuppressWarnings("static-access") - public SolrInputDocument translate(Individual ind) throws IndexingException{ + public SearchInputDocument translate(Individual ind) throws IndexingException{ try{ String excludeMsg = checkExcludes( ind ); if( excludeMsg != DONT_EXCLUDE){ @@ -54,7 +55,7 @@ public class IndividualToSolrDocument { return null; } - SolrInputDocument doc = new SolrInputDocument(); + SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument(); //DocID doc.addField(term.DOCID, getIdForUri( ind.getURI() ) ); @@ -79,7 +80,7 @@ public class IndividualToSolrDocument { addObjectPropertyText(ind, doc, objectNames, addUri); //time of index in msec past epoch - doc.addField(term.INDEXEDTIME, new Long( (new DateTime()).getMillis() ) ); + doc.addField(term.INDEXEDTIME, (Object) new DateTime().getMillis() ); addAllText( ind, doc, classPublicNames, objectNames ); @@ -125,7 +126,7 @@ public class IndividualToSolrDocument { protected Map docModClassToTime = new HashMap(); protected long docModCount =0; - protected void runAdditionalDocModifers( Individual ind, SolrInputDocument doc, StringBuffer addUri ) + protected void runAdditionalDocModifers( Individual ind, SearchInputDocument doc, StringBuffer addUri ) throws SkipIndividualException{ //run the document modifiers if( documentModifiers != null && !documentModifiers.isEmpty()){ @@ -158,7 +159,7 @@ public class IndividualToSolrDocument { } } - protected void addAllText(Individual ind, SolrInputDocument doc, StringBuffer classPublicNames, StringBuffer objectNames) { + protected void addAllText(Individual ind, SearchInputDocument doc, StringBuffer classPublicNames, StringBuffer objectNames) { String t=null; //ALLTEXT, all of the 'full text' StringBuffer allTextValue = new StringBuffer(); @@ -209,7 +210,7 @@ public class IndividualToSolrDocument { * Get the rdfs:labes for objects of statements and put in objectNames. * Get the URIs for objects of statements and put in addUri. */ - protected void addObjectPropertyText(Individual ind, SolrInputDocument doc, + protected void addObjectPropertyText(Individual ind, SearchInputDocument doc, StringBuffer objectNames, StringBuffer addUri) { try{ @@ -245,7 +246,7 @@ public class IndividualToSolrDocument { * @returns true if prohibited from search * @throws SkipIndividualException */ - protected void addClasses(Individual ind, SolrInputDocument doc, StringBuffer classPublicNames) throws SkipIndividualException{ + protected void addClasses(Individual ind, SearchInputDocument doc, StringBuffer classPublicNames) throws SkipIndividualException{ ArrayList superClassNames = null; List vclasses = ind.getVClasses(false); @@ -279,7 +280,7 @@ public class IndividualToSolrDocument { } } - protected void addMostSpecificTypeUris(Individual ind, SolrInputDocument doc){ + protected void addMostSpecificTypeUris(Individual ind, SearchInputDocument doc){ List mstURIs = ind.getMostSpecificTypeURIs(); if( mstURIs != null ){ for( String typeURI : mstURIs ){ @@ -289,7 +290,7 @@ public class IndividualToSolrDocument { } } - protected void addLabel(Individual ind, SolrInputDocument doc) { + protected void addLabel(Individual ind, SearchInputDocument doc) { String value = ""; String label = ind.getRdfsLabel(); if (label != null) { @@ -324,8 +325,8 @@ public class IndividualToSolrDocument { public Individual unTranslate(Object result) { Individual ent = null; - if( result != null && result instanceof SolrDocument){ - SolrDocument hit = (SolrDocument) result; + if( result instanceof SearchResultDocument){ + SearchResultDocument hit = (SearchResultDocument) result; String uri= (String) hit.getFirstValue(term.URI); ent = new IndividualImpl(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java index 1b0613b99..83a23bde6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java @@ -2,10 +2,9 @@ package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.SolrInputField; - import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class NameBoost implements DocumentModifier { @@ -27,11 +26,11 @@ public class NameBoost implements DocumentModifier { } @Override - public void modifyDocument(Individual individual, SolrInputDocument doc, + public void modifyDocument(Individual individual, SearchInputDocument doc, StringBuffer addUri) { for( String fieldName : fieldsToBoost){ - SolrInputField field = doc.getField(fieldName); + SearchInputField field = doc.getField(fieldName); if( field != null ){ field.setBoost(field.getBoost() + boost); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java index d4619b92a..f2943038f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java @@ -8,9 +8,9 @@ import java.io.InputStreamReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.SolrInputDocument; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ResultFormat; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; @@ -31,7 +31,7 @@ public class NameFields implements DocumentModifier { } @Override - public void modifyDocument(Individual ind, SolrInputDocument doc, + public void modifyDocument(Individual ind, SearchInputDocument doc, StringBuffer addUri) throws SkipIndividualException { if( ind == null || ind.getURI() == null ){ return; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java index 23e96c08e..5a138e04c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java @@ -2,9 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; -import org.apache.solr.common.SolrInputDocument; - import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class SourceInstitution implements DocumentModifier { @@ -22,7 +21,7 @@ public class SourceInstitution implements DocumentModifier { } @Override - public void modifyDocument(Individual individual, SolrInputDocument doc, + public void modifyDocument(Individual individual, SearchInputDocument doc, StringBuffer addUri) throws SkipIndividualException { doc.addField(VitroSearchTermNames.SITE_URL, siteURL); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java index 1517983aa..7b6a054d7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java @@ -9,13 +9,13 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.common.SolrInputDocument; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; @@ -45,7 +45,7 @@ public class ThumbnailImageURL implements DocumentModifier { } @Override - public void modifyDocument(Individual individual, SolrInputDocument doc, + public void modifyDocument(Individual individual, SearchInputDocument doc, StringBuffer addUri) throws SkipIndividualException { //add a field for storing the location of thumbnail for the individual. @@ -56,7 +56,7 @@ public class ThumbnailImageURL implements DocumentModifier { /** * Adds if the individual has a thumbnail image or not. */ - protected void addThumbnailExistence(Individual ind, SolrInputDocument doc) { + protected void addThumbnailExistence(Individual ind, SearchInputDocument doc) { try{ if(ind.hasThumb()) doc.addField(THUMBNAIL, "1"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java index a5fff0582..d60c6928a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java @@ -9,8 +9,6 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import org.apache.solr.client.solrj.impl.HttpSolrServer; - import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.OWL; @@ -23,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; @@ -75,7 +74,7 @@ public class SearchIndexerSetup implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(context); - HttpSolrServer server = (HttpSolrServer) ApplicationUtils.instance().getSearchEngine(); + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); try { /* set up the individual to solr doc translation */ @@ -107,7 +106,7 @@ public class SearchIndexerSetup implements ServletContextListener { modifiersFromContext, searchIndexExcludesFromContext); /* setup solr indexer */ - SolrIndexer solrIndexer = new SolrIndexer(server, indToSolrDoc); + SolrIndexer solrIndexer = new SolrIndexer(searchEngine, indToSolrDoc); // This is where the builder gets the list of places to try to // get objects to index. It is filtered so that non-public text diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java index f8aa99ce1..00b845bd8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java @@ -8,7 +8,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; @@ -56,7 +55,7 @@ public class DataGetterUtils { * exception if a page has PageDataGetters. */ public static List getDataGettersForPage(VitroRequest vreq, Model displayModel, String pageURI) - throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException { + throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException { if( vreq.getAttribute(DATA_GETTERS_FOR_PAGE) != null){ return (List) vreq.getAttribute(DATA_GETTERS_FOR_PAGE); @@ -74,7 +73,7 @@ public class DataGetterUtils { * This allows the individual profile for an individual of a specific class to be returned . */ public static List getDataGettersForClass( VitroRequest vreq, Model displayModel, String classURI) - throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException{ + throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException { List dgUris = getDataGetterURIsForAssociatedURI( displayModel, classURI); List dgList = dataGettersForURIs(vreq, displayModel, dgUris); log.debug("getDataGettersForClass: " + dgList); @@ -86,7 +85,7 @@ public class DataGetterUtils { * @param templateName a filename like "index.ftl", which will be used as a URI like "freemarker:index.ftl". */ public static List getDataGettersForTemplate( VitroRequest vreq, Model displayModel, String templateName) - throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException{ + throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, SecurityException, InvocationTargetException { String templateUri = "freemarker:" + templateName; List dgUris = getDataGetterURIsForAssociatedURI( displayModel, templateUri); List dgList = dataGettersForURIs(vreq, displayModel, dgUris); @@ -197,7 +196,7 @@ public class DataGetterUtils { }finally{ displayModel.leaveCriticalSection(); } - return chooseType( types, displayModel, dataGetterURI); + return chooseType( types, dataGetterURI); } @@ -229,7 +228,7 @@ public class DataGetterUtils { return dgURIs; } - private static String chooseType(List types, Model displayModel, String dataGetterURI) throws IllegalAccessException { + private static String chooseType(List types, String dataGetterURI) throws IllegalAccessException { //currently just get the first one that is not owl:Thing for(String type : types){ if( ! StringUtils.isEmpty( type ) && !type.equals( OWL.Thing.getURI() )) @@ -270,8 +269,8 @@ public class DataGetterUtils { /** * Get Individual count for Solr query for intersection of multiple classes */ - public static long getIndividualCountForIntersection(VitroRequest vreq, ServletContext context, List classUris) { - return IndividualListController.getIndividualCount(classUris, vreq.getWebappDaoFactory().getIndividualDao(), context); + public static long getIndividualCountForIntersection(VitroRequest vreq, List classUris) { + return IndividualListController.getIndividualCount(classUris, vreq.getWebappDaoFactory().getIndividualDao()); } //Return data getter type to be employed in display model @@ -410,7 +409,7 @@ public class DataGetterUtils { /* * Copied from JSONServlet as expect this to be related to VitroClassGroup */ - public static JSONObject processVClassGroupJSON(VitroRequest vreq, ServletContext context, VClassGroup vcg) { + public static JSONObject processVClassGroupJSON(VClassGroup vcg) { JSONObject map = new JSONObject(); try { ArrayList classes = new ArrayList(vcg.size()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java index 45c4a3eba..7e4aa1d34 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java @@ -163,7 +163,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D protected void processClassesAndRestrictions(VitroRequest vreq, ServletContext context, HashMap data, List classes, List restrictClasses ) { processClassesForDisplay(vreq, context, data, classes); - processRestrictionClasses(vreq, context, data, restrictClasses); + processRestrictionClasses(vreq, data, restrictClasses); processIntersections(vreq, context, data); } @@ -217,7 +217,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D for(VClass r: restrictClasses) { classUris.add(r.getURI()); } - long count = DataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris); + long count = DataGetterUtils.getIndividualCountForIntersection(vreq, classUris); return new Long(count).intValue(); } @@ -254,7 +254,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D data.put("vClassGroup", classesGroup); } - private void processRestrictionClasses(VitroRequest vreq, ServletContext context, + private void processRestrictionClasses(VitroRequest vreq, HashMap data, List restrictClasses) { try { VClassGroup restrictClassesGroup = new VClassGroup(); @@ -305,7 +305,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D } } - public static VClassGroupTemplateModel getClassGroup(String classGroupUri, ServletContext context, VitroRequest vreq){ + public static VClassGroupTemplateModel getClassGroup(String classGroupUri, VitroRequest vreq){ VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq); List vcgList = vcgc.getGroups(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java index cb5e89c67..cf8431ade 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java @@ -176,8 +176,7 @@ public class SolrIndividualsDataGetter extends DataGetterBase implements DataGet vclass.getURI(), page, alpha, - vreq.getWebappDaoFactory().getIndividualDao(), - vreq.getSession().getServletContext()); + vreq.getWebappDaoFactory().getIndividualDao()); body.putAll(vcResults.asFreemarkerMap()); List inds = vcResults.getEntities(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java index 924a5cd58..6b7227744 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java @@ -7,21 +7,20 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; - import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListQueryResults; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; /** * Some static method to help in constructing Solr queries and parsing the @@ -63,7 +62,7 @@ public class SolrQueryUtils { * the result, according to the fieldMap. */ public static List> parseResponse( - QueryResponse queryResponse, FieldMap fieldMap) { + SearchResponse queryResponse, FieldMap fieldMap) { return new SolrResultsParser(queryResponse, fieldMap).parse(); } @@ -75,7 +74,7 @@ public class SolrQueryUtils { * the result, according to the fieldMap. */ public static List> parseAndFilterResponse( - QueryResponse queryResponse, FieldMap fieldMap, + SearchResponse queryResponse, FieldMap fieldMap, SolrResponseFilter filter, int maxNumberOfResults) { return new SolrResultsParser(queryResponse, fieldMap) .parseAndFilterResponse(filter, maxNumberOfResults); @@ -139,12 +138,12 @@ public class SolrQueryUtils { } //Get count of individuals without actually getting the results - public static long getIndividualCount(List vclassUris, IndividualDao indDao, ServletContext context) { - SolrQuery query = new SolrQuery(makeMultiClassQuery(vclassUris)); + public static long getIndividualCount(List vclassUris, IndividualDao indDao) { + SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchQuery query = solr.createQuery(makeMultiClassQuery(vclassUris)); query.setRows(0); try { - SolrServer solr = SolrSetup.getSolrServer(context); - QueryResponse response = null; + SearchResponse response = null; response = solr.query(query); return response.getResults().getNumFound(); } catch(Exception ex) { @@ -157,8 +156,9 @@ public class SolrQueryUtils { * builds a query with a type clause for each type in vclassUris, NAME_LOWERCASE filetred by * alpha, and just the hits for the page for pageSize. */ - public static SolrQuery getQuery(List vclassUris, String alpha, int page, int pageSize){ + public static SearchQuery getQuery(List vclassUris, String alpha, int page, int pageSize){ String queryText = ""; + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); try { queryText = makeMultiClassQuery(vclassUris); @@ -168,31 +168,32 @@ public class SolrQueryUtils { queryText += VitroSearchTermNames.NAME_LOWERCASE + ":" + alpha.toLowerCase() + "*"; } - SolrQuery query = new SolrQuery(queryText); + SearchQuery query = searchEngine.createQuery(queryText); //page count starts at 1, row count starts at 0 int startRow = (page-1) * pageSize ; query.setStart( startRow ).setRows( pageSize ); // Need a single-valued field for sorting - query.setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, SolrQuery.ORDER.asc); + query.addSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, Order.ASC); log.debug("Query is " + query.toString()); return query; } catch (Exception ex){ log.error("Could not make Solr query",ex); - return new SolrQuery(); + return searchEngine.createQuery(); } } - public static SolrQuery getRandomQuery(List vclassUris, int page, int pageSize){ + public static SearchQuery getRandomQuery(List vclassUris, int page, int pageSize){ String queryText = ""; + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); - try { + try { queryText = makeMultiClassQuery(vclassUris); log.debug("queryText is " + queryText); - SolrQuery query = new SolrQuery(queryText); + SearchQuery query = searchEngine.createQuery(queryText); //page count starts at 1, row count starts at 0 query.setStart( page ).setRows( pageSize ); @@ -202,7 +203,7 @@ public class SolrQueryUtils { } catch (Exception ex){ log.error("Could not make the Solr query",ex); - return new SolrQuery(); + return searchEngine.createQuery(); } } @@ -221,11 +222,10 @@ public class SolrQueryUtils { } public static IndividualListQueryResults buildAndExecuteVClassQuery( - List vclassURIs, String alpha, int page, int pageSize, - ServletContext context, IndividualDao indDao) - throws SolrServerException { - SolrQuery query = SolrQueryUtils.getQuery(vclassURIs, alpha, page, pageSize); - IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao, context); + List vclassURIs, String alpha, int page, int pageSize, IndividualDao indDao) + throws SearchEngineException { + SearchQuery query = SolrQueryUtils.getQuery(vclassURIs, alpha, page, pageSize); + IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao); log.debug("Executed solr query for " + vclassURIs); if (results.getIndividuals().isEmpty()) { log.debug("entities list is null for vclass " + vclassURIs); @@ -234,11 +234,10 @@ public class SolrQueryUtils { } public static IndividualListQueryResults buildAndExecuteRandomVClassQuery( - List vclassURIs, int page, int pageSize, - ServletContext context, IndividualDao indDao) - throws SolrServerException { - SolrQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize); - IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao, context); + List vclassURIs, int page, int pageSize, IndividualDao indDao) + throws SearchEngineException { + SearchQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize); + IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao); log.debug("Executed solr query for " + vclassURIs); if (results.getIndividuals().isEmpty()) { log.debug("entities list is null for vclass " + vclassURIs); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java index 30b591c9d..4904489c3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java @@ -9,9 +9,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; + +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; /** * Parse this Solr response, creating a map of values for each document. @@ -22,10 +23,10 @@ import org.apache.solr.common.SolrDocumentList; public class SolrResultsParser { private static final Log log = LogFactory.getLog(SolrResultsParser.class); - private final QueryResponse queryResponse; + private final SearchResponse queryResponse; private final Map fieldNameMapping; - public SolrResultsParser(QueryResponse queryResponse, FieldMap fieldMap) { + public SolrResultsParser(SearchResponse queryResponse, FieldMap fieldMap) { this.queryResponse = queryResponse; this.fieldNameMapping = fieldMap.map(); } @@ -41,14 +42,14 @@ public class SolrResultsParser { return maps; } - SolrDocumentList docs = queryResponse.getResults(); + SearchResultDocumentList docs = queryResponse.getResults(); if (docs == null) { log.debug("Docs for a search was null"); return maps; } log.debug("Total number of hits = " + docs.getNumFound()); - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { maps.add(parseSingleDocument(doc)); } @@ -69,14 +70,14 @@ public class SolrResultsParser { return maps; } - SolrDocumentList docs = queryResponse.getResults(); + SearchResultDocumentList docs = queryResponse.getResults(); if (docs == null) { log.debug("Docs for a search was null"); return maps; } log.debug("Total number of hits = " + docs.getNumFound()); - for (SolrDocument doc : docs) { + for (SearchResultDocument doc : docs) { Map map = parseSingleDocument(doc); if (filter.accept(map)) { maps.add(map); @@ -92,7 +93,7 @@ public class SolrResultsParser { /** * Create a map from this document, applying translation on the field names. */ - private Map parseSingleDocument(SolrDocument doc) { + private Map parseSingleDocument(SearchResultDocument doc) { Map result = new HashMap(); for (String solrFieldName : fieldNameMapping.keySet()) { String jsonFieldName = fieldNameMapping.get(solrFieldName); @@ -106,8 +107,8 @@ public class SolrResultsParser { /** * Find a single value in the document */ - private String parseSingleValue(SolrDocument doc, String key) { - Object rawValue = getFirstValue(doc.get(key)); + private String parseSingleValue(SearchResultDocument doc, String key) { + Object rawValue = doc.getFirstValue(key); if (rawValue == null) { return ""; @@ -118,20 +119,4 @@ public class SolrResultsParser { return String.valueOf(rawValue); } - /** - * The result might be a list. If so, get the first element. - */ - private Object getFirstValue(Object rawValue) { - if (rawValue instanceof List) { - List list = (List) rawValue; - if (list.isEmpty()) { - return null; - } else { - return list.get(0); - } - } else { - return rawValue; - } - } - } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServletTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServletTest.java index 3677d62ef..8e5814b24 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServletTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServletTest.java @@ -10,18 +10,19 @@ import java.util.regex.PatternSyntaxException; import javax.servlet.ServletException; -import org.apache.solr.client.solrj.SolrQuery; - import org.json.JSONException; import org.json.JSONObject; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub; +import stubs.javax.servlet.ServletContextStub; import stubs.javax.servlet.http.HttpServletRequestStub; import stubs.javax.servlet.http.HttpServletResponseStub; - import edu.cornell.mannlib.vitro.testing.AbstractTestClass; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; /** * Tests on various methods in the class. @@ -36,6 +37,8 @@ public class JSONReconcileServletTest extends AbstractTestClass { @Before public void setup() throws Exception { + ApplicationStub.setup(new ServletContextStub(), new SearchEngineStub()); + request = new HttpServletRequestStub(); request.setRequestUrl(new URL("http://vivo.this.that/reconcile")); request.setMethod("POST"); @@ -78,23 +81,17 @@ public class JSONReconcileServletTest extends AbstractTestClass { propertiesList.add(properties); // test getQuery - SolrQuery solrQuery = reconcile.getQuery(nameStr, nameType, rowNum, propertiesList); + SearchQuery searchQuery = reconcile.getQuery(nameStr, nameType, rowNum, propertiesList); String messagePrefix = "Query should contain the text: "; - testAssertTrue(messagePrefix + orgStr, orgStr, solrQuery.toString()); - testAssertTrue(messagePrefix + nameStr, nameStr, solrQuery.toString()); - testAssertTrue(messagePrefix + orgType, orgType, solrQuery.toString()); - testAssertTrue(messagePrefix + nameType, orgType, solrQuery.toString()); + testAssertTrue(messagePrefix + orgStr, orgStr, searchQuery.toString()); + testAssertTrue(messagePrefix + nameStr, nameStr, searchQuery.toString()); + testAssertTrue(messagePrefix + orgType, orgType, searchQuery.toString()); + testAssertTrue(messagePrefix + nameType, orgType, searchQuery.toString()); } private void testAssertTrue(String message, String inputStr, String resultStr) { try { - String modStr = null; - if (inputStr.contains(":") && inputStr.contains("/")) { - modStr = inputStr.replaceAll(":", "%3A").replaceAll("/", "%2F"); - } else { - modStr = inputStr; - } - Pattern regex = Pattern.compile(modStr, Pattern.CASE_INSENSITIVE); + Pattern regex = Pattern.compile(inputStr, Pattern.CASE_INSENSITIVE); Matcher regexMatcher = regex.matcher(resultStr); Assert.assertTrue(message, regexMatcher.find()); } catch (PatternSyntaxException e) { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java index 9128b6f0e..558179317 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java @@ -20,16 +20,16 @@ import org.junit.Test; import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub; import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub; import stubs.javax.servlet.ServletConfigStub; import stubs.javax.servlet.ServletContextStub; import stubs.javax.servlet.http.HttpServletRequestStub; import stubs.javax.servlet.http.HttpServletResponseStub; import stubs.javax.servlet.http.HttpSessionStub; -import stubs.org.apache.solr.client.solrj.SolrServerStub; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; /** * TODO @@ -85,7 +85,7 @@ public class JsonServletTest extends AbstractTestClass { private WebappDaoFactoryStub wadf; private VClassDaoStub vcDao; - private SolrServerStub solr; + private SearchEngineStub solr; @Before public void setup() throws ServletException { @@ -112,8 +112,8 @@ public class JsonServletTest extends AbstractTestClass { vcDao = new VClassDaoStub(); wadf.setVClassDao(vcDao); - solr = new SolrServerStub(); - ctx.setAttribute(SolrSetup.SOLR_SERVER, solr); + solr = new SearchEngineStub(); + ApplicationStub.setup(new ServletContextStub(), solr); } @Test diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java deleted file mode 100644 index 69c50f53e..000000000 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java +++ /dev/null @@ -1,327 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.core.CoreContainer; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.xml.sax.SAXException; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.ResIterator; -import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.util.FileManager; - -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; -import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle; -import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; -import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; - -/** - * This tests what results will be returned for queries to the - * Solr service. - * - * The test will setup a temporary Solr service, setup a temporary RDF store, load the - * store with some individuals, and then index the individuals in the store. - * - * Once this is done a set of test queries will be run against that service. - * - * This code is based on a similar test from the CUL Discovery and Access - * integration layer. - * - * All RDF/XML files in webapp/test/testontologies/SolrQueryTestRDF will be - * loaded into the model. - */ - -//ignored for now since the solr directory isn't yet found when running from vivo. -@Ignore -public class SolrQueryTest extends AbstractTestClass { - /** Key of system property for build directory. */ - final static String buildDirSystemPropertyKey = "vitro.build.dir"; - - /** Solr index to run test queries on. */ - static SolrServer solr = null; - - /** Container for solr */ - static CoreContainer coreContainer = null; - - /** Folder to store the temporary Solr index. */ - public static TemporaryFolder solrIndexFolder = null; - - /** - * This test needs to load RDF data to use as a - * source of individuals to to build documents. - * This is relative to the build directory. - */ - final static String testRDFDir = - "/webapp/test/testontologies/SolrQueryTestRDF"; - - @Before - public void setup() throws Exception{ - //solr makes a lot of output - suppressSysout(); - suppressSyserr(); - - File buildDir = findBuildDir(); - - solrIndexFolder = new TemporaryFolder(); - solrIndexFolder.create(); - - File tempSolrBase = solrIndexFolder.newFolder("tempSolrBase"); - FileUtils.copyDirectory(getSolrTemplateDir(buildDir), tempSolrBase ); - solr = setupSolr( tempSolrBase ); - - indexRdf( loadTestRDF( buildDir ) ); - } - - @After - public void takedown() throws Exception{ - if( coreContainer != null ) - coreContainer.shutdown(); - - restoreOutputStreams(); - - if( solrIndexFolder != null ) - solrIndexFolder.delete(); - } - - /** - * This will return the directory to use as the Solr - * home template directory. - * - * Throws an exception if the directory is not found. - * @param buildDir - must not be null, must be the base of the build. - */ - private File getSolrTemplateDir(File buildDir) throws Exception { - if(buildDir == null || !buildDir.exists() ) - throw new Exception("buildDir must not be null"); - - String solrTemplateDirName = buildDir.getAbsolutePath() + "/solr/homeDirectoryTemplate"; - File solrTemplateDir = new File(solrTemplateDirName); - - if( solrTemplateDir == null || ! solrTemplateDir.exists()) - throw new Exception("Solr home directory template " + - "was not found at " + solrTemplateDirName); - else - return solrTemplateDir; - } - - protected SolrServer setupSolr(File solrBase) - throws ParserConfigurationException, IOException, SAXException{ - System.setProperty("solr.solr.home", solrBase.getAbsolutePath()); - CoreContainer.Initializer initializer = new CoreContainer.Initializer(); - coreContainer = initializer.initialize(); - return new EmbeddedSolrServer(coreContainer, ""); - } - - private OntModel loadTestRDF(File buildDir) throws Exception { - String dirname = buildDir.getAbsolutePath() + testRDFDir; - File rdfDir = new File( dirname ); - assertNotNull("could not find dir " + dirname , rdfDir); - assertTrue(dirname + " must be a directory." ,rdfDir.isDirectory()); - - //load all files in test dir. - File[] files = rdfDir.listFiles(); - assertNotNull("no test RDF files found",files); - assertTrue("no test RDF files found", files.length > 0 ); - - OntModel model = ModelFactory.createOntologyModel(); - for (File file : files ){ - InputStream in = FileManager.get().open( file.getAbsolutePath() ); - assertNotNull("Could not load file " + file.getAbsolutePath(), in ); - try{ - if( file.getName().endsWith(".rdf") ){ - model.read(in,null); - }else if( file.getName().endsWith(".n3")){ - model.read(in,null,"N3"); - }else if( file.getName().endsWith(".nt")){ - model.read(in,null,"N-TRIPLE"); - }else if( file.getName().endsWith(".ttl")){ - model.read(in,null,"TURTLE"); - }else{ - throw new Exception("Format unknown for file name " + file.getName()); - } - }catch(Throwable th){ - throw new Exception( "Could not load RDF file " - + file.getAbsolutePath() , th); - } - } - return model ; - } - - /** - * Find the base of the build directories. - * @return This method will return a non-null file to use - * or it will throw an exception if none can be found. - * @throws Exception - */ - private File findBuildDir() throws Exception { - - //First try to find the base directory - //of the build in the system properties. - - String buildDirName = System.getProperty(buildDirSystemPropertyKey); - if( buildDirName != null ){ - File buildDir = new File(buildDirName); - if( buildDir.exists() && buildDir.isDirectory() ){ - return buildDir; - } - } - - //If there is no system property try to - //guess the location based on the working directory - File f = null; - String[] fallBackBases = {"","../","../../"}; - List attempted = new ArrayList(); - for( String base: fallBackBases){ - String attemptedDir =base + "solr/homeDirectoryTemplate"; - f = new File( attemptedDir ); - attempted.add( System.getProperty("user.dir") + '/' + attemptedDir ); - if( f != null && f.exists() && f.isDirectory() ){ - f = new File( base ); - break; - }else{ - f = null; - } - } - - if( f == null ){ - throw new Exception( - "Could not find the base of the " + - "build directory for the project, " + - "checked the system property " + buildDirSystemPropertyKey - + " and checked in these locations: \n" + - StringUtils.join(attempted,"\n ")); - }else{ - return f; - } - } - - - /** Query the RDF, build Solr Documents from results, load them to Solr. */ - private void indexRdf(OntModel model) throws Exception { - RDFServiceModel rdfService = new RDFServiceModel(model); - - IndividualToSolrDocument r2d = - SolrSetup.setupTransltion( - model, - model, - new RDFServiceFactorySingle(rdfService), - null, null); - - WebappDaoFactory wdf = new WebappDaoFactoryJena(model); - - for( String uri: getURISToIndex( model ) ){ - SolrInputDocument doc; - try { - doc = r2d.translate( wdf.getIndividualDao().getIndividualByURI(uri)); - } catch (Exception e) { - throw new Exception("Failed on building document for uri:" + uri, e); - } - try { - solr.add( doc ); - } catch (Exception e) { - throw new Exception("Failed adding doc to solr for uri:" + uri, e); - } - } - solr.commit(); - } - - private List getURISToIndex(Model model) { - //just return all the URIs in the subject position - List uris = new LinkedList(); - ResIterator it = model.listSubjects(); - while(it.hasNext() ){ - Resource res = it.nextResource(); - if( res != null && res.isURIResource() ){ - uris.add( res.getURI() ); - } - } - return uris; - } - - /** - * Test that a document with the given URIs are in the results for the query. - * @throws SolrServerException */ - void testQueryGetsDocs(String errmsg, SolrQuery query, String[] expectedUris) throws SolrServerException{ - assertNotNull(errmsg + " but query was null", query); - assertNotNull(errmsg + " but expected URIs was null", expectedUris ); - - QueryResponse resp = solr.query(query); - if( resp == null ) - fail( errmsg + " but Could not get a solr response"); - - Set uris = new HashSet(Arrays.asList( expectedUris )); - for( SolrDocument doc : resp.getResults()){ - assertNotNull(errmsg + ": solr doc was null", doc); - String uri = (String) doc.getFirstValue( VitroSearchTermNames.URI ); - assertNotNull(errmsg+": no URI field in solr doc" , uri); - uris.remove( uri ); - } - if( uris.size() > 0){ - String errorMsg = - "\nThe query '"+ query + "' was expected " + - "to return the following URIs but did not:"; - for( String uri : uris){ - errorMsg= errorMsg+"\n" + uri; - } - - fail( errmsg + errorMsg); - } - } - - @Test - public void testSolrWasStarted() throws SolrServerException, IOException { - assertNotNull( solr ); - solr.ping();//this will throw an exception of the server is not reachable - } - - @Test - public void testCorsonSearch() throws SolrServerException{ - - /* make sure that we have the document in the index before we do anything */ - SolrQuery query = new SolrQuery().setQuery("corson"); - - testQueryGetsDocs("Expect to find a doc when searching for 'corson'", - query,new String[]{ "http://vivo.cornell.edu/individual/individual22972" } ) ; - } - - @Test - public void testFormFeed() throws SolrServerException{ - /* make sure that we have the document in the index before we do anything */ - SolrQuery query = new SolrQuery().setQuery("vivo15"); - - testQueryGetsDocs("Expect to find a doc when searching for 'vivo15'", - query,new String[]{ "http://vivo.cornell.edu/individual/individualIssueVivo15" } ) ; - } -} diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java index 178a6c1d4..7ebf7f4ed 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java @@ -7,19 +7,24 @@ package edu.cornell.mannlib.vitro.webapp.search.solr; import java.io.InputStream; import org.apache.log4j.Level; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.SolrInputField; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub; +import stubs.javax.servlet.ServletContextStub; + import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; +import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; @@ -37,6 +42,7 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ @Before public void setUp() throws Exception { setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF); + ApplicationStub.setup(new ServletContextStub(), new SearchEngineStub()); Model model = ModelFactory.createDefaultModel(); InputStream in = ThumbnailImageURLTest.class.getResourceAsStream("testPerson.n3"); @@ -52,7 +58,7 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ */ @Test public void testThumbnailFieldCreatedInSolrDoc() { - SolrInputDocument doc = new SolrInputDocument(); + SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument(); ThumbnailImageURL testMe = new ThumbnailImageURL( testRDF ); Individual ind = new IndividualImpl(); ind.setURI(personsURI); @@ -66,11 +72,11 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ //make sure that a Solr document field got created for the thumbnail image - SolrInputField thumbnailField = doc.getField( VitroSearchTermNames.THUMBNAIL_URL ); + SearchInputField thumbnailField = doc.getField( VitroSearchTermNames.THUMBNAIL_URL ); Assert.assertNotNull(thumbnailField); Assert.assertNotNull( thumbnailField.getValues() ); - Assert.assertEquals(1, thumbnailField.getValueCount()); + Assert.assertEquals(1, thumbnailField.getValues().size()); Assert.assertEquals("http://vivo.cornell.edu/individual/n54945", thumbnailField.getFirstValue()); } diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java index 77dd3b488..3df9f73e3 100644 --- a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchEngineStub.java @@ -3,7 +3,6 @@ package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -14,6 +13,7 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineExcepti import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; +import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchInputDocument; /** * TODO @@ -53,6 +53,11 @@ public class SearchEngineStub implements SearchEngine { } } + @Override + public SearchInputDocument createInputDocument() { + return new BaseSearchInputDocument(); + } + // ---------------------------------------------------------------------- // Un-implemented methods @@ -80,13 +85,6 @@ public class SearchEngineStub implements SearchEngine { throw new RuntimeException("SearchEngineStub.ping() not implemented."); } - @Override - public SearchInputDocument createInputDocument() { - // TODO Auto-generated method stub - throw new RuntimeException( - "SearchEngineStub.createInputDocument() not implemented."); - } - @Override public void add(SearchInputDocument... docs) throws SearchEngineException { // TODO Auto-generated method stub diff --git a/webapp/test/stubs/org/apache/solr/client/solrj/SolrServerStub.java b/webapp/test/stubs/org/apache/solr/client/solrj/SolrServerStub.java deleted file mode 100644 index 4fd1df48b..000000000 --- a/webapp/test/stubs/org/apache/solr/client/solrj/SolrServerStub.java +++ /dev/null @@ -1,46 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package stubs.org.apache.solr.client.solrj; - -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.common.util.NamedList; - -/** - * TODO - */ -public class SolrServerStub extends SolrServer { - private static final Log log = LogFactory.getLog(SolrServerStub.class); - - // ---------------------------------------------------------------------- - // Stub infrastructure - // ---------------------------------------------------------------------- - - // ---------------------------------------------------------------------- - // Stub methods - // ---------------------------------------------------------------------- - - /* - * (non-Javadoc) - * - * @see - * org.apache.solr.client.solrj.SolrServer#request(org.apache.solr.client - * .solrj.SolrRequest) - */ - @Override - public NamedList request(SolrRequest request) - throws SolrServerException, IOException { - // TODO not really an implementation. - return new NamedList(); - } - - // ---------------------------------------------------------------------- - // Un-implemented methods - // ---------------------------------------------------------------------- - -} From 1bb51538574203de20f188958b3207a0fcc90305 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 15:11:31 -0400 Subject: [PATCH 5/9] VIVO-742 Setup the Application properly, and guard against NPEs --- .../webapp/application/ApplicationImpl.java | 43 ++++++++++++++++--- .../webapp/application/ApplicationUtils.java | 4 ++ .../solr/SolrConversionUtils.java | 15 ++++--- .../solr/SolrSearchResultDocumentList.java | 10 ++++- .../WEB-INF/resources/startup_listeners.txt | 2 + 5 files changed, 63 insertions(+), 11 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java index 0d33ad0e9..2ab3ef319 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java @@ -3,22 +3,28 @@ package edu.cornell.mannlib.vitro.webapp.application; import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; import edu.cornell.mannlib.vitro.webapp.modules.Application; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineWrapper; import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine; +import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; /** * The basic implementation of the Application interface. */ public class ApplicationImpl implements Application { + // ---------------------------------------------------------------------- + // The instance + // ---------------------------------------------------------------------- + private final ServletContext ctx; private SearchEngine searchEngine; public ApplicationImpl(ServletContext ctx) { this.ctx = ctx; - setSearchEngine(new SolrSearchEngine()); } @Override @@ -32,10 +38,37 @@ public class ApplicationImpl implements Application { } public void setSearchEngine(SearchEngine searchEngine) { - if (searchEngine instanceof SearchEngineWrapper) { - this.searchEngine = searchEngine; - } else { - this.searchEngine = new SearchEngineWrapper(searchEngine); + this.searchEngine = searchEngine; + } + + // ---------------------------------------------------------------------- + // The Setup class. + // ---------------------------------------------------------------------- + + public static class Setup implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext ctx = sce.getServletContext(); + StartupStatus ss = StartupStatus.getBean(ctx); + + try { + SearchEngine searchEngine = new SearchEngineWrapper( + new SolrSearchEngine()); + + ApplicationImpl application = new ApplicationImpl(ctx); + application.setSearchEngine(searchEngine); + ApplicationUtils.setInstance(application); + ss.info(this, "Appliation is configured."); + } catch (Exception e) { + ss.fatal(this, "Failed to initialize the Application.", e); + } } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Nothing to tear down. + } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java index 1aeb7c500..01097e579 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/application/ApplicationUtils.java @@ -25,5 +25,9 @@ public class ApplicationUtils { "Called for Application before it was available", e); } } + + static void setInstance(Application application) { + instance = application; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java index 752c81b94..98f9f3f2d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java @@ -148,8 +148,11 @@ public class SolrConversionUtils { private static Map convertToSearchFacetFieldMap( List facetFields) { Map map = new HashMap<>(); - for (FacetField facetField : facetFields) { - map.put(facetField.getName(), convertToSearchFacetField(facetField)); + if (facetFields != null) { + for (FacetField facetField : facetFields) { + map.put(facetField.getName(), + convertToSearchFacetField(facetField)); + } } return map; } @@ -163,9 +166,11 @@ public class SolrConversionUtils { private static List convertToSearchFacetFieldCounts( List solrCounts) { List searchCounts = new ArrayList<>(); - for (FacetField.Count solrCount : solrCounts) { - searchCounts.add(new BaseCount(solrCount.getName(), solrCount - .getCount())); + if (solrCounts != null) { + for (FacetField.Count solrCount : solrCounts) { + searchCounts.add(new BaseCount(solrCount.getName(), solrCount + .getCount())); + } } return searchCounts; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java index 196b87217..5656438ce 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrSearchResultDocumentList.java @@ -21,7 +21,15 @@ public class SolrSearchResultDocumentList implements SearchResultDocumentList { private SolrDocumentList solrDocs; public SolrSearchResultDocumentList(SolrDocumentList solrDocs) { - this.solrDocs = solrDocs; + if (solrDocs == null) { + SolrDocumentList list = new SolrDocumentList(); + list.setStart(0L); + list.setNumFound(0L); + list.setMaxScore(0.0F); + this.solrDocs = list; + } else { + this.solrDocs = solrDocs; + } } @Override diff --git a/webapp/web/WEB-INF/resources/startup_listeners.txt b/webapp/web/WEB-INF/resources/startup_listeners.txt index 8899f7187..78e2e230d 100644 --- a/webapp/web/WEB-INF/resources/startup_listeners.txt +++ b/webapp/web/WEB-INF/resources/startup_listeners.txt @@ -13,6 +13,8 @@ edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings$Setup +edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$Setup + edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup From bf71c639fb125acfd05350ca5563d4f8aede1b62 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 17:58:58 -0400 Subject: [PATCH 6/9] VIVO-742 Many changes to remove "solr" from methods, variables, classes. --- .../rdf/displayTbox/everytime/displayTBOX.n3 | 2 +- .../IndividualListRdfController.java | 6 +- .../admin/ajax/ProfileAutoCompleter.java | 25 +++--- .../ajax/BasicProfilesGetter.java | 23 +++--- .../freemarker/IndividualListController.java | 18 ++--- .../IndividualListQueryResults.java | 7 +- .../grefine/JSONReconcileServlet.java | 5 +- .../GetRandomSolrIndividualsByVClass.java | 2 +- .../GetRenderedSolrIndividualsByVClass.java | 2 +- ...java => GetSearchIndividualsByVClass.java} | 10 +-- ...va => GetSearchIndividualsByVClasses.java} | 8 +- .../webapp/controller/json/JsonServlet.java | 40 +++++----- .../webapp/dao/jena/VClassGroupCache.java | 40 +++++----- ... => IndividualsViaSearchQueryOptions.java} | 20 ++--- .../DefaultObjectPropertyFormGenerator.java | 21 +++-- .../utils/ProcessDataGetterN3Map.java | 2 +- ...ProcessSearchIndividualsDataGetterN3.java} | 6 +- .../webapp/filters/CachingResponseFilter.java | 36 ++++----- .../controller/AutocompleteController.java | 6 +- .../controller/PagedSearchController.java | 13 ++- .../search/indexing/IndexWorkerThread.java | 4 +- .../{SolrIndexer.java => SearchIndexer.java} | 41 +++++----- .../documentBuilding/ContextNodeFields.java | 6 +- .../documentBuilding/ExcludeNonFlagVitro.java | 2 +- ...t.java => IndividualToSearchDocument.java} | 10 +-- .../searchindex/SearchIndexerSetup.java | 12 +-- .../utils/dataGetter/BrowseDataGetter.java | 4 +- .../utils/dataGetter/DataGetterUtils.java | 4 +- ....java => SearchIndividualsDataGetter.java} | 12 +-- .../AutoCompleteWords.java | 9 ++- .../{solr => searchengine}/FieldMap.java | 17 ++-- .../SearchQueryUtils.java} | 54 ++++++------- .../searchengine/SearchResponseFilter.java | 12 +++ .../SearchResultsParser.java} | 24 +++--- .../webapp/utils/solr/SolrResponseFilter.java | 12 --- .../webapp/web/widgets/BrowseWidget.java | 2 +- .../controller/json/JsonServletTest.java | 25 +++--- .../searchengine/AutoCompleteWordsTest.java | 80 +++++++++++++++++++ .../pageManagement--customDataScript.ftl | 2 +- 39 files changed, 347 insertions(+), 277 deletions(-) rename webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/{GetSolrIndividualsByVClass.java => GetSearchIndividualsByVClass.java} (79%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/{GetSolrIndividualsByVClasses.java => GetSearchIndividualsByVClasses.java} (87%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/{IndividualsViaSolrQueryOptions.java => IndividualsViaSearchQueryOptions.java} (86%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/{ProcessSolrIndividualsDataGetterN3.java => ProcessSearchIndividualsDataGetterN3.java} (97%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/{SolrIndexer.java => SearchIndexer.java} (84%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/{IndividualToSolrDocument.java => IndividualToSearchDocument.java} (97%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/{SolrIndividualsDataGetter.java => SearchIndividualsDataGetter.java} (94%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/utils/{solr => searchengine}/AutoCompleteWords.java (89%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/utils/{solr => searchengine}/FieldMap.java (53%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/utils/{solr/SolrQueryUtils.java => searchengine/SearchQueryUtils.java} (81%) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResponseFilter.java rename webapp/src/edu/cornell/mannlib/vitro/webapp/utils/{solr/SolrResultsParser.java => searchengine/SearchResultsParser.java} (78%) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResponseFilter.java create mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWordsTest.java diff --git a/webapp/rdf/displayTbox/everytime/displayTBOX.n3 b/webapp/rdf/displayTbox/everytime/displayTBOX.n3 index f43eebd8c..0338c9a94 100644 --- a/webapp/rdf/displayTbox/everytime/displayTBOX.n3 +++ b/webapp/rdf/displayTbox/everytime/displayTBOX.n3 @@ -41,7 +41,7 @@ display:RequiredAction a owl:Class ; a owl:Class ; rdfs:comment "Data getter for running a SPARQL query." . - + a owl:Class ; rdfs:comment "A data getter for a Solr Class search, i.e. get individuals for VClass" . diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java index e57bfa65e..d9433f7a9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/IndividualListRdfController.java @@ -33,11 +33,12 @@ public class IndividualListRdfController extends VitroHttpServlet { @Override public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); // Make the query String vclassUri = req.getParameter("vclass"); String queryStr = VitroSearchTermNames.RDFTYPE + ":\"" + vclassUri + "\""; - SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(queryStr); + SearchQuery query = search.createQuery(queryStr); query.setStart(0) .setRows(ENTITY_LIST_CONTROLLER_MAX_RESULTS) .addFields(VitroSearchTermNames.URI); @@ -45,11 +46,10 @@ public class IndividualListRdfController extends VitroHttpServlet { //.addSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED); // Execute the query - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); SearchResponse response = null; try { - response = solr.query(query); + response = search.query(query); } catch (Throwable t) { log.error(t, t); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java index b545f899c..3a55ab72b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/ajax/ProfileAutoCompleter.java @@ -1,14 +1,13 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin.ajax; - import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.AC_NAME_STEMMED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_UNSTEMMED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.RDFTYPE; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.URI; -import static edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils.Conjunction.OR; +import static edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils.Conjunction.OR; import java.io.IOException; import java.util.Collection; @@ -43,10 +42,10 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineExcepti import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; -import edu.cornell.mannlib.vitro.webapp.utils.solr.AutoCompleteWords; -import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResponseFilter; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.AutoCompleteWords; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.FieldMap; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchResponseFilter; /** * Get a list of Profiles with last names that begin with this search term, and @@ -60,7 +59,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResponseFilter; * if an error occurs, return an empty result. */ class ProfileAutoCompleter extends AbstractAjaxResponder implements - SolrResponseFilter { + SearchResponseFilter { private static final Log log = LogFactory .getLog(ProfileAutoCompleter.class); @@ -71,7 +70,7 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements .singleton("http://xmlns.com/foaf/0.1/Person"); private static final String WORD_DELIMITER = "[, ]+"; - private static final FieldMap RESPONSE_FIELDS = SolrQueryUtils.fieldMap() + private static final FieldMap RESPONSE_FIELDS = SearchQueryUtils.fieldMap() .put(URI, "uri").put(NAME_RAW, "label"); private static final Syntax SYNTAX = Syntax.syntaxARQ; @@ -96,7 +95,7 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements this.externalAuthId = getStringParameter(PARAMETER_ETERNAL_AUTH_ID, ""); this.term = getStringParameter(PARAMETER_SEARCH_TERM, ""); - this.searchWords = SolrQueryUtils.parseForAutoComplete(term, + this.searchWords = SearchQueryUtils.parseForAutoComplete(term, WORD_DELIMITER); // TODO This seems to expose the matching property and mechanism too @@ -123,7 +122,7 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements SearchQuery query = buildSearchQuery(); SearchResponse queryResponse = executeSearchQuery(query); - List> maps = SolrQueryUtils + List> maps = SearchQueryUtils .parseAndFilterResponse(queryResponse, RESPONSE_FIELDS, this, 30); @@ -142,7 +141,7 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements SearchQuery q = ApplicationUtils.instance().getSearchEngine().createQuery(); q.addFields(NAME_RAW, URI); q.addSortField(NAME_LOWERCASE_SINGLE_VALUED, Order.ASC); - q.addFilterQuery(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, + q.addFilterQuery(SearchQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR)); q.setStart(0); q.setRows(10000); @@ -152,8 +151,8 @@ class ProfileAutoCompleter extends AbstractAjaxResponder implements private SearchResponse executeSearchQuery(SearchQuery query) throws SearchEngineException { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - return solr.query(query); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + return search.query(query); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java index d507db074..82e2e24c9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ajax/BasicProfilesGetter.java @@ -1,13 +1,14 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ajax; + import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.AC_NAME_STEMMED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_UNSTEMMED; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.RDFTYPE; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.URI; -import static edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils.Conjunction.OR; +import static edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils.Conjunction.OR; import java.io.IOException; import java.util.List; @@ -29,9 +30,9 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineExcepti import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; -import edu.cornell.mannlib.vitro.webapp.utils.solr.AutoCompleteWords; -import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.AutoCompleteWords; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.FieldMap; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; /** * Get the basic auto-complete info for the profile selection. @@ -41,7 +42,7 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { private static final Log log = LogFactory.getLog(BasicProfilesGetter.class); private static final String WORD_DELIMITER = "[, ]+"; - private static final FieldMap RESPONSE_FIELDS = SolrQueryUtils + private static final FieldMap RESPONSE_FIELDS = SearchQueryUtils .fieldMap().put(URI, "uri").put(NAME_RAW, "label") .put("bogus", "classLabel").put("bogus", "imageUrl"); @@ -58,7 +59,7 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { super(servlet, vreq, resp); this.term = getStringParameter(PARAMETER_SEARCH_TERM, ""); - this.searchWords = SolrQueryUtils.parseForAutoComplete(term, + this.searchWords = SearchQueryUtils.parseForAutoComplete(term, WORD_DELIMITER); this.profileTypes = figureProfileTypes(); @@ -69,7 +70,7 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { private List figureProfileTypes() { String typesString = ConfigurationProperties.getBean(vreq).getProperty( PROPERTY_PROFILE_TYPES, DEFAULT_PROFILE_TYPES); - List list = SolrQueryUtils.parseWords(typesString, + List list = SearchQueryUtils.parseWords(typesString, WORD_DELIMITER); if (list.isEmpty()) { log.error("No types configured for profile pages in " @@ -86,11 +87,11 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { } try { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); SearchQuery query = buildSearchQuery(); - SearchResponse queryResponse = solr.query(query); + SearchResponse queryResponse = search.query(query); - List> parsed = SolrQueryUtils + List> parsed = SearchQueryUtils .parseResponse(queryResponse, RESPONSE_FIELDS); String response = assembleJsonResponse(parsed); @@ -106,7 +107,7 @@ public class BasicProfilesGetter extends AbstractAjaxResponder { SearchQuery q = ApplicationUtils.instance().getSearchEngine().createQuery(); q.addFields(NAME_RAW, URI); q.addSortField(NAME_LOWERCASE_SINGLE_VALUED, Order.ASC); - q.addFilterQuery(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR)); + q.addFilterQuery(SearchQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR)); q.setStart(0); q.setRows(30); q.setQuery(searchWords.assembleQuery(NAME_UNSTEMMED, AC_NAME_STEMMED)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index 492d3b420..e7af97537 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -22,7 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual; /** @@ -138,19 +138,19 @@ public class IndividualListController extends FreemarkerHttpServlet { //TODO: Remove and update reference within JsonServlet public static String getAlphaParameter(VitroRequest request){ - return SolrQueryUtils.getAlphaParameter(request); + return SearchQueryUtils.getAlphaParameter(request); } //TODO: Remove and update reference within JsonServlet public static int getPageParameter(VitroRequest request) { - return SolrQueryUtils.getPageParameter(request); + return SearchQueryUtils.getPageParameter(request); } public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao) throws SearchException{ try{ List classUris = Collections.singletonList(vclassURI); - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, indDao); + IndividualListQueryResults results = SearchQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, indDao); return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha); } catch (SearchEngineException e) { String msg = "An error occurred retrieving results for vclass query"; @@ -165,7 +165,7 @@ public class IndividualListController extends FreemarkerHttpServlet { public static IndividualListResults getResultsForVClassIntersections(List vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao) { try{ - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, indDao); + IndividualListQueryResults results = SearchQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, indDao); return getResultsForVClassQuery(results, page, pageSize, alpha); } catch(Throwable th) { log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th); @@ -176,7 +176,7 @@ public class IndividualListController extends FreemarkerHttpServlet { public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao) { try{ List classUris = Collections.singletonList(vclassURI); - IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, indDao); + IndividualListQueryResults results = SearchQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, indDao); return getResultsForVClassQuery(results, page, pageSize, ""); } catch(Throwable th) { log.error("An error occurred retrieving random results for vclass query", th); @@ -184,10 +184,10 @@ public class IndividualListController extends FreemarkerHttpServlet { } } - //TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced + //TODO: Get rid of this method and utilize SearchQueryUtils - currently appears to be referenced //only within DataGetterUtils - public static long getIndividualCount(List vclassUris, IndividualDao indDao) { - return SolrQueryUtils.getIndividualCount(vclassUris, indDao); + public static long getIndividualCount(List vclassUris) { + return SearchQueryUtils.getIndividualCount(vclassUris); } private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java index 337e100f4..c7d832c85 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListQueryResults.java @@ -20,7 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumen import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; /** - * Holds the Individuals that were found in a Solr search query. + * Holds the Individuals that were found in a search query. * * Provides a convenience method to run the query and to find the Individuals. */ @@ -39,9 +39,8 @@ public class IndividualListQueryResults { IndividualDao indDao) throws SearchEngineException { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - SearchResponse response = null; - response = solr.query(query); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + SearchResponse response = search.query(query); if (response == null) { log.debug("response from search query was null"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java index 604db6533..471371f44 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java @@ -271,12 +271,11 @@ public class JSONReconcileServlet extends VitroHttpServlet { // begin search JSONArray resultJsonArr = new JSONArray(); - // Solr SearchQuery query = getQuery(queryVal, searchType, limit, propertiesList); SearchResponse queryResponse = null; if (query != null) { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - queryResponse = solr.query(query); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + queryResponse = search.query(query); } else { log.error("Query for a search was null"); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java index 5e4c268dd..df8fd6a18 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java @@ -26,7 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.Individual * Does a Solr search for individuals, and uses the short view to render each of * the results. */ -public class GetRandomSolrIndividualsByVClass extends GetSolrIndividualsByVClass { +public class GetRandomSolrIndividualsByVClass extends GetSearchIndividualsByVClass { private static final Log log = LogFactory .getLog(GetRandomSolrIndividualsByVClass.class); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java index 81d2ede9e..65ec975cf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java @@ -26,7 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.Individual * Does a Solr search for individuals, and uses the short view to render each of * the results. */ -public class GetRenderedSolrIndividualsByVClass extends GetSolrIndividualsByVClasses { +public class GetRenderedSolrIndividualsByVClass extends GetSearchIndividualsByVClasses { private static final Log log = LogFactory .getLog(GetRenderedSolrIndividualsByVClass.class); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClass.java similarity index 79% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClass.java index 0d40e6026..a56661b48 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClass.java @@ -12,11 +12,11 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; /** * */ -public class GetSolrIndividualsByVClass extends JsonObjectProducer { +public class GetSearchIndividualsByVClass extends JsonObjectProducer { private static final Log log = LogFactory - .getLog(GetSolrIndividualsByVClass.class); + .getLog(GetSearchIndividualsByVClass.class); - protected GetSolrIndividualsByVClass(VitroRequest vreq) { + protected GetSearchIndividualsByVClass(VitroRequest vreq) { super(vreq); } @@ -39,9 +39,9 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer { vreq.setAttribute("displayType", vitroClassIdStr); if ( queryType != null && queryType.equals("random")){ - return JsonServlet.getRandomSolrIndividualsByVClass(vclass.getURI(), vreq, ctx); + return JsonServlet.getRandomSearchIndividualsByVClass(vclass.getURI(), vreq); } else { - return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx); + return JsonServlet.getSearchIndividualsByVClass(vclass.getURI(), vreq); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClasses.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java similarity index 87% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClasses.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java index 0feffe22b..57921ab39 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClasses.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java @@ -16,11 +16,11 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; * Accepts multiple vclasses and returns individuals which correspond to the * intersection of those classes (i.e. have all those types) */ -public class GetSolrIndividualsByVClasses extends JsonObjectProducer { +public class GetSearchIndividualsByVClasses extends JsonObjectProducer { private static final Log log = LogFactory - .getLog(GetSolrIndividualsByVClasses.class); + .getLog(GetSearchIndividualsByVClasses.class); - public GetSolrIndividualsByVClasses(VitroRequest vreq) { + public GetSearchIndividualsByVClasses(VitroRequest vreq) { super(vreq); } @@ -45,7 +45,7 @@ public class GetSolrIndividualsByVClasses extends JsonObjectProducer { throw new Exception("parameter vclassId URI parameter expected "); } List vclassIds = Arrays.asList(vitroClassIdStr); - return JsonServlet.getSolrIndividualsByVClasses(vclassIds, vreq, ctx); + return JsonServlet.getSearchIndividualsByVClasses(vclassIds, vreq); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java index 6af92cf44..2d688b63b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java @@ -3,12 +3,9 @@ package edu.cornell.mannlib.vitro.webapp.controller.json; import java.io.IOException; -import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; -import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -22,9 +19,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController; -import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResultsUtils; import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults; -import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; +import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResultsUtils; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils; @@ -62,13 +58,13 @@ public class JsonServlet extends VitroHttpServlet { throw new IllegalArgumentException("The call invoked deprecated classes " + "and the parameter for this call appeared nowhere in the code base, " + "so it was removed in May, 2012."); - }else if( vreq.getParameter("getSolrIndividualsByVClass") != null ){ - new GetSolrIndividualsByVClass(vreq).process(resp); + }else if( vreq.getParameter("getSearchIndividualsByVClass") != null ){ + new GetSearchIndividualsByVClass(vreq).process(resp); }else if( vreq.getParameter("getVClassesForVClassGroup") != null ){ new GetVClassesForVClassGroup(vreq).process(resp); - } else if( vreq.getParameter("getSolrIndividualsByVClasses") != null ){ + } else if( vreq.getParameter("getSearchIndividualsByVClasses") != null ){ log.debug("AJAX request to retrieve individuals by vclasses"); - new GetSolrIndividualsByVClasses(vreq).process(resp); + new GetSearchIndividualsByVClasses(vreq).process(resp); } else if( vreq.getParameter("getDataForPage") != null ){ throw new IllegalArgumentException("The call invoked deprecated classes " + "and the parameter for this call appeared nowhere in the code base, " + @@ -84,27 +80,27 @@ public class JsonServlet extends VitroHttpServlet { } - public static JSONObject getSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception { + public static JSONObject getSearchIndividualsByVClass(String vclassURI, HttpServletRequest req) throws Exception { List vclassURIs = Collections.singletonList(vclassURI); VitroRequest vreq = new VitroRequest(req); - IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context); + IndividualListResults vcResults = getSearchVClassIntersectionResults(vclassURIs, vreq); //last parameter indicates single vclass instead of multiple vclasses return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false); } - public static JSONObject getSolrIndividualsByVClasses(List vclassURIs, HttpServletRequest req, ServletContext context) throws Exception { + public static JSONObject getSearchIndividualsByVClasses(List vclassURIs, HttpServletRequest req) throws Exception { VitroRequest vreq = new VitroRequest(req); - log.debug("Retrieve solr results for vclasses" + vclassURIs.toString()); - IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context); - log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + vcResults.getTotalCount()); + log.debug("Retrieve search results for vclasses" + vclassURIs.toString()); + IndividualListResults vcResults = getSearchVClassIntersectionResults(vclassURIs, vreq); + log.debug("Results returned from search engine for " + vclassURIs.toString() + " are of size " + vcResults.getTotalCount()); return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, true); } - //Including version for Solr query for Vclass Intersections - private static IndividualListResults getSolrVClassIntersectionResults(List vclassURIs, VitroRequest vreq, ServletContext context){ - log.debug("Retrieving Solr intersection results for " + vclassURIs.toString()); + //Including version for search query for Vclass Intersections + private static IndividualListResults getSearchVClassIntersectionResults(List vclassURIs, VitroRequest vreq){ + log.debug("Retrieving search intersection results for " + vclassURIs.toString()); String alpha = IndividualListController.getAlphaParameter(vreq); int page = IndividualListController.getPageParameter(vreq); log.debug("Alpha and page parameters are " + alpha + " and " + page); @@ -128,17 +124,17 @@ public class JsonServlet extends VitroHttpServlet { return value; } - public static JSONObject getRandomSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception { + public static JSONObject getRandomSearchIndividualsByVClass(String vclassURI, HttpServletRequest req) throws Exception { VitroRequest vreq = new VitroRequest(req); - IndividualListResults vcResults = getRandomSolrVClassResults(vclassURI, vreq, context); + IndividualListResults vcResults = getRandomSearchVClassResults(vclassURI, vreq); //last parameter indicates single vclass instead of multiple vclasses return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false); } //Including version for Random Solr query for Vclass Intersections - private static IndividualListResults getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){ - log.debug("Retrieving random Solr intersection results for " + vclassURI); + private static IndividualListResults getRandomSearchVClassResults(String vclassURI, VitroRequest vreq){ + log.debug("Retrieving random search intersection results for " + vclassURI); int page = IndividualListController.getPageParameter(vreq); int pageSize = Integer.parseInt(vreq.getParameter("pageSize")); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java index 5cebc62c0..bdb2cb884 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java @@ -56,15 +56,15 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; * The cache is updated asynchronously by the thread RebuildGroupCacheThread. * A synchronous rebuild can be performed with VClassGroupCache.doSynchronousRebuild() * - * This class should handle the condition where Solr is not available. + * This class should handle the condition where the search engine is not available. * It will not throw an exception but it will return a empty list of classes * or class groups. * * VClassGroupCache.doSynchronousRebuild() and the RebuildGroupCacheThread will try - * to connect to the Solr server a couple of times and then give up. + * to connect to the search engine a couple of times and then give up. * - * As of VIVO release 1.4, the counts come from the Solr index. If the - * solr index is not built or if there were problems building the index, + * As of VIVO release 1.4, the counts come from the search index. If the + * search index is not built or if there were problems building the index, * the class counts from VClassGroupCache will be incorrect. */ public class VClassGroupCache implements IndexingEventListener { @@ -185,7 +185,7 @@ public class VClassGroupCache implements IndexingEventListener { } public void doSynchronousRebuild(){ - //try to rebuild a couple times since the Solr server may not yet be up. + //try to rebuild a couple times since the search engine may not yet be up. int attempts = 0; int maxTries = 3; @@ -194,7 +194,7 @@ public class VClassGroupCache implements IndexingEventListener { while( attempts < maxTries ){ try { attempts++; - rebuildCacheUsingSolr(this); + rebuildCacheUsingSearch(this); break; } catch (SearchEngineException e) { exception = e; @@ -244,17 +244,15 @@ public class VClassGroupCache implements IndexingEventListener { /** * Method that rebuilds the cache. This will use a WebappDaoFactory, - * a SolrSever and maybe a ProhibitedFromSearch from the cache.context. + * a SearchEngine and maybe a ProhibitedFromSearch from the cache.context. * * If ProhibitedFromSearch is not found in the context, that will be skipped. - * - * @throws SearchEngineException if there are problems with the Solr server. */ - protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SearchEngineException{ + protected static void rebuildCacheUsingSearch( VClassGroupCache cache ) throws SearchEngineException{ long start = System.currentTimeMillis(); WebappDaoFactory wdFactory = ModelAccess.on(cache.context).getWebappDaoFactory(); - SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); VitroFilters vFilters = VitroFilterUtils.getPublicFilter(cache.context); VClassGroupDao vcgDao = new WebappDaoFactoryFiltering(wdFactory, vFilters).getVClassGroupDao(); @@ -263,7 +261,7 @@ public class VClassGroupCache implements IndexingEventListener { INCLUDE_UNINSTANTIATED, DONT_INCLUDE_INDIVIDUAL_COUNT); removeClassesHiddenFromSearch(groups, cache.context); - addCountsUsingSolr(groups, solrServer); + addCountsUsingSearch(groups, searchEngine); cache.setCache(groups, classMapForGroups(groups)); log.debug("msec to build cache: " + (System.currentTimeMillis() - start)); @@ -310,23 +308,23 @@ public class VClassGroupCache implements IndexingEventListener { * Add the Individual count to classes in groups. * @throws SearchEngineException */ - protected static void addCountsUsingSolr(List groups, SearchEngine solrServer) + protected static void addCountsUsingSearch(List groups, SearchEngine searchEngine) throws SearchEngineException { - if( groups == null || solrServer == null ) + if( groups == null || searchEngine == null ) return; for( VClassGroup group : groups){ - addClassCountsToGroup(group, solrServer); + addClassCountsToGroup(group, searchEngine); } } - protected static void addClassCountsToGroup(VClassGroup group, SearchEngine solrServer) + protected static void addClassCountsToGroup(VClassGroup group, SearchEngine searchEngine) throws SearchEngineException { if( group == null ) return; String groupUri = group.getURI(); String facetOnField = VitroSearchTermNames.RDFTYPE; - SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(). + SearchQuery query = searchEngine.createQuery(). setRows(0). setQuery(VitroSearchTermNames.CLASSGROUP_URI + ":" + groupUri ). setFaceting(true). //facet on type to get counts for classes in classgroup @@ -335,7 +333,7 @@ public class VClassGroupCache implements IndexingEventListener { log.debug("query: " + query); - SearchResponse rsp = solrServer.query(query); + SearchResponse rsp = searchEngine.query(query); //Get individual count long individualCount = rsp.getResults().getNumFound(); @@ -419,7 +417,7 @@ public class VClassGroupCache implements IndexingEventListener { setWorkLevel(WorkLevel.WORKING); rebuildRequested = false; try { - rebuildCacheUsingSolr( cache ); + rebuildCacheUsingSearch( cache ); log.debug("rebuildGroupCacheThread.run() -- rebuilt cache "); failedAttempts = 0; delay = 100; @@ -427,7 +425,7 @@ public class VClassGroupCache implements IndexingEventListener { failedAttempts++; if( failedAttempts >= maxFailedAttempts ){ log.error("Could not build VClassGroupCache. " + - "Could not connect with Solr after " + + "Could not connect with the search engine after " + failedAttempts + " attempts.", e.getCause()); rebuildRequested = false; failedAttempts = 0; @@ -435,7 +433,7 @@ public class VClassGroupCache implements IndexingEventListener { }else{ rebuildRequested = true; delay = (int) (( Math.pow(2, failedAttempts) ) * 1000); - log.debug("Could not connect with Solr, will attempt " + + log.debug("Could not connect with the search engine, will attempt " + "again in " + delay + " msec."); } }catch(Exception ex){ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSearchQueryOptions.java similarity index 86% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSearchQueryOptions.java index 472af6204..762aaeceb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSolrQueryOptions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/IndividualsViaSearchQueryOptions.java @@ -26,16 +26,16 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils; /* - * This runs a solr query to get individuals of a certain class instead of relying on the dao classes. + * This runs a search query to get individuals of a certain class instead of relying on the dao classes. * Also it gets individuals that belong to the most specific type(s) specified. */ -public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions implements FieldOptions { - private Log log = LogFactory.getLog(IndividualsViaSolrQueryOptions.class); +public class IndividualsViaSearchQueryOptions extends IndividualsViaVClassOptions implements FieldOptions { + private Log log = LogFactory.getLog(IndividualsViaSearchQueryOptions.class); private String subjectUri; private String predicateUri; private String objectUri; - public IndividualsViaSolrQueryOptions(String inputSubjectUri, String inputPredicateUri, String inputObjectUri, String ... vclassURIs) throws Exception { + public IndividualsViaSearchQueryOptions(String inputSubjectUri, String inputPredicateUri, String inputObjectUri, String ... vclassURIs) throws Exception { super(vclassURIs); this.subjectUri = inputSubjectUri; this.predicateUri = inputPredicateUri; @@ -46,10 +46,10 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions protected Map getIndividualsForClass(String vclassURI, WebappDaoFactory wDaoFact ){ Map individualMap = new HashMap(); try { - SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); - //solr query for type count. - SearchQuery query = solrServer.createQuery(); + //search query for type count. + SearchQuery query = searchEngine.createQuery(); if( VitroVocabulary.OWL_THING.equals( vclassURI )){ query.setQuery( "*:*" ); }else{ @@ -59,7 +59,7 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions .setRows(1000); query.addFields(VitroSearchTermNames.URI); // fields to retrieve - SearchResponse rsp = solrServer.query(query); + SearchResponse rsp = searchEngine.query(query); SearchResultDocumentList docs = rsp.getResults(); long found = docs.getNumFound(); if(found > 0) { @@ -75,13 +75,13 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions } } catch(Exception ex) { - log.error("An error occurred retrieving the individual solr query resutls", ex); + log.error("An error occurred retrieving the individual search resutls", ex); } } } } catch(Exception ex) { - log.error("Error occurred in executing solr query ", ex); + log.error("Error occurred in executing search query ", ex); } return individualMap; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index 84c974da2..cce5d6caf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -175,7 +175,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene private boolean tooManyRangeOptions(VitroRequest vreq, HttpSession session ) throws SearchEngineException { List rangeTypes = getRangeTypes(vreq); - SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); List types = new ArrayList(); for (VClass vclass : rangeTypes) { @@ -191,15 +191,15 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene long count = 0; for( String type:types){ - //solr query for type count. - SearchQuery query = solrServer.createQuery(); + //search query for type count. + SearchQuery query = searchEngine.createQuery(); if( VitroVocabulary.OWL_THING.equals( type )){ query.setQuery( "*:*" ); }else{ query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type); } query.setRows(0); - SearchResponse rsp = solrServer.query(query); + SearchResponse rsp = searchEngine.query(query); SearchResultDocumentList docs = rsp.getResults(); long found = docs.getNumFound(); count = count + found; @@ -552,7 +552,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene } //TODO: find out if there are any individuals in the classes of objectTypes - formSpecificData.put("rangeIndividualsExist", rangeIndividualsExist(session,types) ); + formSpecificData.put("rangeIndividualsExist", rangeIndividualsExist(types) ); formSpecificData.put("sparqlForAcFilter", getSparqlForAcFilter(vreq)); if(customErrorMessages != null && !customErrorMessages.isEmpty()) { @@ -562,18 +562,17 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene editConfiguration.setFormSpecificData(formSpecificData); } - private Object rangeIndividualsExist(HttpSession session, List types) throws SearchEngineException { - SearchEngine solrServer = ApplicationUtils.instance().getSearchEngine(); + private Object rangeIndividualsExist(List types) throws SearchEngineException { + SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); boolean rangeIndividualsFound = false; for( VClass type:types){ - //solr for type count. - SearchQuery query =ApplicationUtils.instance().getSearchEngine().createQuery(); - + //search for type count. + SearchQuery query = searchEngine.createQuery(); query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type.getURI()); query.setRows(0); - SearchResponse rsp = solrServer.query(query); + SearchResponse rsp = searchEngine.query(query); SearchResultDocumentList docs = rsp.getResults(); if( docs.getNumFound() > 0 ){ rangeIndividualsFound = true; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Map.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Map.java index 0ca8d4f65..7f155e574 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Map.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3Map.java @@ -18,7 +18,7 @@ public class ProcessDataGetterN3Map { map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessClassGroupDataGetterN3"); map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessIndividualsForClassesDataGetterN3"); map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessFixedHTMLN3"); - map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSolrIndividualsDataGetterN3"); + map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchIndividualsDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSearchIndividualsDataGetterN3"); return map; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSolrIndividualsDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSearchIndividualsDataGetterN3.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSolrIndividualsDataGetterN3.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSearchIndividualsDataGetterN3.java index eae59bb9c..096c0ed67 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSolrIndividualsDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessSearchIndividualsDataGetterN3.java @@ -24,11 +24,11 @@ import com.hp.hpl.jena.rdf.model.Resource; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; //Returns the appropriate n3 based on data getter -public class ProcessSolrIndividualsDataGetterN3 extends ProcessDataGetterAbstract { - private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter"; +public class ProcessSearchIndividualsDataGetterN3 extends ProcessDataGetterAbstract { + private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchIndividualsDataGetter"; private Log log = LogFactory.getLog(ProcessFixedHTMLN3.class); - public ProcessSolrIndividualsDataGetterN3(){ + public ProcessSearchIndividualsDataGetterN3(){ } //Pass in variable that represents the counter diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java index 044de5e31..46325a322 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/CachingResponseFilter.java @@ -30,9 +30,9 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; -import edu.cornell.mannlib.vitro.webapp.utils.solr.FieldMap; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResultsParser; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.FieldMap; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchResultsParser; /** * Assist in cache management for individual profile pages. @@ -41,7 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResultsParser; * * Only works for users who are not logged in. * - * The Solr index must be configured to keep an ETAG on each individual's + * The search index must be configured to keep an ETAG on each individual's * record. The ETAG is a hash of the record's content and is updated each time * the individual is re-indexed. * @@ -59,10 +59,10 @@ import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrResultsParser; * generated, with a Cache-Control header that should prevent the cache from * storing that response. * - * If the requesting user is not logged in, this filter will ask Solr for the - * ETAG on the requested individual. If it is the same as the ETAG supplied by - * the cache in the request, then the response is 304 Not Modified. Otherwise, a - * fresh response is generated. + * If the requesting user is not logged in, this filter will ask the search + * engine for the ETAG on the requested individual. If it is the same as the + * ETAG supplied by the cache in the request, then the response is 304 Not + * Modified. Otherwise, a fresh response is generated. * * An unconditional request may mean that there is no external cache, or that * the cache doesn't have a copy of this particular page. @@ -77,7 +77,7 @@ public class CachingResponseFilter implements Filter { private static final String PROPERTY_ENABLE_CACHING = "http.createCacheHeaders"; private static final String ETAG_FIELD = "etag"; - private static final FieldMap parserFieldMap = SolrQueryUtils.fieldMap() + private static final FieldMap parserFieldMap = SearchQueryUtils.fieldMap() .put(ETAG_FIELD, ETAG_FIELD); private ServletContext ctx; @@ -241,18 +241,18 @@ public class CachingResponseFilter implements Filter { } /** - * Ask Solr whether it has an ETAG for this URI. + * Ask the search engine whether it has an ETAG for this URI. */ private String findEtagForIndividual(String individualUri) { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - SearchQuery query = solr.createQuery("URI:" + individualUri) - .addFields(ETAG_FIELD); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + SearchQuery query = search.createQuery("URI:" + individualUri).addFields( + ETAG_FIELD); try { - SearchResponse response = solr.query(query); - List> maps = new SolrResultsParser(response, + SearchResponse response = search.query(query); + List> maps = new SearchResultsParser(response, parserFieldMap).parse(); - log.debug("Solr response for '" + query.getQuery() + "' was " + log.debug("Search response for '" + query.getQuery() + "' was " + maps); if (maps.isEmpty()) { @@ -262,14 +262,14 @@ public class CachingResponseFilter implements Filter { } } catch (SearchEngineException e) { log.warn( - "Solr query '" + query.getQuery() + "' threw an exception", + "Search query '" + query.getQuery() + "' threw an exception", e); return null; } } /** - * The ETAG from the Solr index is not specific enough, since we may have + * The ETAG from the search index is not specific enough, since we may have * different versions for different languages. Add the Locales from the * request to make it unique. */ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java index 9a56983e5..0d5e4300f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java @@ -74,8 +74,8 @@ public class AutocompleteController extends VitroAjaxController { } log.debug("query for '" + qtxt +"' is " + query.toString()); - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - SearchResponse queryResponse = solr.query(query); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + SearchResponse queryResponse = search.query(query); if ( queryResponse == null) { log.error("Query response for a search was null"); @@ -254,7 +254,7 @@ public class AutocompleteController extends VitroAjaxController { } private String escapeWhitespaceInQueryString(String queryStr) { - // Solr wants whitespace to be escaped with a backslash + // The search engine wants whitespace to be escaped with a backslash return queryStr.replaceAll("\\s+", "\\\\ "); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index 2d052d22b..cadbf36dc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -55,10 +55,7 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult.Individu import edu.ucsf.vitro.opensocial.OpenSocialManager; /** - * Paged search controller that uses Solr - * - * @author bdc34, rjy7 - * + * Paged search controller that uses the search engine */ public class PagedSearchController extends FreemarkerHttpServlet { @@ -170,14 +167,14 @@ public class PagedSearchController extends FreemarkerHttpServlet { } SearchQuery query = getQuery(queryText, hitsPerPage, startIndex, vreq); - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); SearchResponse response = null; try { - response = solr.query(query); + response = search.query(query); } catch (Exception ex) { String msg = makeBadSearchMessage(queryText, ex.getMessage(), vreq); - log.error("could not run Solr query",ex); + log.error("could not run search query",ex); return doFailedSearch(msg, queryText, format, vreq); } @@ -467,7 +464,7 @@ public class PagedSearchController extends FreemarkerHttpServlet { } private SearchQuery getQuery(String queryText, int hitsPerPage, int startIndex, VitroRequest vreq) { - // Lowercase the search term to support wildcard searches: Solr applies no text + // Lowercase the search term to support wildcard searches: The search engine applies no text // processing to a wildcard search term. SearchQuery query = ApplicationUtils.instance().getSearchEngine().createQuery(queryText); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java index 57caebb5d..cb33a9406 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java @@ -11,14 +11,14 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; class IndexWorkerThread extends VitroBackgroundThread{ private static final Log log = LogFactory.getLog(IndexWorkerThread.class); protected final int threadNum; - protected IndividualToSolrDocument individualToSolrDoc; + protected IndividualToSearchDocument individualToSolrDoc; protected final IndexerIface indexer; protected final Iterator individualsToIndex; protected boolean stopRequested = false; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java similarity index 84% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java index afd4deb30..952c4653f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.search.solr; -import java.io.IOException; import java.util.HashSet; import org.apache.commons.logging.Log; @@ -19,16 +18,16 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; -public class SolrIndexer implements IndexerIface { - private final static Log log = LogFactory.getLog(SolrIndexer.class); +public class SearchIndexer implements IndexerIface { + private final static Log log = LogFactory.getLog(SearchIndexer.class); protected SearchEngine server; protected boolean indexing; protected HashSet urisIndexed; - protected IndividualToSolrDocument individualToSolrDoc; + protected IndividualToSearchDocument individualToSearchDoc; /** * System is shutting down if true. @@ -37,7 +36,7 @@ public class SolrIndexer implements IndexerIface { /** * This records when a full re-index starts so that once it is done - * all the documents on the Solr service that are earlier than the + * all the documents in the search index that are earlier than the * reindexStart can be removed. */ protected long reindexStart = 0L; @@ -49,15 +48,15 @@ public class SolrIndexer implements IndexerIface { */ protected boolean doingFullIndexRebuild = false; - public SolrIndexer( SearchEngine server, IndividualToSolrDocument indToDoc){ + public SearchIndexer( SearchEngine server, IndividualToSearchDocument indToDoc){ this.server = server; - this.individualToSolrDoc = indToDoc; + this.individualToSearchDoc = indToDoc; } @Override public void index(Individual ind) throws IndexingException { if( ! indexing ) - throw new IndexingException("SolrIndexer: must call " + + throw new IndexingException("SearchIndexer: must call " + "startIndexing() before index()."); if( ind == null ) { @@ -70,20 +69,20 @@ public class SolrIndexer implements IndexerIface { log.debug("already indexed " + ind.getURI() ); return; }else{ - SearchInputDocument solrDoc = null; + SearchInputDocument doc = null; synchronized(this){ urisIndexed.add(ind.getURI()); } log.debug("indexing " + ind.getURI()); - solrDoc = individualToSolrDoc.translate(ind); + doc = individualToSearchDoc.translate(ind); - if( solrDoc != null){ + if( doc != null){ if( log.isDebugEnabled()){ - log.info("boost for " + ind.getName() + " is " + solrDoc.getDocumentBoost()); - log.debug( solrDoc.toString() ); + log.info("boost for " + ind.getName() + " is " + doc.getDocumentBoost()); + log.debug( doc.toString() ); } - server.add( solrDoc ); + server.add( doc ); log.debug("Added docs to server."); }else{ log.debug("removing from index " + ind.getURI()); @@ -110,7 +109,7 @@ public class SolrIndexer implements IndexerIface { public void removeFromIndex(String uri) throws IndexingException { if( uri != null ){ try { - server.deleteById(individualToSolrDoc.getIdForUri(uri)); + server.deleteById(individualToSearchDoc.getIdForUri(uri)); log.debug("deleted " + " " + uri); } catch (SearchEngineException e) { log.error( "could not delete individual " + uri, e); @@ -121,7 +120,7 @@ public class SolrIndexer implements IndexerIface { @Override public synchronized void startIndexing() throws IndexingException { if( indexing) - log.debug("SolrIndexer.startIndexing() Indexing in progress, waiting for completion..."); + log.debug("SearchIndexer.startIndexing() Indexing in progress, waiting for completion..."); while( indexing && ! shutdownRequested ){ //wait for indexing to end. try{ wait( 250 ); } catch(InterruptedException ex){} @@ -137,7 +136,7 @@ public class SolrIndexer implements IndexerIface { public void abortIndexingAndCleanUp() { shutdownRequested = true; try{ - individualToSolrDoc.shutdown(); + individualToSearchDoc.shutdown(); }catch(Exception e){ if( log != null) log.debug(e,e); @@ -159,8 +158,8 @@ public class SolrIndexer implements IndexerIface { server.commit(); } catch (Throwable e) { if( ! shutdownRequested ){ - log.debug("could not commit to solr server, " + - "this should not be a problem since solr will do autocommit"); + log.debug("could not commit to the search engine, " + + "this should not be a problem since the search engine will do autocommit"); } } indexing = false; @@ -213,7 +212,7 @@ public class SolrIndexer implements IndexerIface { return true; } } catch (SearchEngineException e) { - log.error("Could not connect to solr server" ,e.getCause()); + log.error("Could not connect to the search engine." ,e.getCause()); } return false; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java index 68e6b88ea..010bac7b1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java @@ -37,7 +37,7 @@ public class ContextNodeFields implements DocumentModifier{ protected RDFServiceFactory rdfServiceFactory; /** - * Construct this with a model to query when building Solr Documents and + * Construct this with a model to query when building search documents and * a list of the SPARQL queries to run. */ protected ContextNodeFields(List queries, RDFServiceFactory rdfServiceFactory){ @@ -73,10 +73,10 @@ public class ContextNodeFields implements DocumentModifier{ /** * this method gets values that will be added to ALLTEXT - * field of solr Document for each individual. + * field of the search index Document for each individual. * * @param individual - * @return StringBuffer with text values to add to ALLTEXT field of solr Document. + * @return StringBuffer with text values to add to ALLTEXT field of the search index Document. */ protected StringBuffer executeQueryForValues( Individual individual, Collection queries){ /* execute all the queries on the list and concat the values to add to all text */ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java index fdd2df365..6dec71993 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java @@ -1,7 +1,7 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; -import static edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument.DONT_EXCLUDE; +import static edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument.DONT_EXCLUDE; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java index 3a3ca5e71..2e29205b2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java @@ -29,9 +29,9 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumen import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -public class IndividualToSolrDocument { +public class IndividualToSearchDocument { - public static final Log log = LogFactory.getLog(IndividualToSolrDocument.class.getName()); + public static final Log log = LogFactory.getLog(IndividualToSearchDocument.class.getName()); public static VitroSearchTermNames term = new VitroSearchTermNames(); @@ -41,7 +41,7 @@ public class IndividualToSolrDocument { protected List excludes; - public IndividualToSolrDocument(List excludes, List docModifiers){ + public IndividualToSearchDocument(List excludes, List docModifiers){ this.excludes = excludes; this.documentModifiers = docModifiers; } @@ -302,12 +302,12 @@ public class IndividualToSolrDocument { doc.addField(term.NAME_RAW, value); doc.addField(term.NAME_LOWERCASE_SINGLE_VALUED,value); - // NAME_RAW will be copied by solr into the following fields: + // NAME_RAW will be copied by the search engine into the following fields: // NAME_LOWERCASE, NAME_UNSTEMMED, NAME_STEMMED, NAME_PHONETIC, AC_NAME_UNTOKENIZED, AC_NAME_STEMMED } public Object getIndexId(Object obj) { - throw new Error("IndiviudalToSolrDocument.getIndexId() is unimplemented"); + throw new Error("IndiviudalToSearchDocument.getIndexId() is unimplemented"); } public String getIdForUri(String uri){ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java index d60c6928a..2a8543333 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java @@ -29,13 +29,13 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate; import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalUriFinders; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener; -import edu.cornell.mannlib.vitro.webapp.search.solr.SolrIndexer; +import edu.cornell.mannlib.vitro.webapp.search.solr.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnNamespace; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnType; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnTypeNamespace; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeNonFlagVitro; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; +import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameBoost; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameFields; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SearchIndexExcluder; @@ -100,13 +100,13 @@ public class SearchIndexerSetup implements ServletContextListener { List searchIndexExcludesFromContext = (List) context .getAttribute("SearchIndexExcludes"); - IndividualToSolrDocument indToSolrDoc = setupTransltion( + IndividualToSearchDocument indToSolrDoc = setupTransltion( jenaOntModel, displayModel, RDFServiceUtils.getRDFServiceFactory(context), modifiersFromContext, searchIndexExcludesFromContext); /* setup solr indexer */ - SolrIndexer solrIndexer = new SolrIndexer(searchEngine, indToSolrDoc); + SearchIndexer solrIndexer = new SearchIndexer(searchEngine, indToSolrDoc); // This is where the builder gets the list of places to try to // get objects to index. It is filtered so that non-public text @@ -151,7 +151,7 @@ public class SearchIndexerSetup implements ServletContextListener { } - public static IndividualToSolrDocument setupTransltion( + public static IndividualToSearchDocument setupTransltion( OntModel jenaOntModel, Model displayModel, RDFServiceFactory rdfServiceFactory, List modifiersFromContext, @@ -187,6 +187,6 @@ public class SearchIndexerSetup implements ServletContextListener { excludes.add(new ExcludeNonFlagVitro()); excludes.add(new SyncingExcludeBasedOnType(displayModel)); - return new IndividualToSolrDocument(excludes, modifiers); + return new IndividualToSearchDocument(excludes, modifiers); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/BrowseDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/BrowseDataGetter.java index 4ef989663..5873d7e4f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/BrowseDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/BrowseDataGetter.java @@ -91,7 +91,7 @@ public class BrowseDataGetter extends DataGetterBase implements DataGetter { //Get data servuice public String getDataServiceUrl() { - return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId="); + return UrlBuilder.getUrl("/dataservice?getSearchIndividualsByVClass=1&vclassId="); } private Map doClassAlphaDisplay( Map params, VitroRequest request, ServletContext context) throws Exception { Map body = new HashMap(); @@ -108,7 +108,7 @@ public class BrowseDataGetter extends DataGetterBase implements DataGetter { VClass vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri); map.put("class", new VClassTemplateModel(vclass)); - JSONObject vclassRes = JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), request, context); + JSONObject vclassRes = JsonServlet.getSearchIndividualsByVClass(vclass.getURI(), request); map.put("totalCount", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("totalCount") )); map.put("alpha", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("alpha") )); map.put("individuals", JsonToFmModel.convertJSONArrayToList( (JSONArray) vclassRes.get("individuals") )); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java index 00b845bd8..973d54e8a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterUtils.java @@ -267,10 +267,10 @@ public class DataGetterUtils { * For page data getter conversions */ /** - * Get Individual count for Solr query for intersection of multiple classes + * Get Individual count for search query for intersection of multiple classes */ public static long getIndividualCountForIntersection(VitroRequest vreq, List classUris) { - return IndividualListController.getIndividualCount(classUris, vreq.getWebappDaoFactory().getIndividualDao()); + return IndividualListController.getIndividualCount(classUris); } //Return data getter type to be employed in display model diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java similarity index 94% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java index cf8431ade..944f79b3a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SolrIndividualsDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java @@ -34,10 +34,10 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListCont import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; -import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils; +import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual; -public class SolrIndividualsDataGetter extends DataGetterBase implements DataGetter{ +public class SearchIndividualsDataGetter extends DataGetterBase implements DataGetter{ String dataGetterURI; List vclassUris = null; String saveToVar; @@ -45,14 +45,14 @@ public class SolrIndividualsDataGetter extends DataGetterBase implements DataGet ServletContext context; - final static Log log = LogFactory.getLog(SolrIndividualsDataGetter.class); + final static Log log = LogFactory.getLog(SearchIndividualsDataGetter.class); //default template private final static String defaultTemplate = "menupage--defaultSolrIndividuals.ftl"; /** * Constructor with display model and data getter URI that will be called by reflection. */ - public SolrIndividualsDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ + public SearchIndividualsDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ this.configure(vreq, displayModel,dataGetterURI); } @@ -170,8 +170,8 @@ public class SolrIndividualsDataGetter extends DataGetterBase implements DataGet private void populateSolrQueryResults(VClass vclass, Map body) { try { - String alpha = SolrQueryUtils.getAlphaParameter(vreq); - int page = SolrQueryUtils.getPageParameter(vreq); + String alpha = SearchQueryUtils.getAlphaParameter(vreq); + int page = SearchQueryUtils.getPageParameter(vreq); IndividualListResults vcResults = IndividualListController.getResultsForVClass( vclass.getURI(), page, diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/AutoCompleteWords.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWords.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/AutoCompleteWords.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWords.java index bba1ff785..0027c973d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/AutoCompleteWords.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWords.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.utils.solr; +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; import java.util.ArrayList; import java.util.Collections; @@ -27,15 +27,16 @@ public class AutoCompleteWords { private final String partialWord; /** - * Package-access. Use SolrQueryUtils.parseForAutoComplete() to create an + * Package-access. Use SearchQueryUtils.parseForAutoComplete() to create an * instance. */ AutoCompleteWords(String searchTerm, String delimiterPattern) { - this.searchTerm = searchTerm; + this.searchTerm = (searchTerm == null) ? "" : searchTerm; this.delimiterPattern = delimiterPattern; List termWords = figureTermWords(); - if (termWords.isEmpty() || this.searchTerm.endsWith(" ")) { + if (termWords.isEmpty() + || this.searchTerm.matches(".*" + delimiterPattern)) { this.completeWords = termWords; this.partialWord = null; } else { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/FieldMap.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/FieldMap.java similarity index 53% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/FieldMap.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/FieldMap.java index 877f54286..8a27f0fa1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/FieldMap.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/FieldMap.java @@ -1,17 +1,17 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.utils.solr; +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; import java.util.HashMap; import java.util.Map; /** - * A builder object that can assemble a map of Solr field names to JSON field - * names. + * A builder object that can assemble a map of search result field names to JSON + * field names. * * Use like this: * - * m = SolrQueryUtils.fieldMap().row("this", "that").row("2nd", "row").map(); + * m = SearchQueryUtils.fieldMap().put("this", "that").put("2nd", "row").map(); * */ public class FieldMap { @@ -20,14 +20,15 @@ public class FieldMap { /** * Add a row to the map */ - public FieldMap put(String solrFieldName, String jsonFieldName) { - if (solrFieldName == null) { - throw new NullPointerException("solrFieldName may not be null."); + public FieldMap put(String searchResultFieldName, String jsonFieldName) { + if (searchResultFieldName == null) { + throw new NullPointerException( + "searchResultFieldName may not be null."); } if (jsonFieldName == null) { throw new NullPointerException("jsonFieldName may not be null."); } - m.put(solrFieldName, jsonFieldName); + m.put(searchResultFieldName, jsonFieldName); return this; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchQueryUtils.java similarity index 81% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchQueryUtils.java index 6b7227744..42cad8150 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchQueryUtils.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.utils.solr; +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; import java.util.ArrayList; import java.util.Collection; @@ -23,12 +23,12 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; /** - * Some static method to help in constructing Solr queries and parsing the + * Some static methods to help in constructing search queries and parsing the * results. */ -public class SolrQueryUtils { - private static final Log log = LogFactory.getLog(SolrQueryUtils.class.getName()); +public class SearchQueryUtils { + private static final Log log = LogFactory.getLog(SearchQueryUtils.class.getName()); public enum Conjunction { AND, OR; @@ -48,8 +48,8 @@ public class SolrQueryUtils { } /** - * Create a builder object that can assemble a map of Solr field names to - * JSON field names. + * Create a builder object that can assemble a map of search result field + * names to JSON field names. */ public static FieldMap fieldMap() { return new FieldMap(); @@ -58,25 +58,25 @@ public class SolrQueryUtils { /** * Parse a response into a list of maps, one map for each document. * - * The Solr field names in the document are replaced by json field names in - * the result, according to the fieldMap. + * The search result field names in the document are replaced by json field + * names in the result, according to the fieldMap. */ public static List> parseResponse( SearchResponse queryResponse, FieldMap fieldMap) { - return new SolrResultsParser(queryResponse, fieldMap).parse(); + return new SearchResultsParser(queryResponse, fieldMap).parse(); } /** * Parse a response into a list of maps, accepting only those maps that pass * a filter, and only up to a maximum number of records. * - * The Solr field names in the document are replaced by json field names in - * the result, according to the fieldMap. + * The search result field names in the document are replaced by json field + * names in the result, according to the fieldMap. */ public static List> parseAndFilterResponse( SearchResponse queryResponse, FieldMap fieldMap, - SolrResponseFilter filter, int maxNumberOfResults) { - return new SolrResultsParser(queryResponse, fieldMap) + SearchResponseFilter filter, int maxNumberOfResults) { + return new SearchResultsParser(queryResponse, fieldMap) .parseAndFilterResponse(filter, maxNumberOfResults); } @@ -107,8 +107,7 @@ public class SolrQueryUtils { for (String word : words) { terms.add(buildTerm(fieldName, word)); } - String q = StringUtils.join(terms, c.joiner()); - return q; + return StringUtils.join(terms, c.joiner()); } private static String buildTerm(String fieldName, String word) { @@ -116,7 +115,8 @@ public class SolrQueryUtils { } /** - * Methods that can be used in multiple places, such as IndividualListController and SolrIndividualsDataGetter + * Methods that can be used in multiple places, such as + * IndividualListController and SearchIndividualsDataGetter */ public static String getAlphaParameter(VitroRequest request){ @@ -138,13 +138,13 @@ public class SolrQueryUtils { } //Get count of individuals without actually getting the results - public static long getIndividualCount(List vclassUris, IndividualDao indDao) { - SearchEngine solr = ApplicationUtils.instance().getSearchEngine(); - SearchQuery query = solr.createQuery(makeMultiClassQuery(vclassUris)); + public static long getIndividualCount(List vclassUris) { + SearchEngine search = ApplicationUtils.instance().getSearchEngine(); + SearchQuery query = search.createQuery(makeMultiClassQuery(vclassUris)); query.setRows(0); try { SearchResponse response = null; - response = solr.query(query); + response = search.query(query); return response.getResults().getNumFound(); } catch(Exception ex) { log.error("An error occured in retrieving individual count", ex); @@ -181,7 +181,7 @@ public class SolrQueryUtils { return query; } catch (Exception ex){ - log.error("Could not make Solr query",ex); + log.error("Could not make the search query",ex); return searchEngine.createQuery(); } } @@ -202,7 +202,7 @@ public class SolrQueryUtils { return query; } catch (Exception ex){ - log.error("Could not make the Solr query",ex); + log.error("Could not make the search query",ex); return searchEngine.createQuery(); } } @@ -216,7 +216,7 @@ public class SolrQueryUtils { } return StringUtils.join(queryTypes, " AND "); } catch (Exception ex){ - log.error("Could not make Solr query",ex); + log.error("Could not make the search query",ex); return ""; } } @@ -224,9 +224,9 @@ public class SolrQueryUtils { public static IndividualListQueryResults buildAndExecuteVClassQuery( List vclassURIs, String alpha, int page, int pageSize, IndividualDao indDao) throws SearchEngineException { - SearchQuery query = SolrQueryUtils.getQuery(vclassURIs, alpha, page, pageSize); + SearchQuery query = SearchQueryUtils.getQuery(vclassURIs, alpha, page, pageSize); IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao); - log.debug("Executed solr query for " + vclassURIs); + log.debug("Executed search query for " + vclassURIs); if (results.getIndividuals().isEmpty()) { log.debug("entities list is null for vclass " + vclassURIs); } @@ -236,9 +236,9 @@ public class SolrQueryUtils { public static IndividualListQueryResults buildAndExecuteRandomVClassQuery( List vclassURIs, int page, int pageSize, IndividualDao indDao) throws SearchEngineException { - SearchQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize); + SearchQuery query = SearchQueryUtils.getRandomQuery(vclassURIs, page, pageSize); IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao); - log.debug("Executed solr query for " + vclassURIs); + log.debug("Executed search query for " + vclassURIs); if (results.getIndividuals().isEmpty()) { log.debug("entities list is null for vclass " + vclassURIs); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResponseFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResponseFilter.java new file mode 100644 index 000000000..06c7f25b4 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResponseFilter.java @@ -0,0 +1,12 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; + +import java.util.Map; + +/** + * This can be used to filter the results of the search query. + */ +public interface SearchResponseFilter { + boolean accept(Map map); +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResultsParser.java similarity index 78% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResultsParser.java index 4904489c3..9d7fe8931 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResultsParser.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/searchengine/SearchResultsParser.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.utils.solr; +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; import java.util.ArrayList; import java.util.HashMap; @@ -15,18 +15,18 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumen import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; /** - * Parse this Solr response, creating a map of values for each document. + * Parse this search response, creating a map of values for each document. * - * The Solr field names in the document are replaced by json field names in the - * parsed results, according to the fieldMap. + * The search response field names in the document are replaced by json field + * names in the parsed results, according to the fieldMap. */ -public class SolrResultsParser { - private static final Log log = LogFactory.getLog(SolrResultsParser.class); +public class SearchResultsParser { + private static final Log log = LogFactory.getLog(SearchResultsParser.class); private final SearchResponse queryResponse; private final Map fieldNameMapping; - public SolrResultsParser(SearchResponse queryResponse, FieldMap fieldMap) { + public SearchResultsParser(SearchResponse queryResponse, FieldMap fieldMap) { this.queryResponse = queryResponse; this.fieldNameMapping = fieldMap.map(); } @@ -62,7 +62,7 @@ public class SolrResultsParser { * have parsed the entire response). */ public List> parseAndFilterResponse( - SolrResponseFilter filter, int maxNumberOfResults) { + SearchResponseFilter filter, int maxNumberOfResults) { List> maps = new ArrayList>(); if (queryResponse == null) { @@ -95,10 +95,10 @@ public class SolrResultsParser { */ private Map parseSingleDocument(SearchResultDocument doc) { Map result = new HashMap(); - for (String solrFieldName : fieldNameMapping.keySet()) { - String jsonFieldName = fieldNameMapping.get(solrFieldName); - - result.put(jsonFieldName, parseSingleValue(doc, solrFieldName)); + for (String searchResultFieldName : fieldNameMapping.keySet()) { + String jsonFieldName = fieldNameMapping.get(searchResultFieldName); + result.put(jsonFieldName, + parseSingleValue(doc, searchResultFieldName)); } return result; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResponseFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResponseFilter.java deleted file mode 100644 index 3dbe9fc9f..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrResponseFilter.java +++ /dev/null @@ -1,12 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.utils.solr; - -import java.util.Map; - -/** - * This can be used to filter the results of the Solr query. - */ -public interface SolrResponseFilter { - boolean accept(Map map); -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/BrowseWidget.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/BrowseWidget.java index 635454ead..5f2d05c11 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/BrowseWidget.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/BrowseWidget.java @@ -83,7 +83,7 @@ public class BrowseWidget extends Widget { VClass vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri); map.put("class", new VClassTemplateModel(vclass)); - JSONObject vclassRes = JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), request, context); + JSONObject vclassRes = JsonServlet.getSearchIndividualsByVClass(vclass.getURI(), request); map.put("totalCount", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("totalCount") )); map.put("alpha", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("alpha") )); map.put("individuals", JsonToFmModel.convertJSONArrayToList( (JSONArray) vclassRes.get("individuals") )); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java index 558179317..8de80829f 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServletTest.java @@ -35,7 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; * TODO */ public class JsonServletTest extends AbstractTestClass { - private static final String GET_SOLR_INDIVIDUALS_BY_VCLASS = "getSolrIndividualsByVClass"; + private static final String GET_SEARCH_INDIVIDUALS_BY_VCLASS = "getSearchIndividualsByVClass"; private static final String GET_VCLASSES_FOR_VCLASS_GROUP = "getVClassesForVClassGroup"; @@ -51,16 +51,16 @@ public class JsonServletTest extends AbstractTestClass { * ents_edit_head.jsp * (there is an ents_edit.jsp, invoked from EntityEditController, which does not seem to invoke ents_edit.js) * - * GetSolrIndividualsByVClass - * Mock out SolrServer (from SolrSetup) and IndividualDao + * GetSearchIndividualsByVClass + * Mock out search engine and IndividualDao * invoked by BrowseDataGetter.java * home page * invoked by ClassGroupPageData.java * >>>> Bring up "People" tab. * invoked by BrowseWidget.java * - * GetSolrIndividualsByVClasses - * Mock out SolrServer (from SolrSetup) and IndividualDao + * GetSearchIndividualsByVClasses + * Mock out search engine and IndividualDao * invoked by IndividualsForClassesDataGetter.java * ProcessIndividualsForClasses * extended in vivo by ProcessInternalClasses @@ -85,7 +85,7 @@ public class JsonServletTest extends AbstractTestClass { private WebappDaoFactoryStub wadf; private VClassDaoStub vcDao; - private SearchEngineStub solr; + private SearchEngineStub search; @Before public void setup() throws ServletException { @@ -112,8 +112,8 @@ public class JsonServletTest extends AbstractTestClass { vcDao = new VClassDaoStub(); wadf.setVClassDao(vcDao); - solr = new SearchEngineStub(); - ApplicationStub.setup(new ServletContextStub(), solr); + search = new SearchEngineStub(); + ApplicationStub.setup(new ServletContextStub(), search); } @Test @@ -163,7 +163,7 @@ public class JsonServletTest extends AbstractTestClass { IOException { setLoggerLevel(JsonServlet.class, Level.FATAL); setLoggerLevel(JsonObjectProducer.class, Level.FATAL); - req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true"); + req.addParameter(GET_SEARCH_INDIVIDUALS_BY_VCLASS, "true"); servlet.service(req, resp); assertFailureWithErrorMessage("java.lang.Exception: " + "parameter vclassId URI parameter expected "); @@ -175,7 +175,7 @@ public class JsonServletTest extends AbstractTestClass { setLoggerLevel(JsonServlet.class, Level.FATAL); setLoggerLevel(JsonObjectProducer.class, Level.FATAL); String vclassId = "http://bogusVclass"; - req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true"); + req.addParameter(GET_SEARCH_INDIVIDUALS_BY_VCLASS, "true"); req.addParameter(VCLASS_ID, vclassId); servlet.service(req, resp); @@ -185,7 +185,8 @@ public class JsonServletTest extends AbstractTestClass { /** * TODO test successful responses. This will require figuring out how to - * stub SolrServer. It's an abstract class, so we just need to figure out + * stub SearchEngine. Since we are no longer dealing with an abstract class + * (like SolrServer), so we just need to figure out * what sort of NamedList is required as a response to a request. */ @Test @@ -195,7 +196,7 @@ public class JsonServletTest extends AbstractTestClass { setLoggerLevel(ModelAccess.class, Level.ERROR); String vclassId = "http://myVclass"; vcDao.setVClass(vclassId, new VClass(vclassId)); - req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true"); + req.addParameter(GET_SEARCH_INDIVIDUALS_BY_VCLASS, "true"); req.addParameter(VCLASS_ID, vclassId); servlet.service(req, resp); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWordsTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWordsTest.java new file mode 100644 index 000000000..5f93cbda9 --- /dev/null +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/utils/searchengine/AutoCompleteWordsTest.java @@ -0,0 +1,80 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.utils.searchengine; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import edu.cornell.mannlib.vitro.testing.AbstractTestClass; + +public class AutoCompleteWordsTest extends AbstractTestClass { + private static final String WORD_DELIMITER = "[, ]+"; + private static final String FIELD_NAME_COMPLETE = "complete"; + private static final String FIELD_NAME_PARTIAL = "partial"; + + @Test + public void nullSearchTerm() { + assertQueryString(null, ""); + } + + @Test + public void emptySearchTerm() { + assertQueryString("", ""); + } + + @Test + public void blankSearchTerm() { + assertQueryString(" ", ""); + } + + @Test + public void searchTermContainsOnlyCommas() { + assertQueryString(",,", ""); + } + + @Test + public void oneWord() { + assertQueryString("first", "partial:\"first\""); + } + + @Test + public void twoWords() { + assertQueryString("first, second", + "complete:\"first\" AND partial:\"second\""); + } + + @Test + public void threeWords() { + assertQueryString("first, second, third", + "complete:\"first\" AND complete:\"second\" AND partial:\"third\""); + } + + @Test + public void oneWordAndComma() { + assertQueryString("first,", "complete:\"first\""); + } + + @Test + public void oneWordAndCommaAndSpace() { + assertQueryString("first, ", "complete:\"first\""); + } + + @Test + public void emptyCompleteWord() { + assertQueryString(", second", "partial:\"second\""); + } + + // ---------------------------------------------------------------------- + // Helper methods + // ---------------------------------------------------------------------- + + private void assertQueryString(String searchTerm, String expected) { + AutoCompleteWords acw = new AutoCompleteWords(searchTerm, + WORD_DELIMITER); + String actual = acw.assembleQuery(FIELD_NAME_COMPLETE, + FIELD_NAME_PARTIAL); + assertEquals(expected, actual); + } + +} diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement--customDataScript.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement--customDataScript.ftl index 9500289aa..a3523fee7 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement--customDataScript.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement--customDataScript.ftl @@ -13,7 +13,7 @@ scripts list.--> "individualsForClasses": "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "sparqlQuery":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter", "fixedHtml":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter", - "solrIndividuals":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter" + "solrIndividuals":"java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchIndividualsDataGetter" } }; \ No newline at end of file From f4e81a7328cad86648c89ab14ec34a47e31c4ac8 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Tue, 22 Apr 2014 18:28:14 -0400 Subject: [PATCH 7/9] VIVO-742 Rename some 'solr' packages. --- .../search/{solr => }/SearchIndexer.java | 4 ++-- .../documentBuilding/ContextNodeFields.java | 2 +- .../documentBuilding/DocumentModifier.java | 2 +- .../ExcludeBasedOnNamespace.java | 2 +- .../documentBuilding/ExcludeBasedOnType.java | 2 +- .../ExcludeBasedOnTypeNamespace.java | 2 +- .../documentBuilding/ExcludeNonFlagVitro.java | 4 ++-- .../IndividualToSearchDocument.java | 2 +- .../documentBuilding/NameBoost.java | 2 +- .../documentBuilding/NameFields.java | 2 +- .../documentBuilding/SearchIndexExcluder.java | 2 +- .../SkipIndividualException.java | 2 +- .../documentBuilding/SourceInstitution.java | 2 +- .../SyncingExcludeBasedOnType.java | 2 +- .../documentBuilding/ThumbnailImageURL.java | 2 +- .../search/indexing/IndexWorkerThread.java | 2 +- .../searchindex/SearchIndexerSetup.java | 24 +++++++++---------- .../ExcludeBasedOnTypeTest.java | 2 +- .../ThumbnailImageURLTest.java | 8 +++---- .../{solr => documentBuilding}/testPerson.n3 | 0 20 files changed, 35 insertions(+), 35 deletions(-) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/SearchIndexer.java (98%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ContextNodeFields.java (98%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/DocumentModifier.java (89%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ExcludeBasedOnNamespace.java (92%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ExcludeBasedOnType.java (97%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ExcludeBasedOnTypeNamespace.java (96%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ExcludeNonFlagVitro.java (89%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/IndividualToSearchDocument.java (99%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/NameBoost.java (95%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/NameFields.java (97%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/SearchIndexExcluder.java (87%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/SkipIndividualException.java (76%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/SourceInstitution.java (93%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/SyncingExcludeBasedOnType.java (98%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ThumbnailImageURL.java (98%) rename webapp/test/edu/cornell/mannlib/vitro/webapp/search/{solr => }/documentBuilding/ExcludeBasedOnTypeTest.java (97%) rename webapp/test/edu/cornell/mannlib/vitro/webapp/search/{solr => documentBuilding}/ThumbnailImageURLTest.java (88%) rename webapp/test/edu/cornell/mannlib/vitro/webapp/search/{solr => documentBuilding}/testPerson.n3 (100%) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/SearchIndexer.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/SearchIndexer.java index 952c4653f..aafef4ad3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SearchIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/SearchIndexer.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr; +package edu.cornell.mannlib.vitro.webapp.search; import java.util.HashSet; @@ -18,7 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument; public class SearchIndexer implements IndexerIface { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ContextNodeFields.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ContextNodeFields.java index 010bac7b1..21bc72984 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ContextNodeFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ContextNodeFields.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.ArrayList; import java.util.Collection; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/DocumentModifier.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/DocumentModifier.java index a3ff1e8bf..7b3b6194a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/DocumentModifier.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/DocumentModifier.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnNamespace.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnNamespace.java similarity index 92% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnNamespace.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnNamespace.java index 088fe6fb2..615fdfffd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnNamespace.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnNamespace.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.Arrays; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnType.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnType.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnType.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnType.java index 97c9c5aa6..f39f567ea 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnType.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnType.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.ArrayList; import java.util.Arrays; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeNamespace.java similarity index 96% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeNamespace.java index 7e3ba57ea..60af4f0bc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeNamespace.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeNamespace.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.Arrays; import java.util.Collections; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeNonFlagVitro.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeNonFlagVitro.java index 6dec71993..61bb82dab 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeNonFlagVitro.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeNonFlagVitro.java @@ -1,7 +1,7 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; -import static edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument.DONT_EXCLUDE; +import static edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument.DONT_EXCLUDE; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/IndividualToSearchDocument.java similarity index 99% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/IndividualToSearchDocument.java index 2e29205b2..1a09dbffd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/IndividualToSearchDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/IndividualToSearchDocument.java @@ -1,7 +1,7 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.ArrayList; import java.util.HashMap; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java similarity index 95% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java index 83a23bde6..5647a1cca 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameBoost.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameFields.java similarity index 97% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameFields.java index f2943038f..06b592d53 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/NameFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameFields.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.io.BufferedReader; import java.io.IOException; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SearchIndexExcluder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SearchIndexExcluder.java similarity index 87% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SearchIndexExcluder.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SearchIndexExcluder.java index 83678288a..a34a7dde8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SearchIndexExcluder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SearchIndexExcluder.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import edu.cornell.mannlib.vitro.webapp.beans.Individual; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SkipIndividualException.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SkipIndividualException.java similarity index 76% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SkipIndividualException.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SkipIndividualException.java index ef5bc7a79..19f643c1a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SkipIndividualException.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SkipIndividualException.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; public class SkipIndividualException extends Exception{ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SourceInstitution.java similarity index 93% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SourceInstitution.java index 5a138e04c..ccd0c0ccc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SourceInstitution.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SourceInstitution.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SyncingExcludeBasedOnType.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SyncingExcludeBasedOnType.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SyncingExcludeBasedOnType.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SyncingExcludeBasedOnType.java index 3dc3f5dde..dfdf2a28d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/SyncingExcludeBasedOnType.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/SyncingExcludeBasedOnType.java @@ -1,5 +1,5 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.util.ArrayList; import java.util.List; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURL.java similarity index 98% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURL.java index 7b6a054d7..bafcd761d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ThumbnailImageURL.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURL.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.THUMBNAIL; import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.THUMBNAIL_URL; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java index cb33a9406..3e27a57cf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java @@ -11,7 +11,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; class IndexWorkerThread extends VitroBackgroundThread{ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java index 2a8543333..de51e80f1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java @@ -25,22 +25,22 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; +import edu.cornell.mannlib.vitro.webapp.search.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnNamespace; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnType; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnTypeNamespace; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeNonFlagVitro; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameBoost; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.NameFields; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SyncingExcludeBasedOnType; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL; import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalUriFinders; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.SearchReindexingListener; -import edu.cornell.mannlib.vitro.webapp.search.solr.SearchIndexer; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.DocumentModifier; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnNamespace; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnType; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeBasedOnTypeNamespace; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ExcludeNonFlagVitro; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSearchDocument; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameBoost; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.NameFields; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SearchIndexExcluder; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SyncingExcludeBasedOnType; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; /** diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeTest.java similarity index 97% rename from webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeTest.java rename to webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeTest.java index 908b62354..923751325 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/documentBuilding/ExcludeBasedOnTypeTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ExcludeBasedOnTypeTest.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -package edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import static org.junit.Assert.*; diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java similarity index 88% rename from webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java rename to webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java index 7ebf7f4ed..edce6b4a5 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java @@ -2,7 +2,7 @@ /** * */ -package edu.cornell.mannlib.vitro.webapp.search.solr; +package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; import java.io.InputStream; @@ -29,8 +29,8 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SkipIndividualException; -import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SkipIndividualException; +import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL; public class ThumbnailImageURLTest extends AbstractTestClass{ RDFServiceFactory testRDF; @@ -54,7 +54,7 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ * Test to see if ThumbnailImageURL gets the date it is suppose to gete * from a set of RDF. * - * Test method for {@link edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL#modifyDocument(edu.cornell.mannlib.vitro.webapp.beans.Individual, org.apache.solr.common.SolrInputDocument, java.lang.StringBuffer)}. + * Test method for {@link edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL#modifyDocument(edu.cornell.mannlib.vitro.webapp.beans.Individual, org.apache.solr.common.SolrInputDocument, java.lang.StringBuffer)}. */ @Test public void testThumbnailFieldCreatedInSolrDoc() { diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/testPerson.n3 similarity index 100% rename from webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 rename to webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/testPerson.n3 From cceca1659bd40916f06394548940f100dcf03596 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Wed, 23 Apr 2014 14:15:12 -0400 Subject: [PATCH 8/9] VIVO-742 Refine the search interface --- .../webapp/dao/jena/VClassGroupCache.java | 3 +- .../modules/searchEngine/SearchQuery.java | 71 ++++++++++--------- .../controller/PagedSearchController.java | 9 +-- .../searchengine/base/BaseSearchQuery.java | 45 +++--------- .../solr/SolrConversionUtils.java | 18 ++--- .../searchindex/SearchIndexerSetup.java | 16 ++--- 6 files changed, 64 insertions(+), 98 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java index bdb2cb884..9491a1f14 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java @@ -327,8 +327,7 @@ public class VClassGroupCache implements IndexingEventListener { SearchQuery query = searchEngine.createQuery(). setRows(0). setQuery(VitroSearchTermNames.CLASSGROUP_URI + ":" + groupUri ). - setFaceting(true). //facet on type to get counts for classes in classgroup - addFacetFields( facetOnField ). + addFacetFields( facetOnField ). //facet on type to get counts for classes in classgroup setFacetMinCount(0); log.debug("query: " + query); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java index 10977367a..f15d7b076 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/modules/searchEngine/SearchQuery.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.modules.searchEngine; import java.util.Collection; -import java.util.List; import java.util.Map; import java.util.Set; @@ -20,118 +19,124 @@ public interface SearchQuery { /** * Set the text of the query. This will be parsed using Lucene query syntax. + * + * @return this query */ SearchQuery setQuery(String query); /** * Where in the ordered list of result documents should the response begin? * That is, how many of the results should be skipped? (allows paging of - * results) + * results). The default is 0. + * + * @return this query */ SearchQuery setStart(int start); /** * What is the maximum number of documents that will be returned from the - * query? + * query? A negative value means no limit. The default is -1. + * + * @return this query */ SearchQuery setRows(int rows); /** * Which fields should be returned from the query? + * + * @return this query */ SearchQuery addFields(String... names); /** * Which fields should be returned from the query? + * + * @return this query */ SearchQuery addFields(Collection names); /** * What field should be used to sort the results, and in what order? + * + * @return this query */ SearchQuery addSortField(String name, Order order); /** - * Restrict the results by thisw query. + * Restrict the results by this query. + * + * @return this query */ SearchQuery addFilterQuery(String filterQuery); /** * Restrict the results by these queries. + * + * @return this query */ SearchQuery addFilterQueries(String... filterQueries); - /** - * Should the results be faceted? - */ - SearchQuery setFaceting(boolean b); - /** * What fields should be used to facet the results? + * + * @return this query */ SearchQuery addFacetFields(String... fields); /** - * Add queries that can be used to facet the results. + * The maximum number of facet counts that will be returned from the query. + * The default is 100. A negative value means no limit. + * + * @return this query */ - SearchQuery addFacetQueries(String... queries); + SearchQuery setFacetLimit(int cnt); /** - * Facet having fewer hits will be excluded from the list. + * Facet having fewer hits will be excluded from the list. The default is 0. + * + * @return this query */ SearchQuery setFacetMinCount(int cnt); /** - * Add a system-dependent parameter to the query. - */ - SearchQuery addParameter(String name, String... values); - - /** - * Get the text of the query. + * @return The text of the query. May be empty, but never null. */ String getQuery(); int getStart(); /** - * A value of -1 means that no limit has been specified. + * @return A negative value means that no limit has been specified. */ int getRows(); /** - * May return an empty set, but never null. + * @return May return an empty set, but never null. */ Set getFieldsToReturn(); /** - * May return an empty map, but never null. + * @return May return an empty map, but never null. */ Map getSortFields(); /** - * May return an empty set, but never null. + * @return May return an empty set, but never null. */ Set getFilters(); - boolean isFaceting(); - /** - * May return an empty set, but never null. + * @return May return an empty set, but never null. */ Set getFacetFields(); /** - * May return an empty set, but never null. + * @return A negative value means that no limit has been specified. */ - Set getFacetQueries(); + int getFacetLimit(); /** - * A value of -1 means that no limit has been specified. + * @return A negative value means that no limit has been specified. */ int getFacetMinCount(); - - /** - * May return an empty map, but never null. - */ - Map> getParameterMap(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index cadbf36dc..c968390d6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -484,22 +484,17 @@ public class PagedSearchController extends FreemarkerHttpServlet { query.addFilterQuery(VitroSearchTermNames.CLASSGROUP_URI + ":\"" + classgroupParam + "\""); //with ClassGroup filtering we want type facets - query.addParameter("facet","true"); - query.addParameter("facet.limit","-1"); - query.addParameter("facet.field",VitroSearchTermNames.RDFTYPE); + query.addFacetFields(VitroSearchTermNames.RDFTYPE).setFacetLimit(-1); }else if ( ! StringUtils.isBlank(typeParam) ) { // rdf:type filtering log.debug("Firing type query "); log.debug("request.getParameter(type) is "+ typeParam); query.addFilterQuery(VitroSearchTermNames.RDFTYPE + ":\"" + typeParam + "\""); - //with type filtering we don't have facets. }else{ //When no filtering is set, we want ClassGroup facets - query.addParameter("facet","true"); - query.addParameter("facet.limit","-1"); - query.addParameter("facet.field",VitroSearchTermNames.CLASSGROUP_URI); + query.addFacetFields(VitroSearchTermNames.CLASSGROUP_URI).setFacetLimit(-1); } log.debug("Query = " + query.toString()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java index eccc6b243..7b001cc2e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/base/BaseSearchQuery.java @@ -2,13 +2,11 @@ package edu.cornell.mannlib.vitro.webapp.searchengine.base; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; @@ -26,13 +24,10 @@ public class BaseSearchQuery implements SearchQuery { private final Map sortFields = new HashMap<>(); private final Set filters = new HashSet<>(); - private boolean faceting; private final Set facetFields = new HashSet<>(); - private final Set facetQueries = new HashSet<>(); + private int facetLimit = 100; private int facetMinCount = -1; - private final Map> parameterMap = new HashMap<>(); - @Override public SearchQuery setQuery(String query) { this.queryText = query; @@ -80,12 +75,6 @@ public class BaseSearchQuery implements SearchQuery { return this; } - @Override - public SearchQuery setFaceting(boolean b) { - this.faceting = b; - return this; - } - @Override public SearchQuery addFacetFields(String... fields) { facetFields.addAll(Arrays.asList(fields)); @@ -93,8 +82,8 @@ public class BaseSearchQuery implements SearchQuery { } @Override - public SearchQuery addFacetQueries(String... queries) { - facetQueries.addAll(Arrays.asList(queries)); + public SearchQuery setFacetLimit(int cnt) { + facetLimit = cnt; return this; } @@ -104,13 +93,6 @@ public class BaseSearchQuery implements SearchQuery { return this; } - @Override - public SearchQuery addParameter(String name, String... values) { - parameterMap.put(name, Collections.unmodifiableList(new ArrayList<>( - Arrays.asList(values)))); - return this; - } - @Override public String getQuery() { return queryText; @@ -141,19 +123,14 @@ public class BaseSearchQuery implements SearchQuery { return Collections.unmodifiableSet(filters); } - @Override - public boolean isFaceting() { - return faceting; - } - @Override public Set getFacetFields() { return Collections.unmodifiableSet(facetFields); } @Override - public Set getFacetQueries() { - return Collections.unmodifiableSet(facetQueries); + public int getFacetLimit() { + return facetLimit; } @Override @@ -161,19 +138,13 @@ public class BaseSearchQuery implements SearchQuery { return facetMinCount; } - @Override - public Map> getParameterMap() { - return Collections.unmodifiableMap(parameterMap); - } - @Override public String toString() { - return "BaseSearchQuery [queryText=" + queryText + ", start=" + start + return "BaseSearchQuery[queryText=" + queryText + ", start=" + start + ", rows=" + rows + ", fieldsToReturn=" + fieldsToReturn + ", sortFields=" + sortFields + ", filters=" + filters - + ", faceting=" + faceting + ", facetFields=" + facetFields - + ", facetQueries=" + facetQueries + ", facetMinCount=" - + facetMinCount + ", parameterMap=" + parameterMap + "]"; + + ", facetFields=" + facetFields + ", facetLimit=" + facetLimit + + ", facetMinCount=" + facetMinCount + "]"; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java index 98f9f3f2d..a9849491c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchengine/solr/SolrConversionUtils.java @@ -102,28 +102,24 @@ public class SolrConversionUtils { solrQuery.addFilterQuery(filter); } - solrQuery.setFacet(query.isFaceting()); + if (!query.getFacetFields().isEmpty()) { + solrQuery.setFacet(true); + } for (String facetField : query.getFacetFields()) { solrQuery.addFacetField(facetField); } - for (String facetQuery : query.getFacetQueries()) { - solrQuery.addFacetQuery(facetQuery); + int facetLimit = query.getFacetLimit(); + if (facetLimit >= 0) { + solrQuery.setFacetLimit(facetLimit); } - + int minCount = query.getFacetMinCount(); if (minCount >= 0) { solrQuery.setFacetMinCount(minCount); } - Map> parameterMap = query.getParameterMap(); - for (String parameterName : parameterMap.keySet()) { - String[] values = parameterMap.get(parameterName).toArray( - new String[0]); - solrQuery.add(parameterName, values); - } - return solrQuery; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java index de51e80f1..f55acad33 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerSetup.java @@ -77,7 +77,7 @@ public class SearchIndexerSetup implements ServletContextListener { SearchEngine searchEngine = ApplicationUtils.instance().getSearchEngine(); try { - /* set up the individual to solr doc translation */ + /* set up the individual to search doc translation */ OntModel jenaOntModel = ModelAccess.on(context).getJenaOntModel(); OntModel displayModel = ModelAccess.on(context).getDisplayModel(); @@ -100,13 +100,13 @@ public class SearchIndexerSetup implements ServletContextListener { List searchIndexExcludesFromContext = (List) context .getAttribute("SearchIndexExcludes"); - IndividualToSearchDocument indToSolrDoc = setupTransltion( + IndividualToSearchDocument indToSearchDoc = setupTranslation( jenaOntModel, displayModel, RDFServiceUtils.getRDFServiceFactory(context), modifiersFromContext, searchIndexExcludesFromContext); - /* setup solr indexer */ - SearchIndexer solrIndexer = new SearchIndexer(searchEngine, indToSolrDoc); + /* setup search indexer */ + SearchIndexer searchIndexer = new SearchIndexer(searchEngine, indToSearchDoc); // This is where the builder gets the list of places to try to // get objects to index. It is filtered so that non-public text @@ -123,7 +123,7 @@ public class SearchIndexerSetup implements ServletContextListener { .getList(rdfService, wadf.getIndividualDao()); // Make the IndexBuilder - IndexBuilder builder = new IndexBuilder(solrIndexer, wadf, + IndexBuilder builder = new IndexBuilder(searchIndexer, wadf, uriFinders); // Save it to the servlet context so we can access it later in the // webapp. @@ -135,9 +135,9 @@ public class SearchIndexerSetup implements ServletContextListener { SearchReindexingListener srl = new SearchReindexingListener(builder); ModelContext.registerListenerForChanges(ctx, srl); - ss.info(this, "Setup of Solr index completed."); + ss.info(this, "Setup of search indexer completed."); } catch (Throwable e) { - ss.fatal(this, "could not setup local solr server", e); + ss.fatal(this, "could not setup search engine", e); } } @@ -151,7 +151,7 @@ public class SearchIndexerSetup implements ServletContextListener { } - public static IndividualToSearchDocument setupTransltion( + public static IndividualToSearchDocument setupTranslation( OntModel jenaOntModel, Model displayModel, RDFServiceFactory rdfServiceFactory, List modifiersFromContext, From ad9c08cf287cdb8b026428fa6fe1bc01107acc2f Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Wed, 23 Apr 2014 14:20:14 -0400 Subject: [PATCH 9/9] VIVO-742 Many changes to remove "solr" from the code base. Comments, template names, Java classes, variables and method names (Java and JavaScript), etc. --- .../rdf/displayTbox/everytime/displayTBOX.n3 | 4 +- .../grefine/JSONReconcileServlet.java | 2 +- ...> GetRandomSearchIndividualsByVClass.java} | 8 ++-- ...GetRenderedSearchIndividualsByVClass.java} | 12 ++--- .../json/GetSearchIndividualsByVClasses.java | 2 +- .../webapp/controller/json/JsonServlet.java | 10 ++--- .../vitro/webapp/dao/DisplayVocabulary.java | 2 +- .../generators/ManagePageGenerator.java | 6 +-- .../webapp/search/beans/IndexerIface.java | 4 +- .../search/controller/IndexController.java | 6 +-- .../search/documentBuilding/NameBoost.java | 10 +++-- .../webapp/search/indexing/IndexBuilder.java | 2 +- .../search/indexing/IndexWorkerThread.java | 3 +- .../utils/dataGetter/ClassGroupPageData.java | 2 +- .../IndividualsForClassesDataGetter.java | 4 +- .../SearchIndividualsDataGetter.java | 14 +++--- .../ThumbnailImageURLTest.java | 6 +-- webapp/web/i18n/all.properties | 2 +- webapp/web/js/menupage/pageManagementUtils.js | 44 +++++++++---------- .../web/js/menupage/processDataGetterUtils.js | 2 +- .../menupage/processSolrDataGetterContent.js | 22 +++++----- .../freemarker/body/admin/searchIndex.ftl | 10 ++--- ...=> menupage--defaultSearchIndividuals.ftl} | 0 .../menupage--exampleMultipleContentTypes.ftl | 5 ++- .../edit/forms/autoCompleteObjectPropForm.ftl | 2 +- .../pageManagement--contentTemplates.ftl | 2 +- .../pageManagement--customDataScript.ftl | 2 +- ... => pageManagement--searchIndividuals.ftl} | 8 ++-- .../freemarker/edit/forms/pageManagement.ftl | 4 +- 29 files changed, 97 insertions(+), 103 deletions(-) rename webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/{GetRandomSolrIndividualsByVClass.java => GetRandomSearchIndividualsByVClass.java} (90%) rename webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/{GetRenderedSolrIndividualsByVClass.java => GetRenderedSearchIndividualsByVClass.java} (89%) rename webapp/web/templates/freemarker/body/menupage/{menupage--defaultSolrIndividuals.ftl => menupage--defaultSearchIndividuals.ftl} (100%) rename webapp/web/templates/freemarker/edit/forms/{pageManagement--solrIndividuals.ftl => pageManagement--searchIndividuals.ftl} (87%) diff --git a/webapp/rdf/displayTbox/everytime/displayTBOX.n3 b/webapp/rdf/displayTbox/everytime/displayTBOX.n3 index 0338c9a94..d2fc816e6 100644 --- a/webapp/rdf/displayTbox/everytime/displayTBOX.n3 +++ b/webapp/rdf/displayTbox/everytime/displayTBOX.n3 @@ -43,7 +43,7 @@ display:RequiredAction a owl:Class ; a owl:Class ; - rdfs:comment "A data getter for a Solr Class search, i.e. get individuals for VClass" . + rdfs:comment "A data getter for a Class search, i.e. get individuals for VClass" . a owl:Class ; @@ -141,7 +141,7 @@ owl:topObjectProperty display:hasVClassId a owl:ObjectProperty ; - rdfs:comment "Object property defining class for solr data getter" . + rdfs:comment "Object property defining class for search data getter" . ###Vitro properties without which individual templates throw errors as are required diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java index 471371f44..01ed16d9a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/grefine/JSONReconcileServlet.java @@ -454,7 +454,7 @@ public class JSONReconcileServlet extends VitroHttpServlet { } private String escapeWhitespaceInQueryString(String queryStr) { - // Solr wants whitespace to be escaped with a backslash + // The search engine wants whitespace to be escaped with a backslash return queryStr.replaceAll("\\s+", "\\\\ "); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java similarity index 90% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java index df8fd6a18..7a15f8428 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.json; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,7 +13,6 @@ import org.json.JSONException; import org.json.JSONObject; import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService; @@ -26,11 +24,11 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.Individual * Does a Solr search for individuals, and uses the short view to render each of * the results. */ -public class GetRandomSolrIndividualsByVClass extends GetSearchIndividualsByVClass { +public class GetRandomSearchIndividualsByVClass extends GetSearchIndividualsByVClass { private static final Log log = LogFactory - .getLog(GetRandomSolrIndividualsByVClass.class); + .getLog(GetRandomSearchIndividualsByVClass.class); - protected GetRandomSolrIndividualsByVClass(VitroRequest vreq) { + protected GetRandomSearchIndividualsByVClass(VitroRequest vreq) { super(vreq); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSearchIndividualsByVClass.java similarity index 89% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSearchIndividualsByVClass.java index 65ec975cf..ba95c69f4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRenderedSearchIndividualsByVClass.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.json; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,7 +13,6 @@ import org.json.JSONException; import org.json.JSONObject; import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService; @@ -23,14 +21,14 @@ import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; /** - * Does a Solr search for individuals, and uses the short view to render each of + * Does a search for individuals, and uses the short view to render each of * the results. */ -public class GetRenderedSolrIndividualsByVClass extends GetSearchIndividualsByVClasses { +public class GetRenderedSearchIndividualsByVClass extends GetSearchIndividualsByVClasses { private static final Log log = LogFactory - .getLog(GetRenderedSolrIndividualsByVClass.class); + .getLog(GetRenderedSearchIndividualsByVClass.class); - protected GetRenderedSolrIndividualsByVClass(VitroRequest vreq) { + protected GetRenderedSearchIndividualsByVClass(VitroRequest vreq) { super(vreq); } @@ -62,8 +60,6 @@ public class GetRenderedSolrIndividualsByVClass extends GetSearchIndividualsByVC return rObj; } - //Get - /** * Look through the return object. For each individual, render the short * view and insert the resulting HTML into the object. diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java index 57921ab39..c64937a17 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSearchIndividualsByVClasses.java @@ -28,7 +28,7 @@ public class GetSearchIndividualsByVClasses extends JsonObjectProducer { protected JSONObject process() throws Exception { log.debug("Executing retrieval of individuals by vclasses"); VClass vclass=null; - log.debug("Retrieving solr individuals by vclasses"); + log.debug("Retrieving search individuals by vclasses"); // Could have multiple vclass ids sent in String[] vitroClassIdStr = vreq.getParameterValues("vclassId"); if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java index 2d688b63b..c479f5a09 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java @@ -69,10 +69,10 @@ public class JsonServlet extends VitroHttpServlet { throw new IllegalArgumentException("The call invoked deprecated classes " + "and the parameter for this call appeared nowhere in the code base, " + "so it was removed in Aug 5th 2013."); - }else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){ - new GetRenderedSolrIndividualsByVClass(vreq).process(resp); - }else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){ - new GetRandomSolrIndividualsByVClass(vreq).process(resp); + }else if( vreq.getParameter("getRenderedSearchIndividualsByVClass") != null ){ + new GetRenderedSearchIndividualsByVClass(vreq).process(resp); + }else if( vreq.getParameter("getRandomSearchIndividualsByVClass") != null ){ + new GetRandomSearchIndividualsByVClass(vreq).process(resp); } else if( vreq.getParameter("getAllVClasses") != null ){ new GetAllVClasses(vreq).process(resp); } @@ -132,7 +132,7 @@ public class JsonServlet extends VitroHttpServlet { return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false); } - //Including version for Random Solr query for Vclass Intersections + //Including version for Random search query for Vclass Intersections private static IndividualListResults getRandomSearchVClassResults(String vclassURI, VitroRequest vreq){ log.debug("Retrieving random search intersection results for " + vclassURI); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java index 511644afe..e6e72abf1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java @@ -133,7 +133,7 @@ public class DisplayVocabulary { public static final String FIXED_HTML_VALUE = DISPLAY_NS + "htmlValue"; - /* URI of property for Solr Query Generator */ + /* URI of property for Search Query Generator */ public static final String VCLASSID = DISPLAY_NS + "hasVClassId"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java index 42e85f8e7..caed9de4d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java @@ -526,7 +526,7 @@ private String getExistingIsSelfContainedTemplateQuery() { MenuManagementDataUtils.includeRequiredSystemData(vreq.getSession().getServletContext(), data); data.put("classGroup", new ArrayList()); data.put("classGroups", DataGetterUtils.getClassGroups(vreq)); - //for solr individuals data get getter + //for search individuals data get getter data.put("classes", this.getAllVClasses(vreq)); data.put("availablePermissions", this.getAvailablePermissions(vreq)); data.put("availablePermissionOrderedList", this.getAvailablePermissonsOrderedURIs()); @@ -671,9 +671,9 @@ private String getExistingIsSelfContainedTemplateQuery() { return query; } - //Get all vclasses for the list of vclasses for solr + //Get all vclasses for the list of vclasses for search //Originally considered using an ajax request to get the vclasses list which is fine for adding a new content type - //but for an existing solr content type, would need to make yet another ajax request which seems too much + //but for an existing search content type, would need to make yet another ajax request which seems too much private List> getAllVClasses(VitroRequest vreq) { List vclasses = new ArrayList(); VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java index 55781137d..00bd2a8f4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java @@ -10,8 +10,8 @@ import edu.cornell.mannlib.vitro.webapp.search.IndexingException; * IndexBuilder will manage getting lists of object to index and then use * an object that implements IndexerIface to stuff the backend index. * - * An example is SolrIndexer which is set up and associated with a - * IndexBuilder in SolrSetup. + * An example is SearchIndexer which is set up and associated with a + * IndexBuilder in SearchIndexerSetup. * * @author bdc34 * diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java index 18d827e4b..151f1b670 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/IndexController.java @@ -38,8 +38,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.Work * That IndexBuilder will be associated with a object that implements the * IndexerIface. * - * An example of the IndexerIface is SolrIndexer. An example of the IndexBuilder - * and SolrIndexer setup is in SolrSetup. + * An example of the IndexerIface is SearchIndexer. An example of the IndexBuilder + * and SearchIndexer setup is in SearchIndexerSetup. * * @author bdc34 */ @@ -161,7 +161,7 @@ public class IndexController extends FreemarkerHttpServlet { ApplicationUtils.instance().getSearchEngine().ping(); return Boolean.TRUE; } catch (Exception e) { - log.error("Can't connect to the Solr server.", e); + log.error("Can't connect to the search engine.", e); return Boolean.FALSE; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java index 5647a1cca..5a0da964b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/NameBoost.java @@ -2,21 +2,23 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding; +import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_LOWERCASE; +import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW; +import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_STEMMED; +import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_UNSTEMMED; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField; -import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; public class NameBoost implements DocumentModifier { /** - * These are the fields in the solr Document that + * These are the fields in the search Document that * are related to the name. If you modify the schema, * please consider if you need to change this list * of name fields to boost. */ - static final VitroSearchTermNames term = new VitroSearchTermNames(); - String[] fieldsToBoost = {term.NAME_RAW,term.NAME_LOWERCASE,term.NAME_UNSTEMMED,term.NAME_STEMMED}; + String[] fieldsToBoost = {NAME_RAW,NAME_LOWERCASE,NAME_UNSTEMMED,NAME_STEMMED}; final float boost; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index 69e2ba3ee..f923cd42e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -33,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; * The IndexBuilder is used to rebuild or update a search index. * There should only be one IndexBuilder in a vitro web application. * It uses an implementation of a back-end through an object that - * implements IndexerIface. An example of a back-end is SolrIndexer. + * implements IndexerIface. An example of a back-end is SearchIndexer. * * See the class SearchReindexingListener for an example of how a model change * listener can use an IndexBuilder to keep the full text index in sncy with diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java index 3e27a57cf..8ca506c98 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexWorkerThread.java @@ -11,14 +11,12 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.IndexerIface; -import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.IndividualToSearchDocument; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; class IndexWorkerThread extends VitroBackgroundThread{ private static final Log log = LogFactory.getLog(IndexWorkerThread.class); protected final int threadNum; - protected IndividualToSearchDocument individualToSolrDoc; protected final IndexerIface indexer; protected final Iterator individualsToIndex; protected boolean stopRequested = false; @@ -38,6 +36,7 @@ class IndexWorkerThread extends VitroBackgroundThread{ stopRequested = true; } + @Override public void run(){ setWorkLevel(WorkLevel.WORKING, "indexing " + individualsToIndex + " individuals"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/ClassGroupPageData.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/ClassGroupPageData.java index 8952c38d6..5560d259d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/ClassGroupPageData.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/ClassGroupPageData.java @@ -160,7 +160,7 @@ public class ClassGroupPageData extends DataGetterBase implements DataGetter{ //Get data servuice public String getDataServiceUrl() { - return UrlBuilder.getUrl("/dataservice?getRenderedSolrIndividualsByVClass=1&vclassId="); + return UrlBuilder.getUrl("/dataservice?getRenderedSearchIndividualsByVClass=1&vclassId="); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java index 7e4aa1d34..25f0ff7fc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/IndividualsForClassesDataGetter.java @@ -210,7 +210,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D //update class count based on restrict classes private int retrieveCount(VitroRequest vreq, ServletContext context, VClass v, List restrictClasses) { - //Execute solr query that returns only count of individuals + //Execute search query that returns only count of individuals log.debug("Entity count is " + v.getEntityCount()); List classUris = new ArrayList(); classUris.add(v.getURI()); @@ -351,7 +351,7 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D //Get data servuice public String getDataServiceUrl() { - return UrlBuilder.getUrl("/dataservice?getRenderedSolrIndividualsByVClass=1&vclassId="); + return UrlBuilder.getUrl("/dataservice?getRenderedSearchIndividualsByVClass=1&vclassId="); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java index 944f79b3a..753f1c56c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SearchIndividualsDataGetter.java @@ -47,7 +47,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG final static Log log = LogFactory.getLog(SearchIndividualsDataGetter.class); //default template - private final static String defaultTemplate = "menupage--defaultSolrIndividuals.ftl"; + private final static String defaultTemplate = "menupage--defaultSearchIndividuals.ftl"; /** * Constructor with display model and data getter URI that will be called by reflection. @@ -67,7 +67,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG merged.put(key, new String[] {String.valueOf(pageData.get(key))}); } - return doSolrQuery( merged); + return doSearchQuery( merged); } /** @@ -125,12 +125,12 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG //Partially copied from IndividualListController - private Map doSolrQuery( Map merged) { + private Map doSearchQuery( Map merged) { if(vclassUris.size() == 0) { if(merged.containsKey("vclassuri")) { this.vclassUris = Arrays.asList(merged.get("vclassuri")); } else { - log.error("No vclass uri found. Solr query will not work"); + log.error("No vclass uri found. Search query will not work"); } } @@ -160,7 +160,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG body.put("subtitle", vclass.getName()); } body.put("title", title); - populateSolrQueryResults(vclass, body); + populateSearchQueryResults(vclass, body); body.put("bodyTemplate", this.defaultTemplate); } else { log.error("No VClass URIs found. No query will be executed"); @@ -168,7 +168,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG return body; } - private void populateSolrQueryResults(VClass vclass, Map body) { + private void populateSearchQueryResults(VClass vclass, Map body) { try { String alpha = SearchQueryUtils.getAlphaParameter(vreq); int page = SearchQueryUtils.getPageParameter(vreq); @@ -203,7 +203,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG public static final String defaultVarNameForResults = "results"; /** - * Query to get the definition of the Solr individuals data getter for a given URI. + * Query to get the definition of the search individuals data getter for a given URI. */ private static final String dataGetterQuery = "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java index edce6b4a5..1c963c99d 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/documentBuilding/ThumbnailImageURLTest.java @@ -53,11 +53,9 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ /** * Test to see if ThumbnailImageURL gets the date it is suppose to gete * from a set of RDF. - * - * Test method for {@link edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ThumbnailImageURL#modifyDocument(edu.cornell.mannlib.vitro.webapp.beans.Individual, org.apache.solr.common.SolrInputDocument, java.lang.StringBuffer)}. */ @Test - public void testThumbnailFieldCreatedInSolrDoc() { + public void testThumbnailFieldCreatedInSearchDoc() { SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument(); ThumbnailImageURL testMe = new ThumbnailImageURL( testRDF ); Individual ind = new IndividualImpl(); @@ -70,7 +68,7 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ Assert.fail("Test individual was skipped by classes that build the search document: " + e.getMessage()); } - //make sure that a Solr document field got created for the thumbnail image + //make sure that a search document field got created for the thumbnail image SearchInputField thumbnailField = doc.getField( VitroSearchTermNames.THUMBNAIL_URL ); Assert.assertNotNull(thumbnailField); diff --git a/webapp/web/i18n/all.properties b/webapp/web/i18n/all.properties index 0fce78764..9d3439c58 100644 --- a/webapp/web/i18n/all.properties +++ b/webapp/web/i18n/all.properties @@ -592,7 +592,7 @@ page_text = page text sparql_query_results = Sparql Query Results no_results_returned = No results were returned. -solr_individual_results = Solr Class Individuals +solr_individual_results = Search Class Individuals select_vclass_uri = Select VClass # # manage proxies templates ( /templates/freemarker/body/manageproxies ) diff --git a/webapp/web/js/menupage/pageManagementUtils.js b/webapp/web/js/menupage/pageManagementUtils.js index f0dd32258..456092bbb 100644 --- a/webapp/web/js/menupage/pageManagementUtils.js +++ b/webapp/web/js/menupage/pageManagementUtils.js @@ -104,7 +104,7 @@ var pageManagementUtils = { this.classGroupSection = $("section#browseClassGroup"); this.sparqlQuerySection = $("section#sparqlQuery"); this.fixedHTMLSection = $("section#fixedHtml"); - this.solrIndividualsSection = $("section#solrIndividuals"); + this.searchIndividualsSection = $("section#searchIndividuals"); //From original menu management edit this.defaultTemplateRadio = $('input.default-template'); this.customTemplateRadio = $('input.custom-template'); @@ -133,8 +133,8 @@ var pageManagementUtils = { this.rightSideDiv = $("div#rightSide"); //contentDivs container where content added/existing placed this.savedContentDivs = $("section#contentDivs"); - //for solr individuals data getter - this.solrAllClassesDropdown = $("select#vclassUri"); + //for search individuals data getter + this.searchAllClassesDropdown = $("select#vclassUri"); }, initDisplay: function(){ //right side components @@ -147,7 +147,7 @@ var pageManagementUtils = { this.classGroupSection.hide(); this.sparqlQuerySection.hide(); this.fixedHTMLSection.hide(); - this.solrIndividualsSection.hide(); + this.searchIndividualsSection.hide(); this.classesForClassGroup.addClass('hidden'); //left side components //These depend on whether or not this is an existing item or not @@ -160,14 +160,14 @@ var pageManagementUtils = { this.menuSection.hide(); } } - //populates the dropdown of classes for the solr individuals template + //populates the dropdown of classes for the search individuals template //dropdown now populated in template/from form specific data instead of ajax request - //this.populateClassForSolrDropdown(); + //this.populateClassForSearchDropdown(); }, //this method can be utilized if using an ajax request to get the vclasses /* - //for solr individuals - remember this populates the template class dropdown - populateClassForSolrDropdown:function() { + //for search individuals - remember this populates the template class dropdown + populateClassForSearchDropdown:function() { //Run ajax query var url = "dataservice?getAllVClasses=1"; @@ -176,10 +176,10 @@ var pageManagementUtils = { $.getJSON(url, function(results) { //Moved the function to processClassGroupDataGetterContent //Should probably remove this entire method and copy there - pageManagementUtils.displayAllClassesForSolrDropdown(results); + pageManagementUtils.displayAllClassesForSearchDropdown(results); }); }, - displayAllClassesForSolrDropdown:function(results) { + displayAllClassesForSearchDropdown:function(results) { if ( results.classes.length == 0 ) { } else { @@ -193,7 +193,7 @@ var pageManagementUtils = { //if there are options to add if(appendHtml != "") { - pageManagementUtils.solrAllClassesDropdown.html(appendHtml); + pageManagementUtils.searchAllClassesDropdown.html(appendHtml); } } @@ -285,7 +285,7 @@ var pageManagementUtils = { pageManagementUtils.classGroupSection.hide(); pageManagementUtils.fixedHTMLSection.hide(); pageManagementUtils.sparqlQuerySection.hide(); - pageManagementUtils.solrIndividualsSection.hide(); + pageManagementUtils.searchIndividualsSection.hide(); //Reset main content type drop-down pageManagementUtils.contentTypeSelectOptions.eq(0).attr('selected', 'selected'); if ( pageManagementUtils.leftSideDiv.css("height") != undefined ) { @@ -357,31 +357,31 @@ var pageManagementUtils = { pageManagementUtils.classGroupSection.show(); pageManagementUtils.fixedHTMLSection.hide(); pageManagementUtils.sparqlQuerySection.hide(); - pageManagementUtils.solrIndividualsSection.hide(); + pageManagementUtils.searchIndividualsSection.hide(); pageManagementUtils.headerBar.text(pageManagementUtils.browseClassGroup + " - "); pageManagementUtils.headerBar.show(); $('div#selfContainedDiv').hide(); } - if ( _this.contentTypeSelect.val() == "fixedHtml" || _this.contentTypeSelect.val() == "sparqlQuery" || _this.contentTypeSelect.val() == "solrIndividuals") { + if ( _this.contentTypeSelect.val() == "fixedHtml" || _this.contentTypeSelect.val() == "sparqlQuery" || _this.contentTypeSelect.val() == "searchIndividuals") { pageManagementUtils.classGroupSection.hide(); //if fixed html show that, otherwise show sparql results if ( _this.contentTypeSelect.val() == "fixedHtml" ) { pageManagementUtils.headerBar.text(pageManagementUtils.fixedHtml + " - "); pageManagementUtils.fixedHTMLSection.show(); pageManagementUtils.sparqlQuerySection.hide(); - pageManagementUtils.solrIndividualsSection.hide(); + pageManagementUtils.searchIndividualsSection.hide(); } else if (_this.contentTypeSelect.val() == "sparqlQuery"){ pageManagementUtils.headerBar.text(pageManagementUtils.sparqlResults + " - "); pageManagementUtils.sparqlQuerySection.show(); pageManagementUtils.fixedHTMLSection.hide(); - pageManagementUtils.solrIndividualsSection.hide(); + pageManagementUtils.searchIndividualsSection.hide(); } else { - //solr individuals - pageManagementUtils.headerBar.text(pageManagementUtils.solrIndividuals + " - "); + //search individuals + pageManagementUtils.headerBar.text(pageManagementUtils.searchIndividuals + " - "); pageManagementUtils.sparqlQuerySection.hide(); pageManagementUtils.fixedHTMLSection.hide(); - pageManagementUtils.solrIndividualsSection.show(); + pageManagementUtils.searchIndividualsSection.show(); } pageManagementUtils.headerBar.show(); @@ -392,7 +392,7 @@ var pageManagementUtils = { pageManagementUtils.classGroupSection.hide(); pageManagementUtils.fixedHTMLSection.hide(); pageManagementUtils.sparqlQuerySection.hide(); - pageManagementUtils.solrIndividualsSection.hide(); + pageManagementUtils.searchIndividualsSection.hide(); pageManagementUtils.classesForClassGroup.addClass('hidden'); pageManagementUtils.headerBar.hide(); pageManagementUtils.headerBar.text(""); @@ -430,7 +430,7 @@ var pageManagementUtils = { pageManagementUtils.clearInputs(pageManagementUtils.fixedHTMLSection); pageManagementUtils.clearInputs(pageManagementUtils.sparqlQuerySection); pageManagementUtils.clearInputs(pageManagementUtils.classGroupSection); - pageManagementUtils.clearInputs(pageManagementUtils.solrIndividualsSection); + pageManagementUtils.clearInputs(pageManagementUtils.searchIndividualsSection); }, clearInputs:function($el) { @@ -474,7 +474,7 @@ var pageManagementUtils = { // Get rid of the cancel link; it'll be replaced by a delete link $newContentObj.find('span#cancelContent' + counter).html(''); - if ( contentType == "sparqlQuery" || contentType == "fixedHtml" || contentType == "solrIndividuals") { + if ( contentType == "sparqlQuery" || contentType == "fixedHtml" || contentType == "searchIndividuals") { varOrClass = $newContentObj.find('input[name="saveToVar"]').val(); } else if ( contentType == "browseClassGroup" ) { diff --git a/webapp/web/js/menupage/processDataGetterUtils.js b/webapp/web/js/menupage/processDataGetterUtils.js index e7b9cd0c9..009c00ada 100644 --- a/webapp/web/js/menupage/processDataGetterUtils.js +++ b/webapp/web/js/menupage/processDataGetterUtils.js @@ -10,7 +10,7 @@ var processDataGetterUtils = { "sparqlQuery": processSparqlDataGetterContent, "fixedHtml":processFixedHTMLDataGetterContent, "individualsForClasses":processIndividualsForClassesDataGetterContent, - "solrIndividuals":processSolrDataGetterContent}, + "searchIndividuals":processSearchDataGetterContent}, selectDataGetterType:function(pageContentSection) { var contentType = pageContentSection.attr("contentType"); //The form can provide "browse class group" as content type but need to check diff --git a/webapp/web/js/menupage/processSolrDataGetterContent.js b/webapp/web/js/menupage/processSolrDataGetterContent.js index 0e1026b5e..13de2d641 100644 --- a/webapp/web/js/menupage/processSolrDataGetterContent.js +++ b/webapp/web/js/menupage/processSolrDataGetterContent.js @@ -1,9 +1,9 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -$.extend(this, i18nStringsSolrIndividuals); +$.extend(this, i18nStringsSearchIndividuals); //Process sparql data getter and provide a json object with the necessary information -var processSolrDataGetterContent = { +var processSearchDataGetterContent = { dataGetterClass:null, //can use this if expect to initialize from elsewhere initProcessor:function(dataGetterClass) { @@ -30,13 +30,13 @@ var processSolrDataGetterContent = { //Now find and set value pageContentSection.find("input[name='saveToVar']").val(saveToVarValue); - //set value of solr query + //set value of query pageContentSection.find("select[name='vclassUri']").val(vclassUriValue); }, //For the label of the content section for editing, need to add additional value retrieveContentLabel:function() { - return i18nStringsSolrIndividuals.solrIndividuals; + return i18nStringsSearchIndividuals.searchIndividuals; }, //For the label of the content section for editing, need to add additional value retrieveAdditionalLabelText:function(existingContentObject) { @@ -49,20 +49,20 @@ var processSolrDataGetterContent = { //Check that vclassuri and saveToVar have been input var variableValue = pageContentSection.find("input[name='saveToVar']").val(); if(variableValue == "") { - validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.supplyQueryVariable + "
" + validationError += pageContentSectionLabel + ": " + i18nStringsSearchIndividuals.supplyQueryVariable + "
" } - if(processSolrDataGetterContent.stringHasSingleQuote(variableValue)) { - validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.noApostrophes + "
"; + if(processSearchDataGetterContent.stringHasSingleQuote(variableValue)) { + validationError += pageContentSectionLabel + ": " + i18nStringsSearchIndividuals.noApostrophes + "
"; } - if(processSolrDataGetterContent.stringHasDoubleQuote(variableValue)) { - validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.noDoubleQuotes + "
"; + if(processSearchDataGetterContent.stringHasDoubleQuote(variableValue)) { + validationError += pageContentSectionLabel + ": " + i18nStringsSearchIndividuals.noDoubleQuotes + "
"; } - //validation for solr individuals + //validation for search individuals var vclassUriValue = pageContentSection.find("select[name='vclassUri']").val(); if(vclassUriValue == "") { - validationError += pageContentSectionLabel + ": " + i18nStringsSolrIndividuals.selectClass + "
"; + validationError += pageContentSectionLabel + ": " + i18nStringsSearchIndividuals.selectClass + "
"; } return validationError; }, diff --git a/webapp/web/templates/freemarker/body/admin/searchIndex.ftl b/webapp/web/templates/freemarker/body/admin/searchIndex.ftl index 6486e17c8..06b609b24 100644 --- a/webapp/web/templates/freemarker/body/admin/searchIndex.ftl +++ b/webapp/web/templates/freemarker/body/admin/searchIndex.ftl @@ -7,16 +7,16 @@

${i18n().search_index_status}

<#if !indexIsConnected> - + <#elseif worklevel == "IDLE"> - +

${i18n().search_indexer_idle}

<#if hasPreviousBuild??>

${i18n().most_recent_update} ${since?string("hh:mm:ss a, MMMM dd, yyyy")}

@@ -30,12 +30,12 @@ <#elseif totalToDo == 0> - +

${i18n().preparing_to_rebuild_index}

${i18n().since_elapsed_time(since?string("hh:mm:ss a, MMMM dd, yyyy"),elapsed)}

<#else> - +

${i18n().current_task(currentTask)}

${i18n().since_elapsed_time_est_total(since?string("hh:mm:ss a, MMMM dd, yyyy"),elapsed,expected)}

${i18n().index_recs_completed(completedCount,totalToDo)}

diff --git a/webapp/web/templates/freemarker/body/menupage/menupage--defaultSolrIndividuals.ftl b/webapp/web/templates/freemarker/body/menupage/menupage--defaultSearchIndividuals.ftl similarity index 100% rename from webapp/web/templates/freemarker/body/menupage/menupage--defaultSolrIndividuals.ftl rename to webapp/web/templates/freemarker/body/menupage/menupage--defaultSearchIndividuals.ftl diff --git a/webapp/web/templates/freemarker/body/menupage/menupage--exampleMultipleContentTypes.ftl b/webapp/web/templates/freemarker/body/menupage/menupage--exampleMultipleContentTypes.ftl index 7eca46eac..bc1af5363 100644 --- a/webapp/web/templates/freemarker/body/menupage/menupage--exampleMultipleContentTypes.ftl +++ b/webapp/web/templates/freemarker/body/menupage/menupage--exampleMultipleContentTypes.ftl @@ -1,5 +1,6 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> -<#--This is an example of including multiple content types in the same template, this combines the default templates for Fixed HTML, Class groups and Solr Individuals in one template--> +<#--This is an example of including multiple content types in the same template, + this combines the default templates for Fixed HTML, Class groups and Search Individuals in one template--> <#include "menupage-checkForData.ftl"> <#--Fixed HTML portion--> <#--Note that variableName is employed by both the fixed html and sparql query templates, this is used to store the @@ -32,7 +33,7 @@ variableName is used below.--> ${noDataNotification} -<#--Solr Individuals section--> +<#--Search Individuals section--> <#import "lib-list.ftl" as l> <#include "individualList-checkForData.ftl"> diff --git a/webapp/web/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl b/webapp/web/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl index a9a74c0a1..457a02d31 100644 --- a/webapp/web/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl @@ -103,7 +103,7 @@ <#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" > <#--Passing in object types only if there are any types returned, otherwise -the parameter should not be passed at all to the solr search. +the parameter should not be passed at all to the search. Also multiple types parameter set to true only if more than one type returned--> \ No newline at end of file diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement--solrIndividuals.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement--searchIndividuals.ftl similarity index 87% rename from webapp/web/templates/freemarker/edit/forms/pageManagement--solrIndividuals.ftl rename to webapp/web/templates/freemarker/edit/forms/pageManagement--searchIndividuals.ftl index 38610fd11..31f427226 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement--solrIndividuals.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement--searchIndividuals.ftl @@ -3,7 +3,7 @@ <#assign classGroup = pageData.classGroup /> <#assign classGroups = pageData.classGroups /> <#assign classes = pageData.classes /> -
+
@@ -21,8 +21,8 @@
-${scripts.add('')} +${scripts.add('')} diff --git a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl index 2d248e65f..71e9c9b01 100644 --- a/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/pageManagement.ftl @@ -81,7 +81,7 @@ - +  ${i18n().add_types}
@@ -179,7 +179,7 @@ browseClassGroup: '${i18n().browse_class_group}', fixedHtml: '${i18n().fixed_html}', sparqlResults: '${i18n().sparql_query_results}', - solrIndividuals: '${i18n().solr_individual_results}', + searchIndividuals: '${i18n().solr_individual_results}', orString: '${i18n().or}', deleteString: '${i18n().delete}', allCapitalized: '${i18n().all_capitalized}',