(query-parser) Fix regression where advice terms weren't parsed properly

This commit is contained in:
Viktor Lofgren 2024-10-14 13:46:37 +02:00
parent fe800b3af7
commit 89f7f3c17c
2 changed files with 10 additions and 22 deletions

View File

@ -83,8 +83,9 @@ public class QueryParser {
// special case to deal with possible RPAREN token at the end, // special case to deal with possible RPAREN token at the end,
// but we don't want to break if it's likely part of the search term // but we don't want to break if it's likely part of the search term
if (c == '(' && prevC != ')' && parenDepth > 0) if (c == ')' && prevC != '(' && parenDepth > 0) {
break; break;
}
} }
String displayStr = query.substring(i, end); String displayStr = query.substring(i, end);

View File

@ -160,78 +160,65 @@ public class QueryFactoryTest {
@Test @Test
public void testExpansion() { public void testExpansion() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("elden ring mechanical keyboard slackware linux duke nukem 3d").query; var subquery = parseAndGetSpecs("elden ring mechanical keyboard slackware linux duke nukem 3d").query;
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery.compiledQuery); System.out.println(subquery.compiledQuery);
} }
@Test @Test
public void testExpansion2() { public void testExpansion2() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("need for speed").query; var subquery = parseAndGetSpecs("need for speed").query;
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion3() { public void testExpansion3() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("buy rimonabant buy acomplia"); var subquery = parseAndGetSpecs("buy rimonabant buy acomplia");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion4() { public void testExpansion4() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("The Vietnam of computer science"); var subquery = parseAndGetSpecs("The Vietnam of computer science");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion5() { public void testExpansion5() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("The"); var subquery = parseAndGetSpecs("The");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion6() { public void testExpansion6() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("burning the nerves in the neck"); var subquery = parseAndGetSpecs("burning the nerves in the neck");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion7() { public void testExpansion7() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("amazing work being done"); var subquery = parseAndGetSpecs("amazing work being done");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testExpansion8() { public void testExpansion8() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("success often consists of"); var subquery = parseAndGetSpecs("success often consists of");
System.out.println("Time: " + (System.currentTimeMillis() - start));
System.out.println(subquery); System.out.println(subquery);
} }
@Test @Test
public void testParsing() { public void testParsing() {
long start = System.currentTimeMillis();
var subquery = parseAndGetSpecs("strlen()"); var subquery = parseAndGetSpecs("strlen()");
assertEquals("strlen", subquery.query.compiledQuery); assertEquals("strlen", subquery.query.compiledQuery);
System.out.println("Time: " + (System.currentTimeMillis() - start)); System.out.println(subquery);
}
@Test
public void testAdvice() {
var subquery = parseAndGetSpecs("mmap (strlen)");
assertEquals("mmap", subquery.query.compiledQuery);
assertEquals(List.of("strlen"), subquery.query.searchTermsAdvice);
System.out.println(subquery); System.out.println(subquery);
} }
} }