<commit_before>"""
Get a list containing the file names returned by a lucene search for a set of terms

You need the LuceneSearch.java and BlosxomIndexer.java in order to make this all work.

You'll need to edit JAVA_HOME, lucene, bindir, classpath and index
"""

__author__ = "<NAME> - <EMAIL>"
__version__ = "$Id$"

import glob, os, urllib, cgi
from libs import api

# location of Java
JAVA_HOME = '/usr/bin/java'
# location of lucene jar files
lucene = '/home/twl/pyblog/lib/lucene-1.2/*.jar'
# location of lucene scripts and Java .class files
bindir = '/home/twl/pyblog/bin'
# java Classpath
classpath = ':'.join(glob.glob(lucene)+[bindir])
# location of lucene index file
index = '/home/twl/pyblog/index'

def search(py, term):
    urllib.quote(term)
    results = os.popen(JAVA_HOME+' -cp '+classpath+' LuceneSearch '+index+' '+term,'r').readlines()
    results = [ os.path.join(py['datadir'], x[2:-1]) for x in results ]
    f = file("/tmp/lucene","w")
    for x in results:
        f.write(x)
    f.close()
    return results

def searchHandler(py):
    # Lucene search handling
    form = cgi.FieldStorage()
    if not form.has_key("q"):
        return None
    py['luceneResults'] = search(py, form["q"].value)
    return py['luceneResults']

def initialize():
    api.fileListHandler.register(searchHandler,api.FIRST)
<commit_msg>Update to work with request class<commit_after>"""
Get a list containing the file names returned by a lucene search for a set of terms

You need the LuceneSearch.java and BlosxomIndexer.java in order to make this all work.

You'll need to edit JAVA_HOME, lucene, bindir, classpath and index
"""

__author__ = "<NAME> - <EMAIL>"
__version__ = "$Id$"

import glob, os, urllib, cgi
from libs import api

# location of Java
JAVA_HOME = '/usr/bin/java'
# location of lucene jar files
lucene = '/home/twl/pyblog/lib/lucene-1.2/*.jar'
# location of lucene scripts and Java .class files
bindir = '/home/twl/pyblog/bin'
# java Classpath
classpath = ':'.join(glob.glob(lucene)+[bindir])
# location of lucene index file
index = '/home/twl/pyblog/index'

def search(config, term):
    urllib.quote(term)
    results = os.popen(JAVA_HOME+' -cp '+classpath+' LuceneSearch '+index+' '+term,'r').readlines()
    results = [ os.path.join(config['root_datadir'], x[2:-1]) for x in results ]
    f = file("/tmp/lucene","w")
    for x in results:
        f.write(x)
    f.close()
    return results

def searchHandler(request):
    # Lucene search handling
    config = request.getConfiguration()
    data = request.getData()
    
    form = cgi.FieldStorage()
    if not form.has_key("q"):
        return None
    data['luceneResults'] = search(data, form["q"].value)
    return data['luceneResults']

def initialize():
    api.fileListHandler.register(searchHandler,api.FIRST)

{'fraction_non_alphanumeric': 0.13642857142857143, 'fraction_numerical': 0.002857142857142857, 'mean_word_length': 3.804459691252144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '905658', 'n_tokens_mistral': 971, 'n_tokens_neox': 949, 'n_words': 281}