Skip to content

Commit

Permalink
The upgrade finished
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Oct 8, 2016
1 parent d76da1b commit 32a3d44
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<classpathentry kind="lib" path="build/solrjars-extracted/solr/test-framework/lib/junit-4.10.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/test-framework/lib/junit4-ant-2.3.4.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/test-framework/lib/randomizedtesting-runner-2.3.4.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/test-framework/lucene-libs/lucene-test-framework-6.1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/test-framework/lucene-libs/lucene-test-framework-6.1.0-SNAPSHOT.jar" sourcepath="/apache-solr-61/lucene"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/antlr4-runtime-4.5.1-1.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/asm-5.0.4.jar"/>
<classpathentry kind="lib" path="build/solrjars-extracted/solr/asm-commons-5.0.4.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>apache-solr-48</name>
<comment></comment>
<projects>
<project>apache-solr-49</project>
<project>apache-solr-61</project>
</projects>
<buildSpec>
<buildCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,53 @@ protected QueryNode postProcessNode(QueryNode node)
if (node instanceof WildcardQueryNode) {
field = ((WildcardQueryNode) node).getFieldAsString();
value = ((WildcardQueryNode) node).getTextAsString();
if (value.indexOf('*') == 0 || value.indexOf('?') == 0)
return node; //let the analyzer decide the fate

int asteriskPosition = -1;
int qmarkPosition = -1;
int origLen = value.length();

if (value.indexOf('*') > -1) {
asteriskPosition = value.indexOf('*');
}
if (value.indexOf('?') > -1) {
qmarkPosition = value.indexOf('?');
}

if (asteriskPosition > 0 && asteriskPosition+1 < value.length()
|| qmarkPosition > 0 && qmarkPosition+1 < value.length()
|| asteriskPosition > -1 && qmarkPosition > -1)
return node;

for (String suffix: new String[]{"_wildcard", ""}) {
if (hasAnalyzer(field + suffix)) {
tokens = analyze(field + suffix, value);

if (tokens.length > 1)
if (tokens.length != 1)
return node; // break, let the analyzer decide the fate

if (!tokens[0].equals(value)) {
String newToken = tokens[0];
if (newToken.length() < origLen) {
if (qmarkPosition > -1) {
if (qmarkPosition == 0) {
newToken = '?' + tokens[0];
}
else {
newToken = tokens[0] + '?';
}
}
else {
if (asteriskPosition == 0) {
newToken = '*' + tokens[0];
}
else {
newToken = tokens[0] + '*';
}
}
}

if (!newToken.equals(value)) {
return new WildcardQueryNode(field,
tokens[0], ((WildcardQueryNode)node).getBegin(),
newToken, ((WildcardQueryNode)node).getBegin(),
((WildcardQueryNode)node).getEnd());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BooleanQuery.Builder;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.TermQuery;
Expand All @@ -40,9 +39,12 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestRuleLimitSysouts;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.TestUtil;


@TestRuleLimitSysouts.Limit(bytes = 600000)
@SuppressCodecs({"Lucene3x", "SimpleText"})
public class BenchmarkAuthorSearch extends LuceneTestCase{
private IndexSearcher searcher;
Expand Down Expand Up @@ -411,7 +413,8 @@ private List<TestCase> getIndexData(int[] randomIds) throws IOException {
String original = doc.get("original").toString();
String[] parts = original.split("\\,? ");
int howMany = TestUtil.nextInt(random(), 0, parts.length-1); // how many initials
data.add(new TestCase(original, parts, howMany));
if (howMany > 1)
data.add(new TestCase(original, parts, howMany));
}
return data;
}
Expand All @@ -434,8 +437,11 @@ private void verifySearch(int[] randomIds) throws IOException {
bq.add(q, Occur.MUST);
bq.add(new TermQuery(new Term("id", Integer.toString(randomIds[i]))), Occur.MUST);
if (q != null) {
System.out.println(q.toString());
int no = searcher.search(bq.build(), 1).totalHits;
//System.out.println(q.toString());
Query query = bq.build();
//System.out.println(query.toString());
//System.out.println("q: " + searcher.search(q, 10).totalHits);
int no = searcher.search(query, 1).totalHits;
if (no != 1) {
System.out.println("Results differ: " + oq + " <<>> " + q + " [" + ho + " : " + no + "]");
if (store == true) {
Expand All @@ -457,7 +463,7 @@ private void verifySearch(int[] randomIds) throws IOException {

}

private Query[] buildQueries(String[] parts) throws UnsupportedEncodingException {
private Query[] buildQueries(String[] parts) throws IOException {
if (parts.length - 1 < 3)
return null;
int howMany = TestUtil.nextInt(random(), 2, parts.length-1); // how many initials
Expand All @@ -483,7 +489,8 @@ private Query getSpanQuery(String[] parts, int howMany, boolean truncate) throws
clauses[0] = new SpanTermQuery(new Term("vectrfield", parts[0])); // surname
for (int i = 0; i < howMany; i++) {
if (truncate) {
clauses[i+1] = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("vectrfield", parts[i+1].substring(0, 1) + "*")));
SpanMultiTermQueryWrapper<WildcardQuery> q = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("vectrfield", parts[i+1].substring(0, 1) + "*")));
clauses[i+1] = q;
}
else {
clauses[i+1] = new SpanTermQuery(new Term("vectrfield", parts[i+1]));
Expand All @@ -493,7 +500,7 @@ private Query getSpanQuery(String[] parts, int howMany, boolean truncate) throws
return sq;
}

private Query getPayloadQuery(String[] parts, int howMany, boolean truncate) throws UnsupportedEncodingException {
private Query getPayloadQuery(String[] parts, int howMany, boolean truncate) throws IOException {
List<BytesRef> payloads = new ArrayList<BytesRef>(howMany+1);
BytesRef pay = new BytesRef((Integer.toString(0)).getBytes("UTF-8"));
payloads.add(pay);
Expand All @@ -502,8 +509,10 @@ private Query getPayloadQuery(String[] parts, int howMany, boolean truncate) thr
clauses[0] = new SpanTermQuery(new Term("vectrfield", parts[0])); // surname
for (int i = 0; i < howMany; i++) {
if (truncate) {
//clauses[i+1] = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("vectrfield", parts[i+1].substring(0, 1) + "*")));
clauses[i+1] = new SpanMultiTermQueryWrapper<PrefixQuery>(new PrefixQuery(new Term("vectrfield", parts[i+1].substring(0, 1))));
SpanMultiTermQueryWrapper<WildcardQuery> q = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("vectrfield", parts[i+1].substring(0, 1) + "*")));
clauses[i+1] = (SpanQuery) q.rewrite(searcher.getIndexReader());

//clauses[i+1] = new SpanMultiTermQueryWrapper<PrefixQuery>(new PrefixQuery(new Term("vectrfield", parts[i+1].substring(0, 1))));
}
else {
clauses[i+1] = new SpanTermQuery(new Term("vectrfield", parts[i+1]));
Expand Down

0 comments on commit 32a3d44

Please sign in to comment.