Beispiel #1
0
def advancedFeatureSearch(query, sought_feature):
    formatted_query = parser.parse(query)
    scoreDocs = searcher.search(formatted_query, 50).scoreDocs

    #### create return structure ####
    results = []
    comments = []

    for scoreDoc in scoreDocs:
        doc = searcher.doc(scoreDoc.doc)
        featureMap = simplejson.loads(doc.get("feature-contents"))

        comments.append(featureMap["featureMap"][sought_feat]["sentence"])
        resentry = {
            "feature": sought_feature,
            "title": doc.get("title"),
            "review_date": doc.get("modified"),
            "comments": comments
        }
        results.append(resentry)

    return render_to_response("search_by_product_and_feature_results.html", {
        "submitted_query": query,
        "results": results
    })
Beispiel #2
0
def extractFeatureQueryWords(query):
    import string
    from lucene import Document, TermQuery, Term
    
    # create analyzer
    aux_analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)
    
    try:
        file = open('../features.txt', 'r')
        
        featurelist = []
        for line in file.readlines():
            words_in_line = line.split()
            featurelist += words_in_line
             
        querywordlist = query.split()
        
        featureQueryList = []
        productQueryList = []
        
        for word in querywordlist:
            if word in featurelist:
                featureQueryList.append(word)
            else:
                # create parser for word
                aux_parser = QueryParser(Version.LUCENE_CURRENT, "title", aux_analyzer)
                aux_query = aux_parser.parse(word)
                scoreDocs = searcher.search(aux_query, 50).scoreDocs
                if scoreDocs:
                    productQueryList.append(word)

        
        featureQuery = ""
        if featureQueryList:
            featureQuery = "("
            for i in range(len(featureQueryList)):
                if i == len(featureQueryList) - 1:
                    featureQuery += featureQueryList[i] + ")"
                else:
                    featureQuery += featureQueryList[i] + " AND "
                
            print featureQuery
        
        productQuery = ""
        if productQueryList:
            productQuery = "("
            for i in range(len(productQueryList)):
                if i == len(productQueryList) - 1:
                    productQuery += productQueryList[i] + ")"
                else:
                    productQuery += productQueryList[i] + " AND "
            
        return (featureQuery, productQuery, featureQueryList, productQueryList)
    except Exception, ex:
        print "Could not separate feature query words. Reason: ", ex
        return ("", "(" + query + ")", [], querywordlist)
Beispiel #3
0
def extractFeatureQueryWords(query):
    import string
    from lucene import Document, TermQuery, Term

    # create analyzer
    aux_analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)

    try:
        file = open('../features.txt', 'r')

        featurelist = []
        for line in file.readlines():
            words_in_line = line.split()
            featurelist += words_in_line

        querywordlist = query.split()

        featureQueryList = []
        productQueryList = []

        for word in querywordlist:
            if word in featurelist:
                featureQueryList.append(word)
            else:
                # create parser for word
                aux_parser = QueryParser(Version.LUCENE_CURRENT, "title",
                                         aux_analyzer)
                aux_query = aux_parser.parse(word)
                scoreDocs = searcher.search(aux_query, 50).scoreDocs
                if scoreDocs:
                    productQueryList.append(word)

        featureQuery = ""
        if featureQueryList:
            featureQuery = "("
            for i in range(len(featureQueryList)):
                if i == len(featureQueryList) - 1:
                    featureQuery += featureQueryList[i] + ")"
                else:
                    featureQuery += featureQueryList[i] + " AND "

            print featureQuery

        productQuery = ""
        if productQueryList:
            productQuery = "("
            for i in range(len(productQueryList)):
                if i == len(productQueryList) - 1:
                    productQuery += productQueryList[i] + ")"
                else:
                    productQuery += productQueryList[i] + " AND "

        return (featureQuery, productQuery, featureQueryList, productQueryList)
    except Exception, ex:
        print "Could not separate feature query words. Reason: ", ex
        return ("", "(" + query + ")", [], querywordlist)
Beispiel #4
0
def getResultScoreDocs(query):
    # create analyzer
    analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)
    
    # create parser for user submitted query
    parser = QueryParser(Version.LUCENE_CURRENT, "title", analyzer)
    parser.setDefaultOperator(QueryParser.Operator.AND)
    formatted_query = parser.parse(query)
    scoreDocs = searcher.search(formatted_query, 50).scoreDocs
    
    return scoreDocs
Beispiel #5
0
def getResultScoreDocs(query):
    # create analyzer
    analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)

    # create parser for user submitted query
    parser = QueryParser(Version.LUCENE_CURRENT, "title", analyzer)
    parser.setDefaultOperator(QueryParser.Operator.AND)
    formatted_query = parser.parse(query)
    scoreDocs = searcher.search(formatted_query, 50).scoreDocs

    return scoreDocs
Beispiel #6
0
def advancedFeatureSearch(query, sought_feature):
    formatted_query = parser.parse(query)
    scoreDocs = searcher.search(formatted_query, 50).scoreDocs
        
    #### create return structure ####
    results = []
    comments = []
        
    for scoreDoc in scoreDocs:
        doc = searcher.doc(scoreDoc.doc)
        featureMap = simplejson.loads(doc.get("feature-contents"))
        
        comments.append(featureMap["featureMap"][sought_feat]["sentence"])
        resentry = {"feature": sought_feature, "title": doc.get("title"), "review_date": doc.get("modified"),  
                    "comments": comments }
        results.append(resentry)
            
    return render_to_response("search_by_product_and_feature_results.html", {"submitted_query": query, "results" : results})