diff --git a/pom.xml b/pom.xml
index b56eb61..dda37c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,17 +13,6 @@
7.3.0
-
-
- apache.snapshots
- Apache Snapshot Repository
- https://repository.apache.org/content/repositories/snapshots
-
- false
-
-
-
-
src/main/java
src/test/java
@@ -55,7 +44,7 @@
org.apache.maven.plugins
maven-jar-plugin
- 3.0.2
+ 3.1.0
@@ -69,7 +58,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.1.1
+ 3.2.0
package
diff --git a/src/main/java/edu/anadolu/BestSearcher.java b/src/main/java/edu/anadolu/BestSearcher.java
index d1bf792..95936e0 100755
--- a/src/main/java/edu/anadolu/BestSearcher.java
+++ b/src/main/java/edu/anadolu/BestSearcher.java
@@ -6,17 +6,12 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.queryparser.classic.QueryParserBase;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.spans.SpanFirstQuery;
-import org.apache.lucene.search.spans.SpanNearQuery;
-import org.apache.lucene.search.spans.SpanQuery;
-import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.FSDirectory;
import java.io.BufferedReader;
@@ -28,6 +23,7 @@
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
import java.util.regex.Pattern;
/**
@@ -39,9 +35,8 @@ public class BestSearcher implements Closeable {
private final MPD challenge;
private final IndexReader reader;
- private final IndexSearcher searcher;
- private final AtomicReference out;
+ private final SimilarityConfig similarityConfig;
private final Integer maxPlaylist;
@@ -49,7 +44,7 @@ public class BestSearcher implements Closeable {
private final CustomSorter sorter;
- public BestSearcher(Path indexPath, Path challengePath, Path resultPath, SimilarityConfig similarityConfig, Integer maxPlaylist, Integer maxTrack, CustomSorterConfig sorterConfig) throws Exception {
+ public BestSearcher(Path indexPath, Path challengePath, SimilarityConfig similarityConfig, Integer maxPlaylist, Integer maxTrack, CustomSorterConfig sorterConfig) throws Exception {
if (!Files.exists(indexPath) || !Files.isDirectory(indexPath) || !Files.isReadable(indexPath)) {
throw new IllegalArgumentException(indexPath + " does not exist or is not a directory.");
}
@@ -57,8 +52,6 @@ public BestSearcher(Path indexPath, Path challengePath, Path resultPath, Similar
final Gson GSON = new Gson();
this.reader = DirectoryReader.open(FSDirectory.open(indexPath));
- this.searcher = new IndexSearcher(reader);
- this.out = new AtomicReference<>(new PrintWriter(Files.newBufferedWriter(resultPath, StandardCharsets.US_ASCII)));
this.maxPlaylist = maxPlaylist;
this.maxTrack = maxTrack;
this.sorter = sorterConfig.getCustomSorter();
@@ -67,32 +60,18 @@ public BestSearcher(Path indexPath, Path challengePath, Path resultPath, Similar
this.challenge = GSON.fromJson(reader, MPD.class);
}
- this.searcher.setSimilarity(similarityConfig.getSimilarity());
+ this.similarityConfig = similarityConfig;
}
- public void search() {
- Arrays.stream(this.challenge.playlists).parallel().forEach(playlist -> {
-
- try {
- tracksOnly(playlist.tracks, playlist.pid);
+ public void search(Path resultPath) throws IOException {
- /*
- HashSet results = new LinkedHashSet<>();
-
- if (playlist.tracks.length == 0) {
- titleOnly(playlist.name, playlist.pid, results);
- }
- else {
- if (playlist.isSequential()) {
- firstNTracks(playlist.tracks, playlist.pid, results);
- }
- else {
- tracksOnly(playlist.tracks, playlist.pid);
- }
- }
+ final AtomicReference out = new AtomicReference<>(new PrintWriter(Files.newBufferedWriter(resultPath, StandardCharsets.US_ASCII)));
- results.clear();
- */
+ Arrays.stream(this.challenge.playlists).parallel().forEach(playlist -> {
+ try {
+ tracksOnly(playlist.tracks, playlist.pid, out, Track::track_uri, "track_uris");
+ // tracksOnly(playlist.tracks, playlist.pid, out, Track::artist_uri, "artist_uris");
+ // tracksOnly(playlist.tracks, playlist.pid, out, Track::album_uri, "album_uris");
} catch (IOException | ParseException e) {
throw new RuntimeException(e);
}
@@ -107,52 +86,9 @@ public void close() throws IOException {
reader.close();
}
- /**
- * Predict tracks for a playlist given its title only.
- */
- private void titleOnly(String title, int playlistID, HashSet results) throws ParseException, IOException {
-
- QueryParser queryParser = new QueryParser("name", Indexer.icu());
- queryParser.setDefaultOperator(QueryParser.Operator.AND);
-
- Query query = queryParser.parse(QueryParserBase.escape(title));
-
- ScoreDoc[] hits = searcher.search(query, maxPlaylist).scoreDocs;
-
- /*
- * Try with OR operator, relaxed mode.
- */
- if (hits.length == 0) {
- queryParser.setDefaultOperator(QueryParser.Operator.OR);
-
- hits = searcher.search(query, maxPlaylist).scoreDocs;
- }
-
- for (ScoreDoc hit : hits) {
- int docID = hit.doc, pos = -1;
+ private void tracksOnly(Track[] tracks, int playlistID, AtomicReference out, Function