diff --git a/src/main/java/com/andrewlalis/d_package_search/DPackageSearch.java b/src/main/java/com/andrewlalis/d_package_search/DPackageSearch.java index 273f418..a116d97 100644 --- a/src/main/java/com/andrewlalis/d_package_search/DPackageSearch.java +++ b/src/main/java/com/andrewlalis/d_package_search/DPackageSearch.java @@ -11,10 +11,10 @@ import java.util.ArrayList; public class DPackageSearch { public static void main(String[] args) { Path indexPath = Path.of("package-index"); -// startIndexerThread(new IndexGenerator( -// new DubRegistryPackageFetcher(), -// () -> new LucenePackageIndexer(indexPath) -// )); + startIndexerThread(new IndexGenerator( + new DubRegistryPackageFetcher(), + () -> new LucenePackageIndexer(indexPath) + )); new WebApiRunner(new LucenePackageSearcher(indexPath)).run(); } @@ -23,7 +23,7 @@ public class DPackageSearch { * index. * @param indexGenerator The index generator to use. */ - public static void startIndexerThread(IndexGenerator indexGenerator) { + private static void startIndexerThread(IndexGenerator indexGenerator) { Thread.ofVirtual().start(() -> { while (true) { indexGenerator.run(); diff --git a/src/main/java/com/andrewlalis/d_package_search/impl/DubRegistryPackageFetcher.java b/src/main/java/com/andrewlalis/d_package_search/impl/DubRegistryPackageFetcher.java index c545856..17e922e 100644 --- a/src/main/java/com/andrewlalis/d_package_search/impl/DubRegistryPackageFetcher.java +++ b/src/main/java/com/andrewlalis/d_package_search/impl/DubRegistryPackageFetcher.java @@ -13,7 +13,10 @@ import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import java.time.*; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -53,7 +56,7 @@ public class DubRegistryPackageFetcher implements PackageFetcher { try { packages.add(parsePackage((ObjectNode) node, fetchedAt)); } catch (Exception e) { - e.printStackTrace(); + System.err.println("Failed to parse package from JSON object: " + e.getMessage()); } } } diff --git a/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageIndexer.java b/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageIndexer.java index 7c63cf2..cef80fa 100644 --- a/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageIndexer.java +++ b/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageIndexer.java @@ -7,7 +7,6 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.*; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; diff --git a/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageSearcher.java b/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageSearcher.java index d15f068..bdf6673 100644 --- a/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageSearcher.java +++ b/src/main/java/com/andrewlalis/d_package_search/impl/LucenePackageSearcher.java @@ -104,12 +104,11 @@ public class LucenePackageSearcher implements PackageSearcher { Query baseQuery = queryBuilder.build(); System.out.println("Query: " + baseQuery.toString()); - Query boostedQuery = new BooleanQuery.Builder() + return new BooleanQuery.Builder() .add(baseQuery, BooleanClause.Occur.MUST) .add(FeatureField.newSaturationQuery("features", "recency", 0.25f, 1f/30f), BooleanClause.Occur.SHOULD) .add(FeatureField.newSaturationQuery("features", "downloads", 0.5f, 500f), BooleanClause.Occur.SHOULD) .build(); - return boostedQuery; } private PackageSearchResult prepareResult(Document doc, String explanation) {