Compatible with social model 2.0.0

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2024-01-19 13:46:33 +01:00
parent 9defeb589d
commit ebe62bda4e
4 changed files with 40 additions and 52 deletions

48
pom.xml
View File

@ -5,13 +5,13 @@
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.0.0</version> <version>1.1.0</version>
<relativePath /> <relativePath />
</parent> </parent>
<groupId>org.gcube.socialnetworking</groupId> <groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-search-client</artifactId> <artifactId>social-data-search-client</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>2.0.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Social Data Search Client</name> <name>Social Data Search Client</name>
@ -31,8 +31,8 @@
<guavaVersion>18.0</guavaVersion> <guavaVersion>18.0</guavaVersion>
<serviceClass>social-networking</serviceClass> <serviceClass>social-networking</serviceClass>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
@ -49,16 +49,17 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-model</artifactId>
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.socialnetworking</groupId> <groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-indexing-common</artifactId> <artifactId>social-data-indexing-common</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency> <dependency>
<groupId>org.elasticsearch</groupId> <groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId> <artifactId>elasticsearch</artifactId>
@ -76,26 +77,13 @@
<version>1.0.3</version> <version>1.0.3</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.netflix.astyanax</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>astyanax-core</artifactId> <artifactId>jackson-mapper-asl</artifactId>
<scope>provided</scope> <version>1.5.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax-thrift</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax-cassandra</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.resources.discovery</groupId> <groupId>org.gcube.resources.discovery</groupId>
@ -133,8 +121,8 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>1.7</source> <source>1.8</source>
<target>1.7</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -3,7 +3,7 @@ package org.gcube.socialnetworking.social_data_search_client;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.gcube.portal.databook.shared.EnhancedFeed; import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields; import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields;
/** /**
@ -13,28 +13,28 @@ import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFi
public interface ElasticSearchClient { public interface ElasticSearchClient {
/** /**
* Given a query, the method find matching enhanced feeds into the elasticsearch index and return * Given a query, the method find matching enhanced post into the elasticsearch index and return
* at most <b>quantity</b> hits starting from <b>from</b>. A multimatch query is performed against all * at most <b>quantity</b> hits starting from <b>from</b>. A multimatch query is performed against all
* searchable fields. * searchable fields.
* @param query the query to match * @param query the query to match
* @param vreIDS specifies the vre(s) to which the returning feeds must belong * @param vreIDS specifies the vre(s) to which the returning posts must belong
* @param from start hits index * @param from start hits index
* @param quantity max number of hits to return starting from <b>from</b> * @param quantity max number of hits to return starting from <b>from</b>
* @return A list of matching enhanced feeds or nothing * @return A list of matching enhanced posts or nothing
*/ */
List<EnhancedFeed> search(String query, Set<String> vreIDS, int from, int quantity); List<EnhancedPost> search(String query, Set<String> vreIDS, int from, int quantity);
/** /**
* Given a query, the method find matching enhanced feeds into the elasticsearch index and return * Given a query, the method find matching enhanced posts into the elasticsearch index and return
* at most <b>quantity</b> hits starting from <b>from</b>. The query is performed against one of the searchable fields. * at most <b>quantity</b> hits starting from <b>from</b>. The query is performed against one of the searchable fields.
* @param query the query to match * @param query the query to match
* @param vreIDS specifies the vre(s) to which the returning feeds must belong * @param vreIDS specifies the vre(s) to which the returning posts must belong
* @param from start hits index * @param from start hits index
* @param quantity max number of hits to return starting from <b>from</b> * @param quantity max number of hits to return starting from <b>from</b>
* @param field the field against which the query is performed * @param field the field against which the query is performed
* @return A list of matching enhanced feeds or nothing * @return A list of matching enhanced posts or nothing
*/ */
List<EnhancedFeed> searchInField(String query, Set<String> vreIDS, int from, int quantity, SearchableFields field); List<EnhancedPost> searchInField(String query, Set<String> vreIDS, int from, int quantity, SearchableFields field);
/** /**
* Delete from the index a document with id docID. * Delete from the index a document with id docID.

View File

@ -20,7 +20,7 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.gcube.portal.databook.shared.EnhancedFeed; import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster; import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster;
import org.gcube.socialnetworking.social_data_indexing_common.utils.IndexFields; import org.gcube.socialnetworking.social_data_indexing_common.utils.IndexFields;
import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields; import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields;
@ -94,9 +94,9 @@ public class ElasticSearchClientImpl implements ElasticSearchClient{
} }
@Override @Override
public List<EnhancedFeed> search(String query, Set<String> vreIDS, int from, int quantity){ public List<EnhancedPost> search(String query, Set<String> vreIDS, int from, int quantity){
List<EnhancedFeed> toReturn = new ArrayList<>(); List<EnhancedPost> toReturn = new ArrayList<>();
if(from < 0 || quantity <= 0 || vreIDS.isEmpty()) if(from < 0 || quantity <= 0 || vreIDS.isEmpty())
return toReturn; return toReturn;
@ -146,11 +146,11 @@ public class ElasticSearchClientImpl implements ElasticSearchClient{
// rebuild objects // rebuild objects
for (SearchHit hit : results) { for (SearchHit hit : results) {
EnhancedFeed enhFeed; EnhancedPost enhPost;
try { try {
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class); enhPost = mapper.readValue(hit.getSourceAsString(), EnhancedPost.class);
toReturn.add(enhFeed); toReturn.add(enhPost);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.toString()); logger.error(e.toString());
@ -162,10 +162,10 @@ public class ElasticSearchClientImpl implements ElasticSearchClient{
} }
@Override @Override
public List<EnhancedFeed> searchInField(String query, Set<String> vreIDS, public List<EnhancedPost> searchInField(String query, Set<String> vreIDS,
int from, int quantity, SearchableFields field) { int from, int quantity, SearchableFields field) {
List<EnhancedFeed> toReturn = new ArrayList<>(); List<EnhancedPost> toReturn = new ArrayList<>();
if(from < 0 || quantity <= 0 || field == null || vreIDS.isEmpty()) if(from < 0 || quantity <= 0 || field == null || vreIDS.isEmpty())
return toReturn; return toReturn;
@ -207,11 +207,11 @@ public class ElasticSearchClientImpl implements ElasticSearchClient{
// rebuild objects // rebuild objects
for (SearchHit hit : results) { for (SearchHit hit : results) {
EnhancedFeed enhFeed; EnhancedPost enhPost;
try { try {
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class); enhPost = mapper.readValue(hit.getSourceAsString(), EnhancedPost.class);
toReturn.add(enhFeed); toReturn.add(enhPost);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.toString()); logger.error(e.toString());

View File

@ -5,7 +5,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.gcube.portal.databook.shared.EnhancedFeed; import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields; import org.gcube.socialnetworking.social_data_indexing_common.utils.SearchableFields;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,7 +34,7 @@ public class Tests
Set<String> set = new HashSet<String>(); Set<String> set = new HashSet<String>();
set.add("/gcube/devNext/NextNext"); set.add("/gcube/devNext/NextNext");
List<EnhancedFeed> results = el.searchInField("Costantino Perciante", set, 0, 10, SearchableFields.POST_AUTHOR); List<EnhancedPost> results = el.searchInField("Costantino Perciante", set, 0, 10, SearchableFields.POST_AUTHOR);
logger.debug("First result is " + results); logger.debug("First result is " + results);