|
a/Allura/allura/lib/search.py |
|
b/Allura/allura/lib/search.py |
|
... |
|
... |
8 |
from pylons import c,g
|
8 |
from pylons import c,g
|
9 |
import pysolr
|
9 |
import pysolr
|
10 |
|
10 |
|
11 |
from . import helpers as h
|
11 |
from . import helpers as h
|
12 |
from .markdown_extensions import ForgeExtension
|
12 |
from .markdown_extensions import ForgeExtension
|
13 |
|
|
|
14 |
# from allura.tasks.search import AddArtifacts, DelArtifacts
|
|
|
15 |
|
|
|
16 |
# re_SHORTLINK = re.compile(ForgeExtension.core_artifact_link)
|
|
|
17 |
re_SOLR_ERROR = re.compile(r'<pre>(org.apache.lucene[^:]+: )?(?P<text>[^<]+)</pre>')
|
|
|
18 |
|
13 |
|
19 |
log = getLogger(__name__)
|
14 |
log = getLogger(__name__)
|
20 |
|
15 |
|
21 |
def try_solr(func):
|
16 |
def try_solr(func):
|
22 |
def inner(*args, **kwargs):
|
17 |
def inner(*args, **kwargs):
|
|
... |
|
... |
61 |
if not history:
|
56 |
if not history:
|
62 |
fq.append('is_history_b:False')
|
57 |
fq.append('is_history_b:False')
|
63 |
try:
|
58 |
try:
|
64 |
return g.solr.search(q, fq=fq, rows=rows, **kw)
|
59 |
return g.solr.search(q, fq=fq, rows=rows, **kw)
|
65 |
except pysolr.SolrError, e:
|
60 |
except pysolr.SolrError, e:
|
66 |
log.info("Solr error: %s", e)
|
61 |
raise ValueError('Error running search query: %s' % e.message)
|
67 |
m = re_SOLR_ERROR.search(e.message)
|
|
|
68 |
if m:
|
|
|
69 |
text = m.group('text')
|
|
|
70 |
else:
|
|
|
71 |
text = "syntax error?"
|
|
|
72 |
raise ValueError(text)
|
|
|
73 |
|
62 |
|
74 |
def find_shortlinks(text):
|
63 |
def find_shortlinks(text):
|
75 |
md = markdown.Markdown(
|
64 |
md = markdown.Markdown(
|
76 |
extensions=['codehilite', ForgeExtension(), 'tables'],
|
65 |
extensions=['codehilite', ForgeExtension(), 'tables'],
|
77 |
output_format='html4')
|
66 |
output_format='html4')
|
78 |
md.convert(text)
|
67 |
md.convert(text)
|
79 |
link_index = md.postprocessors['forge'].parent.alinks
|
68 |
link_index = md.postprocessors['forge'].parent.alinks
|
80 |
return [ link for link in link_index.itervalues() if link is not None]
|
69 |
return [ link for link in link_index.itervalues() if link is not None]
|
81 |
|
|
|