Cleanup code.

This commit is contained in:
Andrew Lalis 2023-10-10 13:54:49 -04:00
parent db4774938a
commit f4195e2ccc
4 changed files with 11 additions and 10 deletions

View File

@ -11,10 +11,10 @@ import java.util.ArrayList;
public class DPackageSearch { public class DPackageSearch {
public static void main(String[] args) { public static void main(String[] args) {
Path indexPath = Path.of("package-index"); Path indexPath = Path.of("package-index");
// startIndexerThread(new IndexGenerator( startIndexerThread(new IndexGenerator(
// new DubRegistryPackageFetcher(), new DubRegistryPackageFetcher(),
// () -> new LucenePackageIndexer(indexPath) () -> new LucenePackageIndexer(indexPath)
// )); ));
new WebApiRunner(new LucenePackageSearcher(indexPath)).run(); new WebApiRunner(new LucenePackageSearcher(indexPath)).run();
} }
@ -23,7 +23,7 @@ public class DPackageSearch {
* index. * index.
* @param indexGenerator The index generator to use. * @param indexGenerator The index generator to use.
*/ */
public static void startIndexerThread(IndexGenerator indexGenerator) { private static void startIndexerThread(IndexGenerator indexGenerator) {
Thread.ofVirtual().start(() -> { Thread.ofVirtual().start(() -> {
while (true) { while (true) {
indexGenerator.run(); indexGenerator.run();

View File

@ -13,7 +13,10 @@ import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -53,7 +56,7 @@ public class DubRegistryPackageFetcher implements PackageFetcher {
try { try {
packages.add(parsePackage((ObjectNode) node, fetchedAt)); packages.add(parsePackage((ObjectNode) node, fetchedAt));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.err.println("Failed to parse package from JSON object: " + e.getMessage());
} }
} }
} }

View File

@ -7,7 +7,6 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*; import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexableFieldType;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FSDirectory;

View File

@ -104,12 +104,11 @@ public class LucenePackageSearcher implements PackageSearcher {
Query baseQuery = queryBuilder.build(); Query baseQuery = queryBuilder.build();
System.out.println("Query: " + baseQuery.toString()); System.out.println("Query: " + baseQuery.toString());
Query boostedQuery = new BooleanQuery.Builder() return new BooleanQuery.Builder()
.add(baseQuery, BooleanClause.Occur.MUST) .add(baseQuery, BooleanClause.Occur.MUST)
.add(FeatureField.newSaturationQuery("features", "recency", 0.25f, 1f/30f), BooleanClause.Occur.SHOULD) .add(FeatureField.newSaturationQuery("features", "recency", 0.25f, 1f/30f), BooleanClause.Occur.SHOULD)
.add(FeatureField.newSaturationQuery("features", "downloads", 0.5f, 500f), BooleanClause.Occur.SHOULD) .add(FeatureField.newSaturationQuery("features", "downloads", 0.5f, 500f), BooleanClause.Occur.SHOULD)
.build(); .build();
return boostedQuery;
} }
private PackageSearchResult prepareResult(Document doc, String explanation) { private PackageSearchResult prepareResult(Document doc, String explanation) {