Tuesday, 15 July 2014

php - Parsing a string into parts, only consecutive words, not a power set -


I am trying to write a search query to find articles from a database. I want to take the search string that the user enters and finds a specific set of possible search terms. If the user entered the search string "List of Average Pay in Germany for 2011" then I would like to make a list of those rules that are looking for. I thought I would look for whole string and partial strings of consecutive words. That's what I want to search for "list of average wages" and "2011 for Germany", but do not give "Germany 2011 list".

So far, I have a bit of code to make my search terms:

  $ searchString = "List of average wages in Germany for 2011"; $ SearchTokens = Explosion ("", $ search string); $ SearchTerms = array ($ search string); $ Token = count = ($ searchtoken); ($ Max = $ token number - 1; $ max; gt; 0; $ max-) {$ termA = ""; $ Word b = ""; ($ I = 0; $ i & lt; $ max; $ i ++) for {$ word A = $ SearchTokens [$ i]. ""; $ Word b. = $ Search Talkence [($ Token Quote - $ Max) + $ i] ""; } Array_push ($ searchTerms, $ termA); Array_push ($ search term, $ word b); } Print_r ($ SearchTerm);   

And this is giving me a list of words:

  • List of average wages in Germany for 2011
  • Average salary
  • Average salary in Germany
  • Germany for average salary
  • Average salary in Germany for 2011
  • Li>
  • List
  • In Germany for 2011
  • Average Salary
  • List of Average Salary
  • In Germany for 2011
  • List of averages
  • 2011
  • 2011
  • List
  • For
  • Listing
  • Average salary in Germany

    Li> Average salary in Germany

  • Salaries in Germany for more .

    Update

    I am not looking for a "power set" or for valid reasons, for example,

  • Germany for
  • listing salary 2011
  • I am constantly searching for words.

    All you want to search for sequential is the sub-section of the explosion string, just offset = 0 < Start with / code> and divide the array with length = 1 to count-offset :

      $ search_string = '2011 List of average wages in Germany for '; $ Search_array = Explosion ('', $ search_string); $ Count = count ($ search_array); $ S = array (); $ Min_length = 1; ($ Offset = 0; $ offset & lt; $ count; $ offset ++) {$ ($ length = $ min_length; $ length & lt; = $ count- $ offset; $ length ++) {$ match = Array_slice ($ search_array, $ offset, $ length); $ Search_matches [] = Join ('', $ match); }} Print_r ($ search_array); Print_r ($ search_matches);    

    No comments:

    Post a Comment