forked from adsabs/montysolr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add institution field * changes for affilation fields * affiliation_text field definition * improved institution field fails new institution:baz test * Made affiliation field tokenized version and text version
- Loading branch information
1 parent
fd4c014
commit 8482fcc
Showing
4 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
contrib/adsabs/src/test/org/apache/solr/analysis/TestAdsabsTypeAffiliationTokens.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.solr.analysis; | ||
|
||
|
||
import monty.solr.util.MontySolrQueryTestCase; | ||
import monty.solr.util.MontySolrSetup; | ||
|
||
import org.apache.lucene.search.BooleanQuery; | ||
import org.apache.lucene.search.PhraseQuery; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.junit.BeforeClass; | ||
|
||
|
||
/** | ||
* Test for the affiliation_text type | ||
* | ||
*/ | ||
public class TestAdsabsTypeAffiliationTokens extends MontySolrQueryTestCase { | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
|
||
makeResourcesVisible(Thread.currentThread().getContextClassLoader(), new String[] { | ||
MontySolrSetup.getMontySolrHome() + "/contrib/examples/adsabs/server/solr/collection1/conf", | ||
MontySolrSetup.getSolrHome() + "/example/solr/collection1" | ||
}); | ||
|
||
System.setProperty("solr.allow.unsafe.resourceloading", "true"); | ||
|
||
|
||
schemaString = MontySolrSetup.getMontySolrHome() | ||
+ "/contrib/examples/adsabs/server/solr/collection1/conf/schema.xml"; | ||
|
||
configString = MontySolrSetup.getMontySolrHome() | ||
+ "/contrib/examples/adsabs/server/solr/collection1/conf/solrconfig.xml"; | ||
|
||
initCore(configString, schemaString, MontySolrSetup.getSolrHome() | ||
+ "/example/solr"); | ||
} | ||
|
||
|
||
public void test() throws Exception { | ||
|
||
assertU(addDocs("aff_abbrev", "foo bar", "aff_abbrev", "bar baz/hey")); | ||
assertU(addDocs("aff_abbrev", "Kavli Institute/Dept of Physics")); | ||
assertU(commit()); | ||
|
||
// make sure docs are there | ||
assertQ(req("q", "*:*"), "//*[@numFound>='2']"); | ||
|
||
// query parsing tests | ||
assertQueryEquals(req("q", "aff_abbrev:\"Foo Bar\""), | ||
"aff_abbrev:foo bar", | ||
TermQuery.class | ||
); | ||
// it is not visible here, but tokens are: foo bar, baz | ||
assertQueryEquals(req("q", "aff_abbrev:\"Foo Bar/Baz\""), | ||
"aff_abbrev:\"foo bar baz\"", | ||
PhraseQuery.class | ||
); | ||
|
||
// test matches | ||
assertQ(req("q", "aff_abbrev:\"foo bar\""), | ||
"//*[@numFound='1']", | ||
"//doc/str[@name='id'][.='0']" | ||
); | ||
assertQ(req("q", "aff_abbrev:\"bar baz\""), | ||
"//*[@numFound='1']", | ||
"//doc/str[@name='id'][.='0']" | ||
); | ||
assertQ(req("q", "aff_abbrev:HEY"), | ||
"//*[@numFound='1']", | ||
"//doc/str[@name='id'][.='0']" | ||
); | ||
assertQ(req("q", "aff_abbrev:\"bar BAZ/heY\""), | ||
"//*[@numFound='1']", | ||
"//doc/str[@name='id'][.='0']" | ||
); | ||
|
||
// only match full tokens | ||
assertQ(req("q", "aff_abbrev:foo"), "//*[@numFound='0']"); | ||
assertQ(req("q", "aff_abbrev:\"baz/hey\""), "//*[@numFound='0']"); | ||
|
||
|
||
// check the affiliation is there stored as one string | ||
assert h.query(req("q", "aff_abbrev:\"Kavli Institute/Dept of Physics\"")) | ||
.contains("<str>Kavli Institute/Dept of Physics</str>" | ||
); | ||
|
||
} | ||
|
||
|
||
|
||
// Uniquely for Junit 3 | ||
public static junit.framework.Test suite() { | ||
return new junit.framework.JUnit4TestAdapter(TestAdsabsTypeAffiliationTokens.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters