-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#41) - don't re-quote quoted phrases
Issue #41, when original search term is quoted and synonym being expanded is item quoted don't re-quote when doing constructPhraseQueries. Removes issue where double quotes appear in result. Also when doing constructPhraseQueries, only quote phrases not single term synonyms.
- Loading branch information
1 parent
f2fe904
commit 242d330
Showing
2 changed files
with
94 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
# Basic unit tests for HON-Lucene-Synonyms | ||
# | ||
# Test that phrase queries synonyms do not get double quoted | ||
# when search contains quotes. And do not quote single term synonyms | ||
# | ||
|
||
from urllib2 import * | ||
import unittest, solr, urllib, time | ||
class TestBasic(unittest.TestCase): | ||
|
||
# | ||
# We have the synonyms: | ||
# | ||
# dog, pooch, hound, canis familiaris, man's best friend | ||
# | ||
|
||
url = 'http://localhost:8983/solr' | ||
test_data = [ \ | ||
{'id': '1', 'name': "I have a dog."}, \ | ||
{'id': '2', 'name': "I have a pooch."}, \ | ||
{'id': '3', 'name': "I have a hound."}, \ | ||
{'id': '4', 'name': "I have a canis."}, \ | ||
] | ||
solr_connection = None | ||
|
||
def setUp(self): | ||
self.solr_connection = solr.SolrConnection(self.url) | ||
self.solr_connection.delete_query('*:*') | ||
self.solr_connection.add_many(self.test_data) | ||
self.solr_connection.commit() | ||
|
||
def tearDown(self): | ||
self.solr_connection.delete_query('*:*') | ||
self.solr_connection.commit() | ||
|
||
def test_queries(self): | ||
|
||
self.tst_query('"dog"', 10) | ||
self.tst_query('"pooch"', 10) | ||
self.tst_query('"hound"', 10) | ||
self.tst_query('"canis familiaris"', 10) | ||
|
||
self.tst_query('dog', 4) | ||
self.tst_query('pooch', 4) | ||
self.tst_query('hound', 4) | ||
self.tst_query('canis familiaris', 4) | ||
|
||
|
||
def tst_query(self, query, quote_cnt): | ||
#Properly format spaces in the query | ||
query = urllib.quote_plus(query) | ||
connstr = self.url +'/select?q='+query+'&fl=*,score&qf=name&defType=synonym_edismax&synonyms=true&synonyms.constructPhrases=true&debugQuery=on' | ||
#Add wt=python so response is formatted as python readable | ||
conn = urlopen(connstr+'&wt=python') | ||
rsp = eval( conn.read() ) | ||
#print "number of matches=", rsp['response']['numFound'] | ||
print rsp['debug']['expandedSynonyms'] | ||
|
||
#Count the number of quotes in our expandedSynonyms Debug element | ||
cnt = 0 | ||
for str in rsp['debug']['expandedSynonyms']: | ||
#print str | ||
cnt += str.count('"') | ||
print 'Quotes found count = ', cnt | ||
|
||
self.assertEqual(cnt, quote_cnt) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|