Project

General

Profile

« Previous | Next » 

Revision 62378

[maven-release-plugin] copy for tag uoa-search-3.8.3

View differences:

modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/utils/vocabulary/VocabularyFactoryImpl.java
1
package eu.dnetlib.data.search.utils.vocabulary;
2

  
3

  
4
public class VocabularyFactoryImpl {
5

  
6
	public static void createXmlVocabulary(Vocabulary vocabulary) {
7

  
8
	}
9
	
10
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/utils/vocabulary/LocalVocabularyLoader.java
1
package eu.dnetlib.data.search.utils.vocabulary;
2

  
3
import gr.uoa.di.driver.xml.VocabularyXmlConverter;
4
import org.apache.commons.io.IOUtils;
5
import org.apache.log4j.Logger;
6

  
7
import javax.xml.bind.JAXBException;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.util.Locale;
11
import java.util.StringTokenizer;
12

  
13
/**
14
 * Loads vocabulary from the classpath
15
 * @author kiatrop
16
 *
17
 */
18
public class LocalVocabularyLoader extends VocabularyLoader {
19
	
20
	private static final Logger logger = Logger.getLogger(LocalVocabularyLoader.class);
21
	
22
	@Override
23
	public eu.dnetlib.domain.enabling.Vocabulary getVocabulary(Vocabulary vocabulary, Locale locale) {
24
		logger.debug("Getting vocabulary with name " + vocabulary.getName() + " and locale " + locale);
25
		
26
		String xml = null;
27
		StringTokenizer tokenizer = new StringTokenizer(((LocalVocabulary)vocabulary).getFileName(), ".");
28
		String localizedVocabularyName = tokenizer.nextToken() +  "_" +
29
				locale.getLanguage() + "_" + locale.getCountry() + "." + tokenizer.nextToken();
30
		
31
		InputStream xmlInputStream = this.getClass().getClassLoader().getResourceAsStream(localizedVocabularyName);
32
		
33
		if (xmlInputStream == null) {
34
			logger.debug("The " + localizedVocabularyName + " does not exist in classpath. Loading default vocabulary instead.");
35
			xmlInputStream = this.getClass().getClassLoader().getResourceAsStream(((LocalVocabulary)vocabulary).getFileName());
36
		}
37
		
38
		if (xmlInputStream == null) {
39
			logger.warn("The " + ((LocalVocabulary)vocabulary).getFileName() + " does not exist in classpath.");
40
			return null; //null
41
		}
42
		
43
		try {
44
			xml = IOUtils.toString(xmlInputStream, "UTF-8");
45

  
46
			if (xml!=null && !xml.trim().isEmpty()) {
47
				VocabularyXmlConverter converter = null;
48

  
49
				converter = new VocabularyXmlConverter();
50
				return converter.XmlToObject(xml);
51
			}
52
			
53
		} catch (IOException ioe) {
54
			logger.debug("Problem loading " + localizedVocabularyName + " from classpath", ioe);
55

  
56
		} catch (JAXBException jaxbe) {
57
			logger.error("Unable to load vocabulary " + vocabulary.getName(), jaxbe);
58

  
59
		} finally {
60
            IOUtils.closeQuietly(xmlInputStream);
61
        }
62

  
63
		return null;
64
	}
65
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/utils/vocabulary/LocalVocabulary.java
1
package eu.dnetlib.data.search.utils.vocabulary;
2

  
3
public class LocalVocabulary extends Vocabulary{
4
	
5
	/** the name of the vocabulary in classpath */
6
	private final String fileName;
7

  
8
	public LocalVocabulary(String name, String filename) {
9
		super(name);
10
		this.fileName = filename;
11
	}
12
	
13
	public String getFileName() {
14
		return fileName;
15
	}
16
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/utils/vocabulary/Vocabulary.java
1
package eu.dnetlib.data.search.utils.vocabulary;
2

  
3
public abstract class Vocabulary {
4

  
5
	private final String name;
6

  
7
	public String getName() {
8
		return name;
9
	}
10
	
11
	public Vocabulary(String name) {
12
		this.name = name;
13
	}
14
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/micrometer/PrometheusRequestTimerInterceptor.java
1
package eu.dnetlib.data.search.micrometer;
2

  
3
import org.springframework.stereotype.Component;
4
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
5

  
6
@Component
7
public class PrometheusRequestTimerInterceptor extends HandlerInterceptorAdapter{
8

  
9
    /*private PrometheusMeterRegistry prometheusRegistry;
10
    private DistributionSummary summary;
11

  
12
    PrometheusRequestTimerInterceptor(){}
13

  
14
    PrometheusRequestTimerInterceptor(PrometheusMeterRegistry prometheusMeterRegistry) {
15
        this.prometheusRegistry = prometheusMeterRegistry;
16

  
17
        summary = DistributionSummary.builder("search.server.response.size")
18
                .publishPercentileHistogram()
19
                .sla(1000000, 2500000, 3500000)
20
                .minimumExpectedValue((long) 1000000)
21
                .maximumExpectedValue((long) 3500000)
22
                .scale(500000)
23
                .register(prometheusRegistry);
24
    }
25

  
26
    @Override
27
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
28
            throws Exception {
29
        summary.record((double)response.getBufferSize());
30

  
31
    }
32

  
33
    @Override
34
    public void postHandle(
35
            HttpServletRequest request,
36
            HttpServletResponse response,
37
            Object handler,
38
            ModelAndView modelAndView) throws Exception {
39

  
40
    }*/
41
}
modules/uoa-search/tags/uoa-search-3.8.3/pom.xml
1
<?xml version="1.0"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>uoa-search</artifactId>
11
	<packaging>jar</packaging>
12
	<version>3.8.3</version>
13
	<scm>
14
                <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-search/tags/uoa-search-3.8.3</developerConnection> 
15
        </scm>
16

  
17
    <repositories>
18
        <!-- Cloudera Repositories -->
19
        <repository>
20
            <snapshots>
21
                <enabled>false</enabled>
22
            </snapshots>
23
            <id>cloudera-central</id>
24
            <name>cloundera-libs-release</name>
25
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/cloudera-central</url>
26
        </repository>
27
        <repository>
28
            <id>cloudera-snapshots</id>
29
            <name>cloudera-libs-snapshot</name>
30
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/cloudera-snapshots</url>
31
        </repository>
32
        <repository>
33
            <id>typesafe</id>
34
            <name>typesafe-releases</name>
35
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/typesafe</url>
36
        </repository>
37
    </repositories>
38

  
39
	<dependencies>
40
		<dependency>
41
			<groupId>junit</groupId>
42
			<artifactId>junit</artifactId>
43
			<version>${junit.version}</version>
44
			<scope>test</scope>
45
		</dependency>
46
		<dependency>
47
			<groupId>eu.dnetlib</groupId>
48
			<artifactId>uoa-commons</artifactId>
49
			<version>[2.0.0, 3.0.0)</version>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.mockito</groupId>
53
			<artifactId>mockito-all</artifactId>
54
			<version>1.6</version>
55
		</dependency>
56
		<dependency>
57
			<groupId>org.apache.solr</groupId>
58
			<artifactId>solr-solrj</artifactId>
59
			<version>7.2.1</version>
60
            <exclusions>
61
                <exclusion>
62
                    <groupId>org.apache.zookeeper</groupId>
63
                    <artifactId>zookeeper</artifactId>
64
                </exclusion>
65
            </exclusions>
66
		</dependency>
67
        <dependency>
68
            <groupId>org.apache.zookeeper</groupId>
69
            <artifactId>zookeeper</artifactId>
70
            <version>3.4.5-cdh4.3.0</version>
71
        </dependency>
72
		<dependency>
73
			<groupId>eu.dnetlib</groupId>
74
			<artifactId>cnr-cql-utils</artifactId>
75
			<version>[2.0.0, 3.0.0)</version>
76
			<scope>compile</scope>
77
		</dependency>
78
		<dependency>
79
			<groupId>eu.dnetlib</groupId>
80
			<artifactId>cnr-blackboard-common</artifactId>
81
			<version>[2.2.1, 3.0.0)</version>
82
		</dependency>
83

  
84
		<!-- Spring MVC framework -->
85
		<dependency>
86
			<groupId>org.springframework</groupId>
87
			<artifactId>spring-webmvc</artifactId>
88
			<version>${spring.version}</version>
89
		</dependency>
90

  
91
		<dependency>
92
			<groupId>org.apache.velocity</groupId>
93
			<artifactId>velocity</artifactId>
94
			<version>1.7</version>
95
		</dependency>
96

  
97
		<dependency>
98
			<groupId>asm</groupId>
99
			<artifactId>asm</artifactId>
100
			<version>3.3.1</version>
101
		</dependency>
102
		<dependency>
103
			<groupId>com.sun.jersey</groupId>
104
			<artifactId>jersey-bundle</artifactId>
105
			<version>1.19</version>
106
		</dependency>
107
		<dependency>
108
			<groupId>org.json</groupId>
109
			<artifactId>json</artifactId>
110
			<version>20140107</version>
111
		</dependency>
112
		<dependency>
113
			<groupId>com.sun.jersey</groupId>
114
			<artifactId>jersey-server</artifactId>
115
			<version>1.19</version>
116
		</dependency>
117
		<dependency>
118
			<groupId>com.sun.jersey</groupId>
119
			<artifactId>jersey-core</artifactId>
120
			<version>1.19</version>
121
		</dependency>
122
		<dependency>
123
			<groupId>commons-validator</groupId>
124
			<artifactId>commons-validator</artifactId>
125
			<version>1.6</version>
126
		</dependency>
127
		<dependency>
128
			<groupId>org.eclipse.persistence</groupId>
129
			<artifactId>org.eclipse.persistence.moxy</artifactId>
130
			<version>2.5.0</version>
131
		</dependency>
132
		<dependency>
133
			<groupId>com.sun.jersey.contribs</groupId>
134
			<artifactId>jersey-spring</artifactId>
135
			<version>1.8</version>
136
			<exclusions>
137
				<exclusion>
138
					<groupId>org.springframework</groupId>
139
					<artifactId>spring</artifactId>
140
				</exclusion>
141
				<exclusion>
142
					<groupId>org.springframework</groupId>
143
					<artifactId>spring-core</artifactId>
144
				</exclusion>
145
				<exclusion>
146
					<groupId>org.springframework</groupId>
147
					<artifactId>spring-web</artifactId>
148
				</exclusion>
149
				<exclusion>
150
					<groupId>org.springframework</groupId>
151
					<artifactId>spring-beans</artifactId>
152
				</exclusion>
153
				<exclusion>
154
					<groupId>org.springframework</groupId>
155
					<artifactId>spring-context</artifactId>
156
				</exclusion>
157
				<exclusion>
158
					<groupId>org.springframework</groupId>
159
					<artifactId>spring-utils</artifactId>
160
				</exclusion>
161
				<exclusion>
162
					<groupId>org.springframework</groupId>
163
					<artifactId>spring-aop</artifactId>
164
				</exclusion>
165
			</exclusions>
166
		</dependency>
167
		<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
168
		<dependency>
169
			<groupId>com.google.code.gson</groupId>
170
			<artifactId>gson</artifactId>
171
			<version>2.3.1</version>
172
		</dependency>
173
		<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
174
		<dependency>
175
			<groupId>org.apache.commons</groupId>
176
			<artifactId>commons-lang3</artifactId>
177
			<version>3.5</version>
178
		</dependency>
179

  
180
		<dependency>
181
			<groupId>io.prometheus</groupId>
182
			<artifactId>simpleclient</artifactId>
183
			<version>0.6.0</version>
184
		</dependency>
185

  
186
		<dependency>
187
			<groupId>io.prometheus</groupId>
188
			<artifactId>simpleclient_servlet</artifactId>
189
			<version>0.6.0</version>
190
		</dependency>
191

  
192
		<dependency>
193
			<groupId>io.prometheus</groupId>
194
			<artifactId>simpleclient_hotspot</artifactId>
195
			<version>0.6.0</version>
196
		</dependency>
197

  
198
		<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
199
		<dependency>
200
			<groupId>io.micrometer</groupId>
201
			<artifactId>micrometer-registry-prometheus</artifactId>
202
			<version>1.2.0</version>
203
		</dependency>
204

  
205
		<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-spring-legacy -->
206
		<dependency>
207
			<groupId>io.micrometer</groupId>
208
			<artifactId>micrometer-spring-legacy</artifactId>
209
			<version>1.2.0</version>
210
		</dependency>
211

  
212

  
213
		<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
214
		<!-- AspectJ -->
215
		<dependency>
216
			<groupId>org.aspectj</groupId>
217
			<artifactId>aspectjrt</artifactId>
218
			<version>1.9.4</version>
219
		</dependency>
220
		<dependency>
221
			<groupId>org.aspectj</groupId>
222
			<artifactId>aspectjweaver</artifactId>
223
			<version>1.9.4</version>
224
		</dependency>
225

  
226
        <!-- https://mvnrepository.com/artifact/org.apache.maven/maven-model -->
227
        <dependency>
228
            <groupId>org.apache.maven</groupId>
229
            <artifactId>maven-model</artifactId>
230
            <version>3.3.9</version>
231
        </dependency>
232

  
233

  
234

  
235
    </dependencies>
236

  
237
	<build>
238
		<plugins>
239
			<plugin>
240
				<groupId>org.apache.maven.plugins</groupId>
241
				<artifactId>maven-compiler-plugin</artifactId>
242
				<configuration>
243
					<source>1.8</source>
244
					<target>1.8</target>
245
				</configuration>
246
			</plugin>
247
		</plugins>
248
	</build>
249
</project>
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/app/SearchServiceImpl.java
1
package eu.dnetlib.data.search.app;
2

  
3
import eu.dnetlib.api.data.IndexService;
4
import eu.dnetlib.api.data.IndexServiceException;
5
import eu.dnetlib.api.data.SearchService;
6
import eu.dnetlib.api.data.SearchServiceException;
7
import eu.dnetlib.api.enabling.ISLookUpService;
8
import eu.dnetlib.common.rmi.UnimplementedException;
9
import eu.dnetlib.data.search.app.plan.FieldRewriteRule;
10
import eu.dnetlib.data.search.app.plan.QueryRewriteRule;
11
import eu.dnetlib.data.search.solr.SolrResultSet;
12
import eu.dnetlib.data.search.transform.Transformer;
13
import eu.dnetlib.data.search.transform.config.SearchRegistry;
14
import eu.dnetlib.data.search.transform.formatter.Formatter;
15
import eu.dnetlib.domain.ActionType;
16
import eu.dnetlib.domain.EPR;
17
import eu.dnetlib.domain.ResourceType;
18
import eu.dnetlib.domain.data.FormattedSearchResult;
19
import eu.dnetlib.domain.data.SearchResult;
20
import eu.dnetlib.domain.data.SuggestiveResult;
21
import eu.dnetlib.domain.enabling.Notification;
22
import gr.uoa.di.driver.app.DriverServiceImpl;
23
import gr.uoa.di.driver.enabling.issn.NotificationListener;
24
import gr.uoa.di.driver.enabling.resultset.ResultSet;
25
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory;
26
import gr.uoa.di.driver.util.ServiceLocator;
27
import io.micrometer.core.instrument.Timer;
28
import io.micrometer.prometheus.PrometheusMeterRegistry;
29
import org.apache.log4j.Logger;
30
import org.apache.solr.client.solrj.SolrServerException;
31
import org.springframework.beans.factory.annotation.Autowired;
32
import org.w3c.dom.Document;
33
import org.w3c.dom.Node;
34
import org.xml.sax.InputSource;
35

  
36
import javax.xml.parsers.DocumentBuilder;
37
import javax.xml.parsers.DocumentBuilderFactory;
38
import javax.xml.xpath.XPath;
39
import javax.xml.xpath.XPathConstants;
40
import javax.xml.xpath.XPathExpression;
41
import javax.xml.xpath.XPathFactory;
42
import java.io.OutputStream;
43
import java.io.StringReader;
44
import java.util.*;
45

  
46
//import eu.dnetlib.utils.cql.CqlException;
47

  
48
public class SearchServiceImpl extends DriverServiceImpl
49
        implements SearchService {
50

  
51
    private static Logger logger = Logger.getLogger(SearchServiceImpl.class);
52
    //@Deprecated
53
    //private static Logger tlogger = Logger.getLogger("eu.dnetlib.data.search.app.Timer");
54

  
55
    private String mdFormat = "DMF";
56
    private String indexLayout = "index";
57

  
58
    private ServiceLocator<IndexService> indexLocator = null;
59
    private ServiceLocator<ISLookUpService> lookUpServiceServiceLocator = null;
60
    private ResultSetFactory rsFactory = null;
61

  
62
    private SearchRegistry transformerFactory = null;
63

  
64
    private List<QueryRewriteRule> queryRules = null;
65
    private List<String> fieldQueryRules = null;
66

  
67
    private Map<String, FieldRewriteRule> fieldRules = null;
68
    private boolean enableBrowseCache = false;
69

  
70
    private SearchServiceBlackboardHandler blackboardNotificationHandler = null;
71

  
72
    @Autowired
73
    private PrometheusMeterRegistry registry;
74

  
75

  
76
    //private CQLParser cqlParser = null;
77
    @Override
78
    public void init() {
79
        super.init();
80

  
81
        String serviceId = this.getServiceEPR().getParameter("serviceId");
82

  
83
        this.subscribe(
84
                ActionType.UPDATE,
85
                ResourceType.ANY.SEARCHSERVICERESOURCETYPE,
86
                serviceId,
87
                "RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_REQUEST",
88
                new NotificationListener() {
89

  
90
                    @Override
91
                    public void processNotification(Notification notification) {
92
                        blackboardNotificationHandler.notified(
93
                                notification.getSubscriptionId(),
94
                                notification.getTopic(),
95
                                notification.getIsId(),
96
                                notification.getMessage());
97
                    }
98
                });
99

  
100
        try {
101
            String searchProfile = lookUpServiceServiceLocator.getService().getResourceProfile(serviceId);
102

  
103
            if (searchProfile != null) {
104
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
105
                dbf.setNamespaceAware(true);
106
                DocumentBuilder db = dbf.newDocumentBuilder();
107
                Document doc = db.parse(new InputSource(new StringReader(searchProfile)));
108

  
109

  
110
                XPathFactory factory = XPathFactory.newInstance();
111
                XPath xpath = factory.newXPath();
112

  
113
                XPathExpression searchMdFormatExpression = xpath.compile("//SERVICE_PROPERTIES/PROPERTY[@key='mdformat']");
114
                Node node = (Node) searchMdFormatExpression.evaluate(doc,XPathConstants.NODE);
115

  
116
                if (node != null){
117
                    String profileMdFormat = node.getAttributes().getNamedItem("value").getTextContent();
118
                    if (profileMdFormat != null) {
119
                        //logger.debug("mdformat in properties " + mdFormat );
120
                        logger.info("Setting mdformat to '" + profileMdFormat + "'");
121
                        mdFormat = profileMdFormat;
122
                    }
123
                }
124
            }
125

  
126
        } catch (Exception e) {
127
            logger.error("Fail to load search service profile with id " + serviceId + " from IS.", e);
128
        }
129

  
130
    }
131

  
132
    @Override
133
    public SuggestiveResult suggestiveSearch(String query) throws SearchServiceException {
134
        throw new UnimplementedException();
135
    }
136

  
137
    @Override
138
    @Deprecated
139
    public SearchResult search(String text, String transformer, String locale, int page, int size) throws SearchServiceException {
140
        return searchNrefine(text, transformer, null, locale, page, size, null);
141
    }
142

  
143
    @Override
144
    @Deprecated
145
    public SearchResult refine(String text, String transformer, String locale, Collection<String> fields) throws SearchServiceException {
146
        return searchNrefine(text, null, transformer, locale, 1, -1, fields);
147
    }
148

  
149
    @Override
150
    @Deprecated
151
    public SearchResult searchNrefine(String text, String searchTransformer, String browseTransformer,
152
                                      String locale, int page, int size, Collection<String> fields) throws SearchServiceException {
153

  
154
        //logger.info("deprecated searchNrefine > from: " + page + " to:" + size);
155
        //TODO check locale
156
        //logger.debug("Search transformer " + searchTransformer);
157
        Transformer sTransformer = transformerFactory.getTransformer(searchTransformer, Locale.getDefault());
158
        Transformer oldRefineTransformer = transformerFactory.getTransformer("results_openaire_browse", Locale.getDefault());
159

  
160
        //logger.debug("Refine transformer " + browseTransformer);
161
        //Transformer rTranformer = transformerFactory.getTransformer(refineTransformer, Locale.getDefault());
162

  
163
        List<String> refineFields = null;
164
        if (fields!=null) {
165
            refineFields = new ArrayList<String>(fields);
166
        }
167

  
168
        return newSearch(text, locale, refineFields, null, new ArrayList<String>(), page, size, "", sTransformer, oldRefineTransformer, true);
169
    }
170

  
171
    @Override
172
    public FormattedSearchResult search(String queryText, String transformerName, String format, String locale, int page, int size)
173
            throws SearchServiceException {
174
        return searchNrefine(queryText, transformerName, null, format, locale, page, size, null);
175
    }
176

  
177
    @Override
178
    public FormattedSearchResult refine(String queryText, String refineTransformer, String format, String locale, Collection<String> fields) throws SearchServiceException {
179
        return searchNrefine(queryText, null, refineTransformer, format, locale, 0, -1, fields);
180
    }
181

  
182
    @Override
183
    public FormattedSearchResult searchNrefine(String queryText,
184
                                               String searchTransformer, String refineTransformer, String format,
185
                                               String locale, int page, int size, Collection<String> fields)  throws SearchServiceException {
186

  
187

  
188
        //logger.info("searchNrefine > from: " + page + " to:" + size);
189
        //TODO check locale
190
        FormattedSearchResult formattedSearchResult = null;
191

  
192
        //logger.debug("Search transformer " + searchTransformer);
193
        Transformer sTransformer = transformerFactory.getTransformer(searchTransformer, Locale.getDefault());
194
        Transformer oldRefineTransformer = transformerFactory.getTransformer("results_openaire_browse", Locale.getDefault());
195

  
196
        //logger.debug("Refine transformer " + refineTransformer);
197
        //Transformer rTranformer = transformerFactory.getTransformer(refineTransformer, Locale.getDefault());
198

  
199
        List<String> refineFields = null;
200
        if (fields!=null) {
201
            refineFields = new ArrayList<String>(fields);
202
        }
203
        SearchResult searchResult = newSearch(queryText, locale, refineFields, new ArrayList<>(), new ArrayList<String>(), page, size, format, sTransformer, oldRefineTransformer, true);
204

  
205
        Formatter formatter = transformerFactory.getFormatter(format); // formatter cannot be returned as null
206
        try {
207
            formattedSearchResult = new FormattedSearchResult(formatter.format(searchResult), searchResult.getTotal());
208

  
209
        } catch (Exception e) {
210
            logger.error("Error formating search results.", e);
211
        }
212

  
213
        return formattedSearchResult;
214
    }
215

  
216

  
217
    public SearchResult newSearch (String text, String locale, List<String> refinefields, List<String> specialFacets, List<String> fieldQueries,
218
                                   int from, int to, String format, Transformer transformer, Transformer oldRefineTransformer,
219
                                   boolean oldPaging) throws SearchServiceException {
220
        logger.info("newSearch > from: " + from + " to:" + to);
221
        long startTime = System.nanoTime();
222

  
223
        Timer.Sample timer = Timer.start(registry);
224

  
225
        IndexService index = getIndexLocator().getService();
226

  
227
        EPR epr = null;
228
        ResultSet<String> rs = null;
229

  
230
        List<String> browseResults = null;
231
        List<String> searchResults = null;
232

  
233
        String query = rewrite(text);
234
        enhanceFieldQueries(fieldQueries);
235
        logger.info("Performing query '" + query + "' and fields " + fieldQueries + " and refine " + refinefields);
236

  
237
        try {
238
            //TODO see parser and maybe delete!
239
            //query = new CQLParser().parse(query).toCQL();
240
            String eprQuery = createEprQuery(query, refinefields, specialFacets, fieldQueries);
241

  
242
            epr = index.getBrowsingStatistics(eprQuery, "all", mdFormat, indexLayout);
243

  
244
            if (epr == null){
245
                throw new SearchServiceException("Something really strange happened there! Index returned null result set id.");
246
            }
247

  
248
            //get the locale TODO do we need this?
249
            //String correctLocale = getCorrectLocale(locale);
250
            //StringTokenizer tokenizer = new StringTokenizer(correctLocale, "_");
251
            //Locale requestLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken());
252

  
253
            rs = rsFactory.createResultSet(epr);
254

  
255

  
256
            Map<String, List<String>> list = null;
257
            if (oldPaging) {
258
                list = ((SolrResultSet)rs).newGet(from-1, to, format, transformer, oldRefineTransformer);
259

  
260
            } else {
261
                list = ((SolrResultSet)rs).newGet(from, to, format, transformer, oldRefineTransformer);
262
            }
263

  
264
            searchResults = list.get("search");
265
            browseResults = list.get("refine");
266

  
267
        } catch (IndexServiceException ise) {
268
            logger.error("Error getting refine results.", ise);
269
            throw new SearchServiceException("Error getting refine results.", ise);
270

  
271
        } finally {
272
            timer.stop(registry.timer("search.server.response.duration"));
273
/*
274
            histogram.observe(System.currentTimeMillis()-startTime);
275
*/
276
        }
277

  
278
        long estimatedTime = System.nanoTime() - startTime;
279

  
280
        logger.debug("Search time " + estimatedTime/1000000 +  " milliseconds for query " + query +
281
                " and fields " + fieldQueries + " and refine " + refinefields + " from: "+ from + " and size " + to);
282

  
283
        //logger.info("Returned results for NEW search query '" + query + "' and fields " + fieldQueries + " and refine " + refinefields);;
284
        rs.close();
285

  
286
        return new SearchResult(query, Locale.getDefault().toString(), rs.size(), from, to, searchResults, browseResults, refinefields);
287
    }
288

  
289
    public void cursorSearch(String text, List<String> refinefields, List<String> specialFacets, List<String> fieldQueries,
290
                             String format, Transformer transformer, OutputStream os) throws SearchServiceException {
291

  
292
        long startTime = System.nanoTime();
293

  
294
        IndexService index = getIndexLocator().getService();
295

  
296

  
297
        EPR epr = null;
298
        ResultSet<String> rs = null;
299

  
300
        String query = rewrite(text);
301
        enhanceFieldQueries(fieldQueries);
302
        logger.info("Performing cursor query " + query + "' and fields " + fieldQueries + " and refine " + refinefields);
303
        logger.debug("Performing cursor query " + query + "' and fields " + fieldQueries + " and refine " + refinefields);
304

  
305

  
306
        try {
307
            String eprQuery = createEprQuery(query, refinefields, specialFacets, fieldQueries);
308
            epr = index.getBrowsingStatistics(eprQuery, "all", mdFormat, indexLayout);
309

  
310
            if (epr == null) {
311
                throw new SearchServiceException("Something really strange happened there! Index returned null result set id.");
312
            }
313

  
314
            rs = rsFactory.createResultSet(epr);
315

  
316
            ((SolrResultSet)rs).cursorGet(transformer,2000, os);
317

  
318
        } catch (IndexServiceException ise) {
319
            logger.error("Error getting cursor results.", ise);
320
            throw new SearchServiceException("Error getting cursor results.", ise);
321

  
322
        } catch (SolrServerException sse) {
323
            logger.error("Error getting cursor results.", sse);
324
            throw new SearchServiceException("Error getting cursor results.", sse);
325
        }
326

  
327
        long estimatedTime = System.nanoTime() - startTime;
328
        logger.debug("Cursor search time " + estimatedTime/1000000 +  " milliseconds for query " + query +
329
                " and fields " + fieldQueries + " and refine " + refinefields);
330

  
331
        rs.close();
332
    }
333

  
334

  
335
    private String rewrite(String query) {
336
        if (queryRules != null) {
337
            for (QueryRewriteRule queryRule: queryRules) {
338
                if (logger.isDebugEnabled()) {
339
                    logger.debug("Apply rule " + query);
340
                }
341
                query = queryRule.apply(query);
342
                if (logger.isDebugEnabled()) {
343
                    logger.debug("Rewritten query is " + query);
344
                }
345
            }
346
        }
347
        return query;
348
    }
349

  
350
    private void enhanceFieldQueries(List<String> fieldQueries) {
351
        if (fieldQueries != null && fieldQueryRules != null && !fieldQueryRules.isEmpty()) {
352
            fieldQueries.addAll(fieldQueryRules);
353
        }
354
    }
355

  
356
    public void setFieldRules(Collection<FieldRewriteRule> fieldRules) {
357
        this.fieldRules = new HashMap<String, FieldRewriteRule>();
358
        for (FieldRewriteRule rule : fieldRules) {
359
            String key = rule.getFieldName();
360
            if (this.fieldRules.containsKey(key)) {
361
                logger.warn("Multiple rules for field " + key);
362
                logger.warn("Keeping last rule " + rule.getName());
363
            }
364
            this.fieldRules.put(key, rule);
365
        }
366
    }
367

  
368
    public static String createEprQuery(String query, List<String> refineFields, List<String> specialFacets, List<String> fieldQueries) {
369
        StringBuffer queryBuffer = new StringBuffer();
370
        queryBuffer.append("query=");
371

  
372
        StringBuffer facetsBuffer = new StringBuffer();
373
        facetsBuffer.append("&groupby=");
374

  
375
        StringBuffer fqBuffer = new StringBuffer();
376
        fqBuffer.append("&fq=");
377

  
378
        StringBuffer sfBuffer = new StringBuffer();
379
        sfBuffer.append("&sf=");
380

  
381
        if (query != null) { //TODO consider exception?
382
            queryBuffer.append(query);
383
        }
384

  
385
        if(refineFields != null) {
386
            for (Iterator<String> iterator = refineFields.iterator(); iterator.hasNext(); ) {
387
                facetsBuffer.append(iterator.next());
388
                if (iterator.hasNext()) {
389
                    facetsBuffer.append(",");
390
                }
391
            }
392
        }
393

  
394
        if(specialFacets != null) {
395
            for (Iterator<String> iterator = specialFacets.iterator(); iterator.hasNext(); ) {
396
                sfBuffer.append(iterator.next());
397
                if (iterator.hasNext()) {
398
                    sfBuffer.append(",");
399
                }
400
            }
401
        }
402
       // logger.debug("special buffer " + sfBuffer.toString());
403

  
404
        if(fieldQueries != null) {
405
            for (Iterator<String> iterator = fieldQueries.iterator(); iterator.hasNext(); ) {
406
                fqBuffer.append(iterator.next());
407
                if (iterator.hasNext()) {
408
                    fqBuffer.append(",");
409
                }
410
            }
411
        }
412

  
413
        return queryBuffer.append(facetsBuffer.toString()).append(sfBuffer.toString()).append(fqBuffer.toString()).toString();
414
    }
415

  
416

  
417
    //TODO: I wish to remove this. This was only made (quick and dirty - only the enhanceFieldQueries(fieldQueries) is missing
418
    //from newSearch() after a last time request for the portal to show all the publications and the deletedbyinference ones.
419
    //I did not want to pass a parameter since I do not know if we are going to keep it. This is for a tech meeting showcase.
420
    //If we want to keep this I need to redesign.
421

  
422
    public SearchResult newSearchWithoutFieldQueries (String text, String locale, List<String> refinefields, List<String> specialFacets,
423
                                                      List<String> fieldQueries, int from, int to, String format, Transformer transformer,
424
                                                      Transformer oldRefineTransformer, boolean oldPaging) throws SearchServiceException {
425
        logger.info("non filtered search for...  > from: " + from + " to:" + to);
426
        long startTime = System.nanoTime();
427

  
428
        IndexService index = getIndexLocator().getService();
429

  
430
        EPR epr = null;
431
        ResultSet<String> rs = null;
432

  
433
        List<String> browseResults = null;
434
        List<String> searchResults = null;
435

  
436
        String query = rewrite(text);
437
        logger.info("Performing query '" + query + "' and fields " + fieldQueries + " and refine " + refinefields);
438

  
439
        try {
440
            //TODO see parser and maybe delete!
441
            //query = new CQLParser().parse(query).toCQL();
442
            String eprQuery = createEprQuery(query, refinefields, specialFacets, fieldQueries);
443

  
444
            epr = index.getBrowsingStatistics(eprQuery, "all", mdFormat, indexLayout);
445

  
446
            if (epr == null) {
447
                throw new SearchServiceException("Something really strange happened there! Index returned null result set id.");
448
            }
449

  
450
            //get the locale TODO do we need this?
451
            //String correctLocale = getCorrectLocale(locale);
452
            //StringTokenizer tokenizer = new StringTokenizer(correctLocale, "_");
453
            //Locale requestLocale = new Locale(tokenizer.nextToken(), tokenizer.nextToken());
454

  
455
            rs = rsFactory.createResultSet(epr);
456

  
457
            Map<String, List<String>> list = null;
458
            if (oldPaging) {
459
                list = ((SolrResultSet)rs).newGet(from-1, to, format, transformer, oldRefineTransformer);
460

  
461
            } else {
462
                list = ((SolrResultSet)rs).newGet(from, to, format, transformer, oldRefineTransformer);
463
            }
464

  
465

  
466
            searchResults = list.get("search");
467
            browseResults = list.get("refine");
468

  
469
        } catch (IndexServiceException ise) {
470
            logger.error("Error getting refine results.", ise);
471
            throw new SearchServiceException("Error getting refine results.", ise);
472

  
473
        }
474

  
475
        long estimatedTime = System.nanoTime() - startTime;
476
        logger.debug("Search time " + estimatedTime/1000000 +  " milliseconds for query " + query +
477
                " and fields " + fieldQueries + " and refine " + refinefields + " from: "+ from + " and size " + to);
478

  
479
        //logger.info("Returned results for NEW search query '" + query + "' and fields " + fieldQueries + " and refine " + refinefields);;
480
        rs.close();
481
        return new SearchResult(query, Locale.getDefault().toString(), rs.size(), from, to, searchResults, browseResults, refinefields);
482
    }
483

  
484

  
485
    public String getMdFormat() {
486
        return mdFormat;
487
    }
488

  
489
    public void setMdFormat(String mdFormat) {
490
        this.mdFormat = mdFormat;
491
    }
492

  
493
    public ServiceLocator<IndexService> getIndexLocator() {
494
        return indexLocator;
495
    }
496

  
497
    public void setIndexLocator(ServiceLocator<IndexService> indexLocator) {
498
        this.indexLocator = indexLocator;
499
    }
500

  
501
    public ResultSetFactory getRsFactory() {
502
        return rsFactory;
503
    }
504

  
505
    public void setRsFactory(ResultSetFactory rsFactory) {
506
        this.rsFactory = rsFactory;
507
    }
508

  
509
    public Collection<FieldRewriteRule> getFieldRules() {
510
        return fieldRules.values();
511
    }
512

  
513
    public List<QueryRewriteRule> getQueryRules() {
514
        return queryRules;
515
    }
516

  
517
    public void setQueryRules(List<QueryRewriteRule> queryRules) {
518
        this.queryRules = queryRules;
519
    }
520

  
521
    public boolean isEnableBrowseCache() {
522
        return enableBrowseCache;
523
    }
524

  
525
    public void setEnableBrowseCache(boolean enableBrowseCache) {
526
        this.enableBrowseCache = enableBrowseCache;
527
    }
528

  
529
    public SearchRegistry getTransformerFactory() {
530
        return transformerFactory;
531
    }
532

  
533
    public void setTransformerFactory(SearchRegistry transformerFactory) { this.transformerFactory = transformerFactory; }
534

  
535
    public String getIndexLayout() {
536
        return indexLayout;
537
    }
538

  
539
    public void setIndexLayout(String indexLayout) {
540
        this.indexLayout = indexLayout;
541
    }
542

  
543
    public SearchServiceBlackboardHandler getBlackboardNotificationHandler() {
544
        return blackboardNotificationHandler;
545
    }
546

  
547
    public void setBlackboardNotificationHandler(SearchServiceBlackboardHandler blackboardNotificationHandler) {
548
        this.blackboardNotificationHandler = blackboardNotificationHandler;
549
    }
550

  
551
    public void setLookUpServiceServiceLocator(ServiceLocator<ISLookUpService> lookUpServiceServiceLocator) {
552
        this.lookUpServiceServiceLocator = lookUpServiceServiceLocator;
553
    }
554

  
555
    public List<String> getFieldQueryRules() {
556
        return fieldQueryRules;
557
    }
558

  
559
    public void setFieldQueryRules(List<String> fieldQueryRules) {
560
        this.fieldQueryRules = fieldQueryRules;
561
    }
562
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/app/plan/PrefixRule.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.search.app.plan;
5

  
6
import org.apache.log4j.Logger;
7

  
8
/**
9
 * @author stoumpos
10
 */
11
public class PrefixRule extends QueryRewriteRule {
12

  
13
	public static final Logger logger = Logger.getLogger(QueryRewriteRule.class);
14
	
15
	private String prefix = null;
16
	
17
	public PrefixRule() {
18
		this(null, null);
19
	}
20
	
21
	public PrefixRule(String name, String prefix) {
22
		super(name);
23
		this.prefix = prefix;
24
	}
25
	
26
	public String getPrefix() {
27
		return prefix;
28
	}
29

  
30
	public void setPrefix(String prefix) {
31
		this.prefix = prefix;
32
	}
33

  
34
	/* (non-Javadoc)
35
	 * @see eu.dnetlib.data.search.app.plan.RewriteRule#apply(eu.dnetlib.data.search.app.plan.Query)
36
	 */
37
	public String apply(String query)  {
38
		String rewritten = query;
39
		
40
		StringBuffer sb = new StringBuffer(prefix);
41
		sb.append(" AND ").append(query);
42
		if (logger.isDebugEnabled()) {
43
			logger.debug("rewrite query '" + query
44
					+ "' as '" + sb.toString() + "'");
45
		}
46

  
47
       rewritten = sb.toString();
48
		return rewritten;
49
	}
50
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/web/utils/RequestResponseHandler.java
1
package eu.dnetlib.data.search.web.utils;
2

  
3
import java.util.Arrays;
4
import java.util.List;
5

  
6
/**
7
 * Created by kiatrop on 19/9/2016.
8
 */
9
public class RequestResponseHandler {
10

  
11
    public enum Entity {
12
        RESULT("result"),
13
        PUBLICATION("publication"),
14
        DATASET("dataset"),
15
        PROJECT("project"),
16
        DATASOURCE("datasource"),
17
        ORGANIZATION("organization"),
18
        //PERSON("person"),
19
        SOFTWARE("software"),
20
        OTHER("other"),
21
        NONE("");
22

  
23
        private final List<String> RESULT_FIELD_QUERIES = Arrays.asList("oaftype exact result");
24
        private final List<String> PUBLICATION_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact publication");
25
        private final List<String> DATASET_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact dataset");
26
        private final List<String> SOFTWARE_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact software");
27
        private final List<String> OTHER_FIELD_QUERIES = Arrays.asList("oaftype exact result", "resulttypeid exact other");
28
        private final List<String> PROJECT_FIELD_QUERIES = Arrays.asList("oaftype exact project");
29
        private final List<String> DATASOURCE_FIELD_QUERIES = Arrays.asList("oaftype exact datasource", "(eosctype exact \"Data Source\")");
30
        private final List<String> ORGANIZATION_FIELD_QUERIES = Arrays.asList("oaftype exact organization");
31
        /*private final List<String> ORGANIZATION_FIELD_QUERIES = Arrays.asList("oaftype exact organization",
32
                "reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or " +
33
                "reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or " +
34
                "reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=*");
35
        */
36
        //private final List<String> PERSON_FIELD_QUERIES = Arrays.asList("oaftype exact person");
37

  
38
        private final String RESULT_QUERY = "oaftype exact result";
39
        private final String PUBLICATION_QUERY = "resulttypeid exact publication";
40
        private final String DATASET_QUERY = "resulttypeid exact dataset";
41
        private final String SOFTWARE_QUERY = "resulttypeid exact software";
42
        private final String OTHER_QUERY = "resulttypeid exact other";
43

  
44
        private String value;
45
        Entity(String value) {
46
            this.value = value;
47
        }
48
        private String getValue() {
49
            return value;
50
        }
51

  
52
        @Override
53
        public String toString() {
54
            return this.getValue();
55
        }
56

  
57
        public String getQueryPrefix() {
58
            switch (this) {
59
                case RESULT:
60
                    return RESULT_PREFIX;
61

  
62
                case PUBLICATION:
63
                    return PUBLICATION_PREFIX;
64

  
65
                case DATASET:
66
                    return DATASET_PREFIX;
67

  
68
                case SOFTWARE:
69
                    return SOFTWARE_PREFIX;
70

  
71
                case OTHER:
72
                    return OTHER_PREFIX;
73

  
74
                case PROJECT:
75
                    return PROJECT_PREFIX;
76

  
77
                case DATASOURCE:
78
                    return DATASOURCE_PREFIX;
79

  
80
                case ORGANIZATION:
81
                    return ORGANIZATION_PREFIX;
82

  
83
                //case PERSON:
84
                //    return PERSON_PREFIX;
85

  
86
                case NONE:
87
                    return "";
88

  
89
                default:
90
                    throw new IllegalArgumentException();
91
            }
92

  
93
        }
94

  
95
        public String getPlural() {
96
            switch (this) {
97
                case RESULT:
98
                    return "results";
99

  
100
                case PUBLICATION:
101
                    return "publications";
102

  
103
                case DATASET:
104
                    return "datasets";
105

  
106
                case SOFTWARE:
107
                    return "software";
108

  
109
                case OTHER:
110
                    return "other";
111

  
112
                case PROJECT:
113
                    return "projects";
114

  
115
                case DATASOURCE:
116
                    return "datasources";
117

  
118
                case ORGANIZATION:
119
                    return "organizations";
120

  
121
                //case PERSON:
122
                //    return "people";
123

  
124
                case NONE:
125
                    return "resources";
126

  
127
                default:
128
                    throw new IllegalArgumentException();
129
            }
130
        }
131

  
132
        public List<String> getFieldQueries() {
133
            switch (this) {
134
                case RESULT:
135
                    return RESULT_FIELD_QUERIES;
136

  
137
                case PUBLICATION:
138
                    return PUBLICATION_FIELD_QUERIES;
139

  
140
                case DATASET:
141
                    return DATASET_FIELD_QUERIES;
142

  
143
                case SOFTWARE:
144
                    return SOFTWARE_FIELD_QUERIES;
145

  
146
                case OTHER:
147
                    return OTHER_FIELD_QUERIES;
148

  
149
                case PROJECT:
150
                    return PROJECT_FIELD_QUERIES;
151

  
152
                case DATASOURCE:
153
                    return DATASOURCE_FIELD_QUERIES;
154

  
155
                case ORGANIZATION:
156
                    return ORGANIZATION_FIELD_QUERIES;
157

  
158
                //case PERSON:
159
                //    return PERSON_FIELD_QUERIES;
160

  
161
                default:
162
                    throw new IllegalArgumentException();
163
            }
164
        }
165

  
166
        public String getSimpleQuery() {
167
            switch (this) {
168
                case RESULT:
169
                    return RESULT_QUERY;
170

  
171
                case PUBLICATION:
172
                    return PUBLICATION_QUERY;
173

  
174
                case DATASET:
175
                    return DATASET_QUERY;
176

  
177
                case SOFTWARE:
178
                    return SOFTWARE_QUERY;
179

  
180
                case OTHER:
181
                    return OTHER_QUERY;
182

  
183
                default:
184
                    throw new IllegalArgumentException();
185
            }
186
        }
187
    }
188

  
189
    public final static String RESULT_PREFIX = "(oaftype exact result)";
190
    public final static String PUBLICATION_PREFIX = "(oaftype exact result) and (resulttypeid exact publication)";
191
    public final static String DATASET_PREFIX = "(oaftype exact result) and (resulttypeid exact dataset)";
192
    public final static String SOFTWARE_PREFIX = "(oaftype exact result) and (resulttypeid exact software)";
193
    public final static String OTHER_PREFIX = "(oaftype exact result) and (resulttypeid exact other)";
194
    public final static String PROJECT_PREFIX = "(oaftype exact project)";
195
    public final static String DATASOURCE_PREFIX = "(oaftype exact datasource) and (eosctype exact \"Data Source\")";
196
    public final static String ORGANIZATION_PREFIX = "(oaftype exact organization and " +
197
            "(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or " +
198
            "reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or " +
199
            "reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy " +
200
            "or relproject=*)";
201
    //public final static String PERSON_PREFIX = "(oaftype exact person)";
202

  
203

  
204

  
205
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/app/plan/FieldRewriteRule.java
1
package eu.dnetlib.data.search.app.plan;
2

  
3
/**
4
 */
5
public abstract class FieldRewriteRule {
6

  
7
	protected String name = null;
8
	protected String fieldName = null;
9
	
10
	public FieldRewriteRule(String name, String fieldName) {
11
		this.name = name;
12
		this.fieldName = fieldName;
13
	}
14
	
15
	public String getFieldName() {
16
		return fieldName;
17
	}
18
	
19
	public void setFieldName(String fieldName) {
20
		this.fieldName = fieldName;
21
	}
22
	
23
	public String getName() {
24
		return name;
25
	}
26
	
27
	public void setName(String name) {
28
		this.name = name;
29
	}
30

  
31
	//public abstract CqlClause apply(CqlRelation relation) throws CqlException;
32
	
33
	@Override
34
	public String toString() {
35
		return name;
36
	}
37
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/solr/SolrIndexClient.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import eu.dnetlib.api.DriverServiceException;
4
import eu.dnetlib.api.data.IndexService;
5
import eu.dnetlib.api.data.IndexServiceException;
6
import eu.dnetlib.domain.EPR;
7
import eu.dnetlib.domain.ServiceIdentity;
8
import eu.dnetlib.domain.data.Hint;
9
import eu.dnetlib.domain.enabling.Notification;
10

  
11
import java.util.List;
12

  
13
/**
14
 * Created by antleb on 2/4/14.
15
 */
16
public class SolrIndexClient implements IndexService {
17
    private String solrServerUrl = null;
18

  
19
    private String interpretation = null;
20

  
21
    @Override
22
    public EPR indexLookup(String id, String query, String mdformat, String layout) throws IndexServiceException {
23
        EPR epr = new EPR();
24

  
25
        epr.setAddress(solrServerUrl);
26
        epr.setParameter("action", "lookup");
27
        epr.setParameter("id", id);
28
        epr.setParameter("query", query);
29
        epr.setParameter("mdformat", mdformat);
30
        epr.setParameter("layout", layout);
31
        epr.setParameter("interpretation", this.interpretation);
32

  
33
        return epr;
34
    }
35

  
36
    @Override
37
    public EPR getBrowsingStatistics(String query, String index, String mdFormatId, String layoutId) throws IndexServiceException {
38
        EPR epr = new EPR();
39

  
40
        epr.setAddress(solrServerUrl);
41
        epr.setParameter("action", "browse");
42
        epr.setParameter("id", index);
43
        epr.setParameter("query", query);
44
        epr.setParameter("mdformat", mdFormatId);
45
        epr.setParameter("layout", layoutId);
46
        epr.setParameter("interpretation", this.interpretation);
47

  
48
        return epr;
49
    }
50

  
51
    public void newMethod(){}
52

  
53
    public EPR getBrowsingStatistics2(String query, String index, String mdFormatId, String layoutId) throws IndexServiceException {
54
        EPR epr = new EPR();
55

  
56
        epr.setAddress(solrServerUrl);
57
        epr.setParameter("action", "browse");
58
        epr.setParameter("id", index);
59
        epr.setParameter("query", query);
60
        epr.setParameter("mdformat", mdFormatId);
61
        epr.setParameter("layout", layoutId);
62
        epr.setParameter("interpretation", this.interpretation);
63

  
64
        return epr;
65
    }
66

  
67
    @Override
68
    public Hint suggestiveSearch(String s, String s2, String s3, String s4, String s5) throws IndexServiceException {
69
        throw new UnsupportedOperationException();
70
    }
71

  
72
    @Override
73
    public List<String> getListOfIndices() throws IndexServiceException {
74
        throw new UnsupportedOperationException();
75
    }
76

  
77
    @Override
78
    public String getIndexStatistics(String s) throws IndexServiceException {
79
        throw new UnsupportedOperationException();
80
    }
81

  
82
    @Override
83
    public String getListOfIndicesCSV() throws IndexServiceException {
84
        throw new UnsupportedOperationException();
85
    }
86

  
87
    @Override
88
    public ServiceIdentity identify() {
89
        throw new UnsupportedOperationException();
90
    }
91

  
92
    @Override
93
    public void notify(Notification notification) throws DriverServiceException {
94
        throw new UnsupportedOperationException();
95
    }
96

  
97
    public String getSolrServerUrl() {
98
        return solrServerUrl;
99
    }
100

  
101
    public void setSolrServerUrl(String solrServerUrl) {
102
        this.solrServerUrl = solrServerUrl;
103
    }
104

  
105
    public String getInterpretation() {
106
        return interpretation;
107
    }
108

  
109
    public void setInterpretation(String interpretation) {
110
        this.interpretation = interpretation;
111
    }
112
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/solr/SolrResultSetFactory.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import eu.dnetlib.domain.EPR;
4
import eu.dnetlib.domain.SecureDriverResource;
5
import gr.uoa.di.driver.enabling.resultset.ResultSet;
6
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory;
7
import io.micrometer.prometheus.PrometheusMeterRegistry;
8
import org.apache.log4j.Logger;
9
import org.apache.solr.client.solrj.impl.CloudSolrClient;
10
import org.springframework.beans.factory.annotation.Autowired;
11

  
12
import java.util.Arrays;
13
import java.util.HashMap;
14
import java.util.Map;
15

  
16
/**
17
 * Created by antleb on 2/4/14.
18
 */
19
public class SolrResultSetFactory implements ResultSetFactory {
20

  
21
    private Logger logger = Logger.getLogger(getClass());
22
    private Map<String, CloudSolrClient> clients = new HashMap<String, CloudSolrClient>();
23

  
24
    @Autowired
25
    private PrometheusMeterRegistry prometheusMeterRegistry;
26

  
27

  
28
    @Override
29
    public ResultSet<String> createResultSet(EPR epr) {
30
        try {
31

  
32
            String[] zkservers= epr.getAddress().split(",");
33

  
34
            CloudSolrClient solrClient;
35

  
36
            synchronized (clients) {
37
                solrClient =  clients.get(epr.getAddress());
38
            }
39
            if (solrClient == null) {
40
                solrClient = new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkservers)).build();
41

  
42
                clients.put(epr.getAddress(), solrClient);
43
            }
44

  
45
            ResultSet<String> solrResultSets = new SolrResultSet(epr, solrClient, prometheusMeterRegistry);
46

  
47
            return solrResultSets;
48

  
49
        } catch (Exception e) {
50
            logger.warn("Error creating solr client", e);
51
        }
52

  
53
        logger.debug("NOT HERE!");
54
        return null;
55
    }
56

  
57
    @Override
58
    public <D> ResultSet<D> createResultSet(EPR epr, Class<D> resourceClass) {
59
        return (ResultSet<D>) createResultSet(epr);
60
    }
61

  
62
    @Override
63
    public <D> ResultSet<D> createResultSet(ResultSet<?> rs, Class<D> resourceClass) {
64
        throw new UnsupportedOperationException();
65
    }
66

  
67
    @Override
68
    public <D extends SecureDriverResource> ResultSet<D> createSecurityAwareRS(EPR epr, Class<D> resourceClass) {
69
        throw new UnsupportedOperationException();
70
    }
71
}
modules/uoa-search/tags/uoa-search-3.8.3/src/main/java/eu/dnetlib/data/search/transform/config/Configuration.java
1
package eu.dnetlib.data.search.transform.config;
2

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff