lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r883975 [3/3] - in /lucene/pylucene/trunk: ./ java/org/apache/pylucene/search/ jcc/ samples/LuceneInAction/ samples/LuceneInAction/lia/advsearching/ samples/LuceneInAction/lia/analysis/ samples/LuceneInAction/lia/analysis/i18n/ samples/Luce...
Date Wed, 25 Nov 2009 04:08:18 GMT
Modified: lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/ScoreTest.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/ScoreTest.py?rev=883975&r1=883974&r2=883975&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/ScoreTest.py (original)
+++ lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/ScoreTest.py Wed Nov 25 04:08:13
2009
@@ -31,29 +31,33 @@
 
         class SimpleSimilarity(PythonSimilarity):
 
-            def lengthNorm(self, field, numTerms):
+            def lengthNorm(_self, field, numTerms):
                 return 1.0
 
-            def queryNorm(self, sumOfSquaredWeights):
+            def queryNorm(_self, sumOfSquaredWeights):
                 return 1.0
 
-            def tf(self, freq):
+            def tf(_self, freq):
                 return freq
 
-            def sloppyFreq(self, distance):
+            def sloppyFreq(_self, distance):
                 return 2.0
 
-            def idfTerms(self, terms, searcher):
+            def idfTerms(_self, terms, searcher):
                 return 1.0
 
-            def idfTerm(self, docFreq, numDocs):
+            def idf(_self, docFreq, numDocs):
                 return 1.0
 
-            def coord(self, overlap, maxOverlap):
+            def coord(_self, overlap, maxOverlap):
+                return 1.0
+
+            def scorePayload(_self, docId, fieldName, start, end, payload,
+                             offset, length):
                 return 1.0
 
         self.indexSingleFieldDocs([Field("contents", "x", Field.Store.YES,
-                                         Field.Index.TOKENIZED)])
+                                         Field.Index.ANALYZED)])
         searcher = IndexSearcher(self.directory)
         searcher.setSimilarity(SimpleSimilarity())
 
@@ -61,15 +65,16 @@
         explanation = searcher.explain(query, 0)
         print explanation
 
-        hits = searcher.search(query)
-        self.assertEqual(1, hits.length())
+        scoreDocs = searcher.search(query, 50).scoreDocs
+        self.assertEqual(1, len(scoreDocs))
 
-        self.assertEqual(hits.score(0), 1.0)
+        self.assertEqual(scoreDocs[0].score, 1.0)
         searcher.close()
 
     def indexSingleFieldDocs(self, fields):
 
-        writer = IndexWriter(self.directory, WhitespaceAnalyzer(), True)
+        writer = IndexWriter(self.directory, WhitespaceAnalyzer(), True,
+                             IndexWriter.MaxFieldLength.UNLIMITED)
 
         for field in fields:
             doc = Document()
@@ -82,33 +87,38 @@
     def testWildcard(self):
 
         self.indexSingleFieldDocs([Field("contents", "wild", Field.Store.YES,
-                                         Field.Index.TOKENIZED),
+                                         Field.Index.ANALYZED),
                                    Field("contents", "child", Field.Store.YES,
-                                         Field.Index.TOKENIZED),
+                                         Field.Index.ANALYZED),
                                    Field("contents", "mild", Field.Store.YES,
-                                         Field.Index.TOKENIZED),
+                                         Field.Index.ANALYZED),
                                    Field("contents", "mildew", Field.Store.YES,
-                                         Field.Index.TOKENIZED)])
+                                         Field.Index.ANALYZED)])
 
         searcher = IndexSearcher(self.directory)
         query = WildcardQuery(Term("contents", "?ild*"))
-        hits = searcher.search(query)
-        self.assertEqual(3, hits.length(), "child no match")
+        scoreDocs = searcher.search(query, 50).scoreDocs
+        self.assertEqual(3, len(scoreDocs), "child no match")
 
