Revision: 7911
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7911&view=rev
Author:   dnaber
Date:     2012-08-23 17:16:42 +0000 (Thu, 23 Aug 2012)
Log Message:
-----------
adding an index overview: show the number of indexed documents per language

Modified Paths:
--------------
    trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java
    
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
    trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp

Modified: trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java
===================================================================
--- trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java        
2012-08-23 15:29:26 UTC (rev 7910)
+++ trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java        
2012-08-23 17:16:42 UTC (rev 7911)
@@ -68,6 +68,17 @@
     }
   }
 
+  public int getDocCount(File indexDir) throws IOException {
+    final FSDirectory directory = FSDirectory.open(indexDir);
+    final DirectoryReader reader = DirectoryReader.open(directory);
+    try {
+      final IndexSearcher indexSearcher = new IndexSearcher(reader);
+      return getDocCount(indexSearcher);
+    } finally {
+      reader.close();
+    }
+  }
+
   private int getDocCount(IndexSearcher indexSearcher) throws IOException {
     final Term searchTerm = new Term(MAX_DOC_COUNT_FIELD, 
MAX_DOC_COUNT_FIELD_VAL);
     final TopDocs search = indexSearcher.search(new TermQuery(searchTerm), 1);

Modified: 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
===================================================================
--- 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-08-23 15:29:26 UTC (rev 7910)
+++ 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-08-23 17:16:42 UTC (rev 7911)
@@ -23,6 +23,7 @@
 import org.languagetool.rules.patterns.PatternRuleLoader
 import org.languagetool.rules.IncorrectExample
 import org.languagetool.dev.index.SearchTimeoutException
+import org.languagetool.dev.index.Searcher
 
 /**
  * Editor that helps with creating the XML for simple rules.
@@ -76,6 +77,22 @@
         }
     }
 
+    def indexOverview = {
+        for (lang in Language.REAL_LANGUAGES) {
+          if (lang.isVariant()) {
+            continue
+          }
+          String indexDirTemplate = grailsApplication.config.fastSearchIndex
+          File indexDir = new File(indexDirTemplate.replace("LANG", 
lang.getShortName()))
+          if (indexDir.isDirectory()) {
+            Searcher searcher = new Searcher()
+            render "${lang}: 
${formatNumber(number:searcher.getDocCount(indexDir), type: 'number')} 
docs<br/>"
+          } else {
+            render "No index found: ${lang}<br/>"
+          }
+      }
+    }
+
     def checkXml = {
         Language language = getLanguage()
         PatternRuleLoader loader = new PatternRuleLoader()

Modified: trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp     
2012-08-23 15:29:26 UTC (rev 7910)
+++ trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp     
2012-08-23 17:16:42 UTC (rev 7911)
@@ -5,7 +5,8 @@
     <g:if test="${searcherResult.getMatchingSentences().size() == 0}">
 
         <p style="width:700px;">We've checked your pattern against 
${docsChecked} documents
-        from the ${params.language.encodeAsHTML()} <a 
href="http://www.wikipedia.org";>Wikipedia</a> and found no matches.
+        from the ${params.language.encodeAsHTML()} <a 
href="http://www.wikipedia.org";>Wikipedia</a>
+        (<g:link action="indexOverview">index size overview</g:link>) and 
found no matches.
         That's a good sign, it means your rule doesn't trigger any false 
alarms at least
         in the documents we checked.</p>
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
Languagetool-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to