Examples of FieldMatch


Examples of org.eurekastreams.commons.search.modelview.FieldMatch

        fieldsToAnalyze.add("typeOfAuto");
        fieldsToAnalyze.add("name");

        sut.setFieldsToAnalyze(fieldsToAnalyze);
        sut.setSearchAnalyzer(new TextStemmerAnalyzer());
        FieldMatch matches = sut.determineFieldMatches(getExplanation(), "ford cars");

        assertTrue(matches.isMatch("typeOfAuto"));
        assertTrue(matches.isMatch("name"));
        assertFalse(matches.isMatch("foobar"));

        // note that the keyword that lucene found was "car", but we passed that in as "cars", so that's what it's
        // telling us we matched.
        Object[] matchedKeywords = matches.getMatchingKeywords("typeOfAuto").toArray();
        assertEquals(1, matchedKeywords.length);
        assertEquals("cars", matchedKeywords[0]);

        // note that these keywords come back in alphabetical order
        matchedKeywords = matches.getMatchingKeywords("name").toArray();
        assertEquals(2, matchedKeywords.length);
        assertEquals("cars", matchedKeywords[0]);
        assertEquals("ford", matchedKeywords[1]);
    }
View Full Code Here

Examples of org.eurekastreams.commons.search.modelview.FieldMatch

    {
        FieldMatchDeterminer sut = new FieldMatchDeterminer();
        sut.setFieldsToAnalyze(new ArrayList<String>());
        sut.setSearchAnalyzer(new TextStemmerAnalyzer());

        FieldMatch matches = sut.determineFieldMatches(getExplanation(), "ford cars");

        assertFalse(matches.isMatch("typeOfAuto"));
        Object[] matchedKeywords = matches.getMatchingKeywords("typeOfAuto").toArray();
        assertEquals(0, matchedKeywords.length);

        matchedKeywords = matches.getMatchingKeywords("name").toArray();
        assertEquals(0, matchedKeywords.length);
    }
View Full Code Here

Examples of org.eurekastreams.commons.search.modelview.FieldMatch

        List<String> fieldsToAnalyze = new ArrayList<String>();
        fieldsToAnalyze.add("typeOfAuto");

        sut.setFieldsToAnalyze(fieldsToAnalyze);
        sut.setSearchAnalyzer(new TextStemmerAnalyzer());
        FieldMatch matches = sut.determineFieldMatches(getExplanation(), "ford cars");

        assertTrue(matches.isMatch("typeOfAuto"));
        assertFalse(matches.isMatch("name"));
        assertFalse(matches.isMatch("foobar"));

        // note that the keyword that lucene found was "car", but we passed that in as "cars", so that's what it's
        // telling us we matched.
        Object[] matchedKeywords = matches.getMatchingKeywords("typeOfAuto").toArray();
        assertEquals(1, matchedKeywords.length);
        assertEquals("cars", matchedKeywords[0]);

        // note that these keywords come back in alphabetical order
        matchedKeywords = matches.getMatchingKeywords("name").toArray();
        assertEquals(0, matchedKeywords.length);
    }
View Full Code Here

Examples of org.eurekastreams.commons.search.modelview.FieldMatch

     */
    public FieldMatch determineFieldMatches(final String inExplanationText, final String searchText)
    {
        String explanationText = inExplanationText;

        FieldMatch matchedKeywords = new FieldMatch();
        if (fieldsToAnalyze.size() == 0)
        {
            return matchedKeywords;
        }

        log.debug("Explanation:" + explanationText);

        // Remove the boost values, makes things easier...
        Pattern boostPattern = Pattern.compile("\\^[0-9]+.[0-9]+");
        Matcher boostPatternMatcher = boostPattern.matcher(explanationText);
        explanationText = boostPatternMatcher.replaceAll("");

        // convert the keywords to the analyzed form, then store them in a hashtable of <tokenizedForm, originalKeyword>
        Map<String, String> tokenizedKeywords = tokenizeKeywords(searchText);

        // We now have a Map with the tokenized keyword as the key, the original search word as the value.
        // Start looking through the explanation for the values
        for (String fieldName : fieldsToAnalyze)
        {
            Pattern weightPattern = Pattern.compile("\\sweight\\(" + fieldName + ":(\\w+)\\s",
                    java.util.regex.Pattern.CASE_INSENSITIVE | java.util.regex.Pattern.MULTILINE);
            Matcher m = weightPattern.matcher(explanationText);
            boolean result = m.find();
            while (result)
            {
                matchedKeywords.addMatch(fieldName, tokenizedKeywords.get(m.group(1)));
                result = m.find();
            }
        }
        return matchedKeywords;
    }
View Full Code Here

Examples of org.eurekastreams.commons.search.modelview.FieldMatch

            final String searchText)
    {
        // Figure out which query terms matched which fields
        for (ModelView result : results)
        {
            FieldMatch match = fieldMatchDeterminer.determineFieldMatches(result.getSearchIndexExplanationString(),
                    searchText);
            result.setFieldMatch(match);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.