-        self.assertEqual(hits.score(0), hits.score(1), "score the same")
-        self.assertEqual(hits.score(1), hits.score(2), "score the same")
+        self.assertEqual(scoreDocs[0].score, scoreDocs[1].score,
+                         "score the same")
+        self.assertEqual(scoreDocs[1].score, scoreDocs[1].score,
+                         "score the same")
 
     def testFuzzy(self):
 
         self.indexSingleFieldDocs([Field("contents", "fuzzy", Field.Store.YES,
-                                         Field.Index.TOKENIZED),
+                                         Field.Index.ANALYZED),
                                    Field("contents", "wuzzy", Field.Store.YES,
-                                         Field.Index.TOKENIZED)])
+                                         Field.Index.ANALYZED)])
 
         searcher = IndexSearcher(self.directory)
         query = FuzzyQuery(Term("contents", "wuzza"))
-        hits = searcher.search(query)
-        self.assertEqual(2, hits.length(), "both close enough")
+        scoreDocs = searcher.search(query, 50).scoreDocs
+        self.assertEqual(2, len(scoreDocs), "both close enough")
 
-        self.assert_(hits.score(0) !=  hits.score(1), "wuzzy closer than fuzzy")
-        self.assertEqual("wuzzy", hits.doc(0).get("contents"), "wuzza bear")
+        self.assert_(scoreDocs[0].score != scoreDocs[1].score,
+                     "wuzzy closer than fuzzy")
+        self.assertEqual("wuzzy",
+                         searcher.doc(scoreDocs[0].doc).get("contents"),
+                         "wuzza bear")

Copied: lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/TermRangeQueryTest.py (from
r820102, lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/RangeQueryTest.py)
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/TermRangeQueryTest.py?p2=lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/TermRangeQueryTest.py&p1=lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/RangeQueryTest.py&r1=820102&r2=883975&rev=883975&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/RangeQueryTest.py (original)
+++ lucene/pylucene/trunk/samples/LuceneInAction/lia/searching/TermRangeQueryTest.py Wed Nov
25 04:08:13 2009
@@ -14,32 +14,16 @@
 
 from lia.common.LiaTestCase import LiaTestCase
 
-from lucene import Term, IndexSearcher, RangeQuery
+from lucene import Term, IndexSearcher, TermRangeQuery
 
 
-class RangeQueryTest(LiaTestCase):
+class TermRangeQueryTest(LiaTestCase):
 
-    def setUp(self):
+    def testTermRangeQuery(self):
 
-        super(RangeQueryTest, self).setUp()
+        searcher = IndexSearcher(self.directory, True)
+        query = TermRangeQuery("title2", "d", "j", True, True)
 
-        self.begin = Term("pubmonth", "198805")
-
-        # pub date of TTC was October 1988
-        self.end = Term("pubmonth", "198810")
-
-    def testInclusive(self):
-
-        query = RangeQuery(self.begin, self.end, True)
-        searcher = IndexSearcher(self.directory)
-
-        hits = searcher.search(query)
-        self.assertEqual(1, hits.length(), "tao")
-
-    def testExclusive(self):
-
-        query = RangeQuery(self.begin, self.end, False)
-        searcher = IndexSearcher(self.directory)
-
-        hits = searcher.search(query)
-        self.assertEqual(0, hits.length(), "there is no tao")
+        topDocs = searcher.search(query, 100)
+        self.assertEqual(3, topDocs.totalHits)
+        searcher.close()

Modified: lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/HighlightTest.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/HighlightTest.py?rev=883975&r1=883974&r2=883975&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/HighlightTest.py (original)
+++ lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/HighlightTest.py Wed Nov 25 04:08:13
2009
@@ -16,7 +16,7 @@
 
 from lucene import \
      SimpleAnalyzer, Term, IndexSearcher, TermQuery, \
-     Highlighter, QueryScorer, StringReader, Hit
+     Highlighter, QueryScorer, StringReader, Version
 
 
 class HighlightTest(LiaTestCase):
@@ -29,24 +29,24 @@
         scorer = QueryScorer(query)
         highlighter = Highlighter(scorer)
 
-        tokenStream = SimpleAnalyzer().tokenStream("field", StringReader(text))
+        tokenStream = SimpleAnalyzer(Version.LUCENE_CURRENT).tokenStream("field", StringReader(text))
 
         self.assertEqual("The quick brown <B>fox</B> jumps over the lazy dog",
                          highlighter.getBestFragment(tokenStream, text))
 
     def testHits(self):
 
-        searcher = IndexSearcher(self.directory)
+        searcher = IndexSearcher(self.directory, True)
         query = TermQuery(Term("title", "action"))
-        hits = searcher.search(query)
+        scoreDocs = searcher.search(query, 50).scoreDocs
 
         scorer = QueryScorer(query)
         highlighter = Highlighter(scorer)
 
-        for hit in hits:
-            doc = Hit.cast_(hit).getDocument()
+        for scoreDoc in scoreDocs:
+            doc = searcher.doc(scoreDoc.doc)
             title = doc["title"]
-            stream = SimpleAnalyzer().tokenStream("title", StringReader(title))
+            stream = SimpleAnalyzer(Version.LUCENE_CURRENT).tokenStream("title", StringReader(title))
             fragment = highlighter.getBestFragment(stream, title)
     
             print fragment

Modified: lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/SnowballTest.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/SnowballTest.py?rev=883975&r1=883974&r2=883975&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/SnowballTest.py (original)
+++ lucene/pylucene/trunk/samples/LuceneInAction/lia/tools/SnowballTest.py Wed Nov 25 04:08:13
2009
@@ -13,30 +13,19 @@
 # ====================================================================
 
 from unittest import TestCase
-from lucene import SnowballAnalyzer, Token, StringReader
+from lucene import SnowballAnalyzer, StringReader, Version
+from lia.analysis.AnalyzerUtils import AnalyzerUtils
 
 
 class SnowballTest(TestCase):
 
     def testEnglish(self):
 
-        analyzer = SnowballAnalyzer("English")
-        self.assertAnalyzesTo(analyzer, "stemming algorithms",
-                              ["stem", "algorithm"])
+        analyzer = SnowballAnalyzer(Version.LUCENE_CURRENT, "English")
+        AnalyzerUtils.assertAnalyzesTo(analyzer, "stemming algorithms",
+                                       ["stem", "algorithm"])
 
     def testSpanish(self):
 
-        analyzer = SnowballAnalyzer("Spanish")
-        self.assertAnalyzesTo(analyzer, "algoritmos", ["algoritm"])
-
-    def assertAnalyzesTo(self, analyzer, input, output):
-
-        stream = analyzer.tokenStream("field", StringReader(input))
-
-        for text in output:
-            token = stream.next()
-            self.assert_(token)
-            self.assertEqual(text, token.termText())
-
-        self.assert_(not list(stream))
-        stream.close()
+        analyzer = SnowballAnalyzer(Version.LUCENE_CURRENT, "Spanish")
+        AnalyzerUtils.assertAnalyzesTo(analyzer, "algoritmos", ["algoritm"])

Modified: lucene/pylucene/trunk/test/test_Similarity.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/test/test_Similarity.py?rev=883975&r1=883974&r2=883975&view=diff
==============================================================================
--- lucene/pylucene/trunk/test/test_Similarity.py (original)
+++ lucene/pylucene/trunk/test/test_Similarity.py Wed Nov 25 04:08:13 2009
@@ -30,10 +30,10 @@
     def sloppyFreq(self, distance):
         return 2.0
 
-    def idf(self, docFreq, numDocs):
+    def idfTerms(self, terms, searcher):
         return 1.0
 
-    def idfTerms(self, terms, searcher):
+    def idf(self, docFreq, numDocs):
         return 1.0
 
     def coord(self, overlap, maxOverlap):



Mime
View raw message