Skip to content

Commit

Permalink
begin work on fixing #32
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Oct 17, 2013
1 parent 853efe2 commit 7f48bda
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/example_synonym_file.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dog,hound,pooch,canis familiaris,man's best friend
back pack=>backpack
e-commerce,electronic commerce,e commerce
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static class Const {
*/
static final String IMPOSSIBLE_FIELD_NAME = "\uFFFC\uFFFC\uFFFC";

static final Pattern COMPLEX_QUERY_OPERATORS_PATTERN = Pattern.compile("(?:\\*|\\b(?:OR|AND|-|\\+)\\b)");
static final Pattern COMPLEX_QUERY_OPERATORS_PATTERN = Pattern.compile("(?:\\*|\\s-\\b|\\b(?:OR|AND|\\+)\\b)");
}

private Map<String, Analyzer> synonymAnalyzers;
Expand Down
50 changes: 50 additions & 0 deletions test/007-test-query-operators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Basic unit tests for HON-Lucene-Synonyms
#
# This one tests some of the problems found in issues #28 and #32
#

import unittest, solr, urllib

class TestBasic(unittest.TestCase):

url = 'http://localhost:8983/solr'
test_data = [ \
{'id': '1', 'name': "e-commerce"}, \
{'id': '2', 'name': "electronic commerce"}, \
]
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({}, 'commerce', 2)
self.tst_query({}, 'electronic commerce', 2)
self.tst_query({}, 'e-commerce', 2)

# means "shouldn't contain the word commerce"
self.tst_query({}, 'e -commerce', 0)

def tst_query(self, extra_params, query, expected_num_docs):

params = {'q': query, 'qf' : 'name', 'mm' : '100%', 'defType' : 'synonym_edismax', 'synonyms' : 'true'}
params.update(extra_params)

response = self.solr_connection.query(**params)
results = response.results
print '\ntesting ',self.url + '/select?' + urllib.urlencode(params),\
'\n',map(lambda x: x['name'],results),'\nActual: %s, Expected: %s' % (len(results), expected_num_docs)

self.assertEqual(len(results), expected_num_docs)

if __name__ == '__main__':
unittest.main()

0 comments on commit 7f48bda

Please sign in to comment.