Better hints.

This commit is contained in:
vlofgren 2022-09-03 18:35:04 +02:00
parent 2e3d95bcb1
commit c912d3127d
4 changed files with 27 additions and 17 deletions

View File

@ -189,7 +189,18 @@ public class EdgeSearchOperator {
} }
resultList.sort(resultListComparator); resultList.sort(resultListComparator);
resultList.removeIf(new UrlDeduplicator(processedQuery.specs.limitByDomain)::shouldRemove);
UrlDeduplicator deduplicator = new UrlDeduplicator(processedQuery.specs.limitByDomain);
List<EdgeUrlDetails> retList = new ArrayList<>(processedQuery.specs.limitTotal);
for (var item : resultList) {
if (retList.size() >= processedQuery.specs.limitTotal)
break;
if (!deduplicator.shouldRemove(item)) {
retList.add(item);
}
}
return new DecoratedSearchResultSet(resultList); return new DecoratedSearchResultSet(resultList);
} }
@ -207,16 +218,13 @@ public class EdgeSearchOperator {
problems.add("Try rephrasing the query, changing the word order or using synonyms to get different results. <a href=\"https://memex.marginalia.nu/projects/edge/search-tips.gmi\">Tips</a>."); problems.add("Try rephrasing the query, changing the word order or using synonyms to get different results. <a href=\"https://memex.marginalia.nu/projects/edge/search-tips.gmi\">Tips</a>.");
} }
if (humanQuery.toLowerCase().matches(".*(definition|define).*")) { Set<String> representativeKeywords = processedQuery.getAllKeywords();
if (representativeKeywords.size()>1 && (representativeKeywords.contains("definition") || representativeKeywords.contains("define") || representativeKeywords.contains("meaning")))
{
problems.add("Tip: Try using a query that looks like <tt>define:word</tt> if you want a dictionary definition"); problems.add("Tip: Try using a query that looks like <tt>define:word</tt> if you want a dictionary definition");
} }
} }
if (humanQuery.contains("/")) {
problems.clear();
problems.add("<b>There is a known bug with search terms that contain a slash that causes them to be marked as unsupported; as a workaround, try using a dash instead. AC-DC will work, AC/DC does not.</b>");
}
return problems; return problems;
} }
@ -289,22 +297,15 @@ public class EdgeSearchOperator {
EdgeSearchResultSet resultSet = indexClient.query(ctx, processedQuery.specs); EdgeSearchResultSet resultSet = indexClient.query(ctx, processedQuery.specs);
Set<EdgeUrlDetails> ret = new HashSet<>(); Set<EdgeUrlDetails> ret = new HashSet<>();
logger.debug("{}", resultSet); for (IndexBlock block : IndexBlock.values()) {
for (IndexBlock block : indexBlockSearchOrder) {
var results = resultSet.resultsList.getOrDefault(block, Collections.emptyList()); var results = resultSet.resultsList.getOrDefault(block, Collections.emptyList());
for (var result : resultDecorator.getAllUrlDetails(results, block)) { ret.addAll(resultDecorator.getAllUrlDetails(results, block));
if (ret.size() > 100) break;
ret.add(result);
}
} }
return ret; return ret;
} }
static final IndexBlock[] indexBlockSearchOrder = Arrays.stream(IndexBlock.values()).sorted(Comparator.comparing(i -> i.sortOrder)).toArray(IndexBlock[]::new);
private Iterable<String> spellCheckTerms(Context ctx, EdgeSearchQuery disjointedQuery) { private Iterable<String> spellCheckTerms(Context ctx, EdgeSearchQuery disjointedQuery) {
return Observable.fromIterable(disjointedQuery.searchTermsHuman) return Observable.fromIterable(disjointedQuery.searchTermsHuman)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())

View File

@ -18,4 +18,11 @@ public class EdgeSearchQuery {
specs = justSpecs; specs = justSpecs;
} }
public Set<String> getAllKeywords() {
Set<String> keywords = new HashSet<>(100);
for (var sq : specs.subqueries) {
keywords.addAll(sq.searchTermsInclude);
}
return keywords;
}
} }

View File

@ -152,6 +152,7 @@ article > section > p { display: none; }
.problems ul { .problems ul {
flex-grow: 1; flex-grow: 1;
margin-left: -1em;
} }
.card .description { .card .description {

View File

@ -39,9 +39,10 @@
</section> </section>
{{/if}} {{/if}}
{{#unless evalResult}}{{#if problems}}<section class="card problems onlyscreen"><h2>Suggestions</h2><ul class="onlyscreen search-problems">{{#each problems}}<li>{{{.}}}</li>{{/each}}</ul></section> {{/if}}{{/unless}}
{{#each results}}{{>edge/search-result}}{{/each}} {{#each results}}{{>edge/search-result}}{{/each}}
{{#unless evalResult}}{{#if problems}}<section class="card problems onlyscreen"><h2>Suggestions</h2><ul class="onlyscreen search-problems">{{#each problems}}<li>{{{.}}}</li>{{/each}}</ul></section> {{/if}}{{/unless}}
</section> </section>
</article> </article>