From f0f82f7db0942acb2909fb0cf9a2fd23495753b8 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Fri, 18 Nov 2022 17:13:08 +0100 Subject: [PATCH] Reduce resource waste (#128) --- CONTRIBUTING.md | 12 ++++++------ README.md | 2 +- .../wmsa/edge/search/query/QueryFactory.java | 14 +++++--------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7909b9c6..2e699223 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,13 +26,13 @@ once per 6-8 weeks, coinciding with the crawling cycle. Where model-breaking changes and changes to the crawler can be introduced. -## Quick Set Up +## Running and set-up -There is a [Set Up Guide](https://git.marginalia.nu/marginalia/marginalia.nu/wiki/Setup/Search) -in the wiki. It has a small tendency to oxidize rather -rapidly since the project currently does not have a -lot of contributors to test it. If you find a problem -with the guide, email . +There is a complementary project, wmsa.local, which +contains scripts and instructions for running this +code base. + +[https://git.marginalia.nu/marginalia/wmsa.local](https://git.marginalia.nu/marginalia/wmsa.local) ## Documentation diff --git a/README.md b/README.md index 927fff6f..44c8a4cb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Documentation is a work in progress. See the [wiki](https://git.marginalia.nu/ma ## Contributing -The project is still being set up, but if you are interested in contributing, please contact me. +[CONTRIBUTING.md](CONTRIBUTING.md) ## Supporting diff --git a/marginalia_nu/src/main/java/nu/marginalia/wmsa/edge/search/query/QueryFactory.java b/marginalia_nu/src/main/java/nu/marginalia/wmsa/edge/search/query/QueryFactory.java index adf6c2b5..444c7845 100644 --- a/marginalia_nu/src/main/java/nu/marginalia/wmsa/edge/search/query/QueryFactory.java +++ b/marginalia_nu/src/main/java/nu/marginalia/wmsa/edge/search/query/QueryFactory.java @@ -23,15 +23,13 @@ import java.util.*; @Singleton public class QueryFactory { - private final LanguageModels lm; - private final TermFrequencyDict dict; private final EnglishDictionary englishDictionary; - private final NGramBloomFilter nGramBloomFilter; private final Logger logger = LoggerFactory.getLogger(getClass()); private final SearchResultValuator searchResultValuator; - private NearQueryProcessor nearQueryProcessor; + private final NearQueryProcessor nearQueryProcessor; private static final int RETAIN_QUERY_VARIANT_COUNT = 5; + private final ThreadLocal queryVariants; @Inject public QueryFactory(LanguageModels lm, @@ -40,17 +38,16 @@ public class QueryFactory { NGramBloomFilter nGramBloomFilter, SearchResultValuator searchResultValuator, NearQueryProcessor nearQueryProcessor) { - this.lm = lm; - this.dict = dict; this.englishDictionary = englishDictionary; - this.nGramBloomFilter = nGramBloomFilter; this.searchResultValuator = searchResultValuator; this.nearQueryProcessor = nearQueryProcessor; + + this.queryVariants = ThreadLocal.withInitial(() -> new QueryVariants(lm, dict, nGramBloomFilter, englishDictionary)); } public QueryParser getParser() { - return new QueryParser(englishDictionary, new QueryVariants(lm ,dict, nGramBloomFilter, englishDictionary)); + return new QueryParser(englishDictionary, queryVariants.get()); } public EdgeSearchQuery createQuery(EdgeUserSearchParameters params) { @@ -219,7 +216,6 @@ public class QueryFactory { EdgeSearchSpecification specs = specsBuilder.build(); return new EdgeSearchQuery(specs, searchTermsHuman, domain); - } private String normalizeDomainName(String str) {